[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1371488862.18733.21.camel@gandalf.local.home>
Date: Mon, 17 Jun 2013 13:07:42 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Juri Lelli <juri.lelli@...il.com>
Cc: fweisbec@...il.com, mingo@...hat.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] ftrace: fix stddev calculation
On Wed, 2013-06-12 at 12:03 +0200, Juri Lelli wrote:
> 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) .
>
> Signed-off-by: Juri Lelli <juri.lelli@...il.com>
I pulled this into my 3.11 queue. Thanks!
-- Steve
> Cc: Steven Rostedt <rostedt@...dmis.org>
> Cc: Frederic Weisbecker <fweisbec@...il.com>
> Cc: Ingo Molnar <mingo@...hat.com>
> ---
> kernel/trace/ftrace.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 6c508ff..6c3fce2 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -622,12 +622,18 @@ static int function_stat_show(struct seq_file *m, void *v)
> if (rec->counter <= 1)
> stddev = 0;
> 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.
> * 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);
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists