Chromium Code Reviews| 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'] |