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

Unified Diff: tools/telemetry/telemetry/value/histogram_util.py

Issue 941803002: Work around exceptions when the 'high' value for a histogram is not present. This happens when the … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added method in histogram_util to parse histogram buckets and correctly set 'high' value Created 5 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
Index: tools/telemetry/telemetry/value/histogram_util.py
diff --git a/tools/telemetry/telemetry/value/histogram_util.py b/tools/telemetry/telemetry/value/histogram_util.py
index bb6ff363d22943b0c8fde15340ceca46a431ae4c..99542bec43a1d6e3501d9be397ce20b790f2cc0e 100644
--- a/tools/telemetry/telemetry/value/histogram_util.py
+++ b/tools/telemetry/telemetry/value/histogram_util.py
@@ -16,6 +16,21 @@ BROWSER_HISTOGRAM = 'browser_histogram'
RENDERER_HISTOGRAM = 'renderer_histogram'
+def GetHistogramBucketsFromJson(histogram_json):
+ return GetHistogramBucketsFromRawValue(json.loads(histogram_json))
+
+
+def GetHistogramBucketsFromRawValue(raw_value):
+ buckets = raw_value.get('buckets', [])
+ if buckets:
+ # If there are values greater than the maximum allowable for the histogram,
+ # the highest bucket will have a 'low': maxvalue entry in the dict but no
+ # 'high' entry. Code often assumes the 'high' value will always be present,
+ # and uses it to get bucket mean. So default it to the same value as low.
+ buckets[-1].setdefault('high', buckets[-1]['low'])
+ return buckets
+
+
def CustomizeBrowserOptions(options):
"""Allows histogram collection."""
options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
@@ -27,9 +42,10 @@ def SubtractHistogram(histogram_json, start_histogram_json):
Both parameters and the returned result are json serializations.
"""
start_histogram = json.loads(start_histogram_json)
+ start_histogram_buckets = GetHistogramBucketsFromRawValue(start_histogram)
# 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:
+ if not start_histogram_buckets:
return histogram_json
histogram = json.loads(histogram_json)
@@ -39,16 +55,16 @@ def SubtractHistogram(histogram_json, start_histogram_json):
'Trying to compare histograms from different processes (%d and %d)'
% (start_histogram['pid'], histogram['pid']))
- start_histogram_buckets = dict()
- for b in start_histogram['buckets']:
- start_histogram_buckets[b['low']] = b['count']
+ start_histogram_bucket_counts = dict()
+ for b in start_histogram_buckets:
+ start_histogram_bucket_counts[b['low']] = b['count']
new_buckets = []
- for b in histogram['buckets']:
+ for b in GetHistogramBucketsFromRawValue(histogram):
new_bucket = b
low = b['low']
- if low in start_histogram_buckets:
- new_bucket['count'] = b['count'] - start_histogram_buckets[low]
+ if low in start_histogram_bucket_counts:
+ new_bucket['count'] = b['count'] - start_histogram_bucket_counts[low]
if new_bucket['count'] < 0:
logging.error('Histogram subtraction error, starting histogram most '
'probably invalid.')
@@ -72,8 +88,7 @@ def AddHistograms(histogram_jsons):
buckets = collections.defaultdict(int)
for histogram_json in histogram_jsons:
- h = json.loads(histogram_json)
- for b in h['buckets']:
+ for b in GetHistogramBucketsFromJson(histogram_json):
key = (b['low'], b['high'])
sullivan 2015/02/20 16:43:19 This line would be buggy without a fix in histogra
buckets[key] += b['count']

Powered by Google App Engine
This is Rietveld 408576698