Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: tools/perf/perf_tools/histogram.py

Issue 12221137: Telemetry / Memory benchmark fix: Separate histograms for different tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add error msg if we do nonsensemaking histogram stuff Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/perf/perf_tools/histogram_measurement.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/perf_tools/histogram.py
diff --git a/tools/perf/perf_tools/histogram.py b/tools/perf/perf_tools/histogram.py
new file mode 100644
index 0000000000000000000000000000000000000000..c5cbb2ebce57abbaf050344c6bca2beb9cf979b5
--- /dev/null
+++ b/tools/perf/perf_tools/histogram.py
@@ -0,0 +1,35 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+import json
+import logging
+
+def SubtractHistogram(histogram_json, start_histogram_json):
+ """Subtracts a previous histogram from a histogram. Both parameters are json
+ serializations of histograms."""
+ start_histogram = json.loads(start_histogram_json)
+ # It's ok if the start histogram is empty (we had no data, maybe even no
+ # histogram at all, at the start of the test).
+ if 'buckets' not in start_histogram:
+ return histogram_json
+
+ start_histogram_buckets = dict()
+ for b in start_histogram['buckets']:
+ start_histogram_buckets[b['low']] = b['count']
+
+ new_buckets = []
+ histogram = json.loads(histogram_json)
+ for b in histogram['buckets']:
+ new_bucket = b
+ low = b['low']
+ if low in start_histogram_buckets:
+ new_bucket['count'] = b['count'] - start_histogram_buckets[low]
+ if new_bucket['count'] < 0:
+ logging.error('Histogram subtraction error, starting histogram most '
+ 'probably invalid.')
+ if new_bucket['count']:
+ new_buckets.append(new_bucket)
+ histogram['buckets'] = new_buckets
+ histogram['count'] -= start_histogram['count']
+
+ return json.dumps(histogram)
« no previous file with comments | « no previous file | tools/perf/perf_tools/histogram_measurement.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698