Refactor function_stat_show() code grouping avg and stddev calculations inside a single function (function_stat_calc()). We are now able to call it from different places.
Signed-off-by: Juri Lelli <juri.le...@gmail.com> Cc: Steven Rostedt <rost...@goodmis.org> Cc: Frederic Weisbecker <fweis...@gmail.com> Cc: Ingo Molnar <mi...@redhat.com> --- kernel/trace/ftrace.c | 46 ++++++++++++++++++++++------------------------ kernel/trace/trace.h | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 24 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 6c508ff..6caaa0e 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -473,16 +473,6 @@ static void ftrace_update_pid_func(void) } #ifdef CONFIG_FUNCTION_PROFILER -struct ftrace_profile { - struct hlist_node node; - unsigned long ip; - unsigned long counter; -#ifdef CONFIG_FUNCTION_GRAPH_TRACER - unsigned long long time; - unsigned long long time_squared; -#endif -}; - struct ftrace_profile_page { struct ftrace_profile_page *next; unsigned long index; @@ -592,6 +582,27 @@ static int function_stat_headers(struct seq_file *m) return 0; } +void function_stat_calc(struct ftrace_profile *rec, + unsigned long long *avg, + unsigned long long *stddev) +{ + *avg = rec->time; + do_div(*avg, rec->counter); + + /* Sample standard deviation (s^2) */ + if (rec->counter <= 1) + *stddev = 0; + else { + *stddev = rec->time_squared - rec->counter * (*avg) * (*avg); + + /* + * Divide only 1000 for ns^2 -> us^2 conversion. + * trace_print_graph_duration will divide 1000 again. + */ + do_div(*stddev, (rec->counter - 1) * 1000); + } +} + static int function_stat_show(struct seq_file *m, void *v) { struct ftrace_profile *rec = v; @@ -615,20 +626,7 @@ static int function_stat_show(struct seq_file *m, void *v) #ifdef CONFIG_FUNCTION_GRAPH_TRACER seq_printf(m, " "); - avg = rec->time; - do_div(avg, rec->counter); - - /* Sample standard deviation (s^2) */ - if (rec->counter <= 1) - stddev = 0; - else { - stddev = rec->time_squared - rec->counter * avg * avg; - /* - * Divide only 1000 for ns^2 -> us^2 conversion. - * trace_print_graph_duration will divide 1000 again. - */ - do_div(stddev, (rec->counter - 1) * 1000); - } + function_stat_calc(rec, &avg, &stddev); trace_seq_init(&s); trace_print_graph_duration(rec->time, &s); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 711ca7d..89c8a7b 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -1062,4 +1062,20 @@ int perf_ftrace_event_register(struct ftrace_event_call *call, #define perf_ftrace_event_register NULL #endif +#ifdef CONFIG_FUNCTION_PROFILER +struct ftrace_profile { + struct hlist_node node; + unsigned long ip; + unsigned long counter; +#ifdef CONFIG_FUNCTION_GRAPH_TRACER + unsigned long long time; + unsigned long long time_squared; +#endif +}; + +void function_stat_calc(struct ftrace_profile *rec, + unsigned long long *avg, + unsigned long long *stddev); +#endif + #endif /* _LINUX_KERNEL_TRACE_H */ -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/