aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/builtin-stat.c')
-rw-r--r--tools/perf/builtin-stat.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9c6377f7152f..e9424fa72420 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -75,7 +75,7 @@ static int null_run = 0;
75static int fd[MAX_NR_CPUS][MAX_COUNTERS]; 75static int fd[MAX_NR_CPUS][MAX_COUNTERS];
76 76
77static u64 event_res[MAX_COUNTERS][3]; 77static u64 event_res[MAX_COUNTERS][3];
78static u64 event_scaled[MAX_COUNTERS]; 78static int event_scaled[MAX_COUNTERS];
79 79
80struct stats 80struct stats
81{ 81{
@@ -97,17 +97,31 @@ static double avg_stats(struct stats *stats)
97} 97}
98 98
99/* 99/*
100 * stddev = sqrt(1/N (\Sum n_i^2) - avg(n)^2) 100 * http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
101 *
102 * (\Sum n_i^2) - ((\Sum n_i)^2)/n
103 * s^2 -------------------------------
104 * n - 1
105 *
106 * http://en.wikipedia.org/wiki/Stddev
107 *
108 * The std dev of the mean is related to the std dev by:
109 *
110 * s
111 * s_mean = -------
112 * sqrt(n)
113 *
101 */ 114 */
102static double stddev_stats(struct stats *stats) 115static double stddev_stats(struct stats *stats)
103{ 116{
104 double avg = stats->sum / run_count; 117 double avg = stats->sum / run_count;
118 double variance = (stats->sum_sq - stats->sum*avg)/(run_count - 1);
119 double variance_mean = variance / run_count;
105 120
106 return sqrt(stats->sum_sq/run_count - avg*avg); 121 return sqrt(variance_mean);
107} 122}
108 123
109struct stats event_res_stats[MAX_COUNTERS][3]; 124struct stats event_res_stats[MAX_COUNTERS][3];
110struct stats event_scaled_stats[MAX_COUNTERS];
111struct stats runtime_nsecs_stats; 125struct stats runtime_nsecs_stats;
112struct stats walltime_nsecs_stats; 126struct stats walltime_nsecs_stats;
113struct stats runtime_cycles_stats; 127struct stats runtime_cycles_stats;
@@ -343,11 +357,10 @@ static void abs_printout(int counter, double avg, double stddev)
343static void print_counter(int counter) 357static void print_counter(int counter)
344{ 358{
345 double avg, stddev; 359 double avg, stddev;
346 int scaled; 360 int scaled = event_scaled[counter];
347 361
348 avg = avg_stats(&event_res_stats[counter][0]); 362 avg = avg_stats(&event_res_stats[counter][0]);
349 stddev = stddev_stats(&event_res_stats[counter][0]); 363 stddev = stddev_stats(&event_res_stats[counter][0]);
350 scaled = avg_stats(&event_scaled_stats[counter]);
351 364
352 if (scaled == -1) { 365 if (scaled == -1) {
353 fprintf(stderr, " %14s %-24s\n", 366 fprintf(stderr, " %14s %-24s\n",