Commit 52d85d76 authored by Juri Lelli's avatar Juri Lelli Committed by Steven Rostedt

ftrace: Fix stddev calculation in function profiler

When FUNCTION_GRAPH_TRACER is enabled, ftrace can profile kernel functions
and print basic statistics about them. Unfortunately, running stddev
calculation is wrong. This patch corrects it implementing Welford’s method:

        s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2) .
Link: http://lkml.kernel.org/r/1371031398-24048-1-git-send-email-juri.lelli@gmail.com

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Signed-off-by: default avatarJuri Lelli <juri.lelli@gmail.com>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 195a84d9
...@@ -641,12 +641,18 @@ static int function_stat_show(struct seq_file *m, void *v) ...@@ -641,12 +641,18 @@ static int function_stat_show(struct seq_file *m, void *v)
if (rec->counter <= 1) if (rec->counter <= 1)
stddev = 0; stddev = 0;
else { else {
stddev = rec->time_squared - rec->counter * avg * avg; /*
* Apply Welford's method:
* s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2)
*/
stddev = rec->counter * rec->time_squared -
rec->time * rec->time;
/* /*
* Divide only 1000 for ns^2 -> us^2 conversion. * Divide only 1000 for ns^2 -> us^2 conversion.
* trace_print_graph_duration will divide 1000 again. * trace_print_graph_duration will divide 1000 again.
*/ */
do_div(stddev, (rec->counter - 1) * 1000); do_div(stddev, rec->counter * (rec->counter - 1) * 1000);
} }
trace_seq_init(&s); trace_seq_init(&s);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment