Skip to contentSkip to conversation

perf: Util.py add_stats() computes the mean correctly

PATCH New Dima Kogan 1 participant 1 message Aug 9, 2017 perf events

lore
Share & tools
lore

Dima Kogan

author
#0 lore raw

PATCH 1/1 perf: Util.py add_stats() computes the mean correctly

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

---
 tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +1 -1
index 1d95009592eb..3d1f08b8ba19 100644
@@ -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():
Signature · 1 line
2.11.0