mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] perf: Util.py add_stats() computes the mean correctly
@ 2017-08-09  5:31 Dima Kogan
  0 siblings, 0 replies; only message in thread
From: Dima Kogan @ 2017-08-09  5:31 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, linux-kernel; +Cc: Dima Kogan

add_stats() is a utility function for perf scripts to accumulate a value, and
keep track of some statistics. The mean is one of the statistics it keeps track
of, but due to a bug, this wasn't being computed properly. This patch makes the
computation correct

Signed-off-by: Dima Kogan <dima@secretsauce.net>
---
 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
index 1d95009592eb..3d1f08b8ba19 100644
--- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
+++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
@@ -41,7 +41,7 @@ def add_stats(dict, key, value):
 			min = value
 		if value > max:
 			max = value
-		avg = (avg + value) / 2
+		avg = (avg*count + float(value)) / (count + 1)
 		dict[key] = (min, max, avg, count + 1)
 
 def clear_term():
-- 
2.11.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-08-09  5:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-09  5:31 [PATCH] perf: Util.py add_stats() computes the mean correctly Dima Kogan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®