libtraceeval: Add average and standard deviation to stat
PATCH 1/1 libtraceeval: Add average and standard deviation to stat
From: "Steven Rostedt (Google)" <[email protected]>
Add the APIs:
traceeval_stat_average()
traceeval_stat_stddev()
That return the average mean and standard deviation respectively of all the values in the stat.
It uses the Welford method of computing the running standard deviation, which is:
count = 0;
calculate(x) {
if (!count) {
count = 1;
M = x;
M2 = 0.0;
} else {
double D;
count++;
D = x - M;
M += D / count;
M2 = D * (x - M);
}}
stddev() {
return sqrt(M2 / (count - 1))}
Signed-off-by Steven Rostedt (Google) <[email protected]>
--- include/traceeval.h | 2 ++ samples/task-eval.c | 22 ++++++++++++++++++++- scripts/utils.mk | 2 +- src/Makefile | 2 ++ src/eval-local.h | 3 ++- src/histograms.c | 47 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 75 insertions(+), 3 deletions(-)
include/traceeval.h +2 -0
@@ -345,6 +345,8 @@ unsigned long long traceeval_stat_max_timestamp(struct traceeval_stat *stat, unsigned long long *ts);unsigned long long traceeval_stat_min_timestamp (struct traceeval_stat *stat,unsigned long long *ts); +unsigned long long traceeval_stat_average (struct traceeval_stat *stat); +double traceeval_stat_stddev (struct traceeval_stat *stat);struct traceeval_iterator *traceeval_iterator_get (struct traceeval *teval);struct traceeval_iterator *traceeval_iterator_delta_start_get (struct traceeval *teval);
samples/task-eval.c +21 -1
@@ -814,6 +814,7 @@ static int compare_pdata(struct traceeval *teval,static void display_cpus (struct traceeval *teval) {struct traceeval_iterator *iter =traceeval_iterator_get (teval); +unsigned long long max, max_ts, min, min_ts;const struct traceeval_data *keys;struct traceeval_stat *stat;int last_cpu =-1 ;
@@ -834,6 +835,9 @@ static void display_cpus(struct traceeval *teval)if (!stat)continue ;// die? + max =traceeval_stat_max_timestamp (stat, &max_ts); + min =traceeval_stat_min_timestamp (stat, &min_ts); +if (last_cpu != cpu)printf (" CPU [%d]:\n" , cpu);
@@ -853,6 +857,18 @@ static void display_cpus(struct traceeval *teval) }printf (" time (us):" );print_microseconds_nl (12 ,traceeval_stat_total (stat)); +printf (" average (us):" ); +print_microseconds_nl (12 ,traceeval_stat_average (stat)); +printf (" max:" ); +print_microseconds (12 , max); +printf ("\tat: %lld\n" , max_ts); +printf (" min:" ); +print_microseconds (12 , min); +printf ("\tat: %lld\n" , min_ts); +printf (" count: %*lld\n" ,11 , +traceeval_stat_count (stat)); +printf (" stddev: %*.3f\n" ,16 , +traceeval_stat_stddev (stat) /1000 ); last_cpu = cpu; }
@@ -883,13 +899,17 @@ static void print_stats(int idx, struct traceeval_stat *stat)printf ("\tat: %lld\n" , max_ts); }else {print_microseconds_nl (idx, total); -printf ("%*s%*lld\n" ,40 - idx,"count:" , idx, cnt); +printf ("%*s" ,40 - idx,"average:" ); +print_microseconds_nl (idx,traceeval_stat_average (stat));printf ("%*s" ,40 - idx,"max:" );print_microseconds (idx, max);printf ("\tat: %lld\n" , max_ts);printf ("%*s" ,40 - idx,"min:" );print_microseconds (idx, min);printf ("\tat: %lld\n" , min_ts); +printf ("%*s%*lld\n" ,40 - idx,"count:" , idx, cnt); +printf ("%*s%*.3f\n" ,40 - idx,"stddev:" , idx +4 , +traceeval_stat_stddev (stat) /1000 ); } }
scripts/utils.mk +1 -1
@@ -101,7 +101,7 @@ extract_example = \ do_sample_build = \ $(Q)($(print_sample_build) \ - $(CC) -o $1 $2 $(CFLAGS) $(LIBRARY_STATIC) $(LIBRARY_LIBS)) + $(CC) -o $1 $2 $(CFLAGS) $(LIBRARY_STATIC) $(LIBRARY_LIBS) -lm) do_sample_obj = \ $(Q)($(print_sample_obj) \
src/Makefile +2 -0
@@ -9,6 +9,8 @@ OBJS += hash.o OBJS := $(OBJS:%.o=$(bdir)/%.o) +LIBS = -lm + $(LIBRARY_STATIC): $(OBJS) $(Q)$(call do_build_static_lib)
src/eval-local.h +2 -1
@@ -56,7 +56,8 @@ struct traceeval_stat {unsigned long long min;unsigned long long min_ts;unsigned long long total; -unsigned long long std; +double M ; +double M2 ;size_t count; };
src/histograms.c +47 -0
77 lines not on this page · raw message
Signature · 1 line
2.42.0