Chromium Code Reviews| Index: tools/telemetry/telemetry/util.py |
| diff --git a/tools/telemetry/telemetry/util.py b/tools/telemetry/telemetry/util.py |
| index db93bcf79cb22d8c54be83016febb60dae8fd84d..30ef414cf755cfbaf3bdd83efe71b510881b635d 100644 |
| --- a/tools/telemetry/telemetry/util.py |
| +++ b/tools/telemetry/telemetry/util.py |
| @@ -2,6 +2,7 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| import inspect |
| +import json |
| import socket |
| import time |
| @@ -66,3 +67,26 @@ def GetAvailableLocalPort(): |
| tmp.close() |
| return port |
| + |
| +def SubtractHistogram(histogram_json, baseline_json): |
|
nduca
2013/02/12 18:33:15
i'd rather this wasn't in telemetry. Histograms ar
marja
2013/02/13 16:09:30
perf_test_helpers.py seems like a logical place, s
|
| + """Subtracts baseline from a histogram. Both histogram and baseline are json |
| + serializations of histograms.""" |
| + histogram = json.loads(histogram_json) |
| + baseline = json.loads(baseline_json) |
| + |
| + baseline_buckets = dict() |
| + for b in baseline['buckets']: |
| + baseline_buckets[b['low']] = b['count'] |
| + |
| + new_buckets = [] |
| + for b in histogram['buckets']: |
| + new_bucket = b |
| + low = b['low'] |
| + if low in baseline_buckets: |
| + new_bucket['count'] = b['count'] - baseline_buckets[low] |
| + if new_bucket['count']: |
| + new_buckets.append(new_bucket) |
| + histogram['buckets'] = new_buckets |
| + histogram['count'] -= baseline['count'] |
| + |
| + return json.dumps(histogram) |