diff options
Diffstat (limited to 'chrome/test/media_router/telemetry/benchmarks/media_router_metric.py')
-rw-r--r-- | chrome/test/media_router/telemetry/benchmarks/media_router_metric.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/chrome/test/media_router/telemetry/benchmarks/media_router_metric.py b/chrome/test/media_router/telemetry/benchmarks/media_router_metric.py index 352e386..0439b58 100644 --- a/chrome/test/media_router/telemetry/benchmarks/media_router_metric.py +++ b/chrome/test/media_router/telemetry/benchmarks/media_router_metric.py @@ -4,6 +4,7 @@ import json +from telemetry.value import histogram from telemetry.value import histogram_util from telemetry.value import scalar @@ -27,19 +28,44 @@ HISTOGRAMS_TO_RECORD = [ class MediaRouterMetric(Metric): "A metric for media router dialog latency from histograms." + def __init__(self): + super(MediaRouterMetric, self).__init__() + self._histogram_start = dict() + self._histogram_delta = dict() + self._started = False + def Start(self, page, tab): - raise NotImplementedError() + self._started = True + + for h in HISTOGRAMS_TO_RECORD: + histogram_data = histogram_util.GetHistogram( + h['type'], h['name'], tab) + # Histogram data may not be available + if not histogram_data: + continue + self._histogram_start[h['name']] = histogram_data def Stop(self, page, tab): - raise NotImplementedError() + assert self._started, 'Must call Start() first' + for h in HISTOGRAMS_TO_RECORD: + # Histogram data may not be available + if h['name'] not in self._histogram_start: + continue + histogram_data = histogram_util.GetHistogram( + h['type'], h['name'], tab) + + if not histogram_data: + continue + self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( + histogram_data, self._histogram_start[h['name']]) def AddResults(self, tab, results): + assert self._histogram_delta, 'Must call Stop() first' for h in HISTOGRAMS_TO_RECORD: - result = json.loads(histogram_util.GetHistogram( - h['type'], h['name'], tab)) - if 'sum' in result: - # For all the histograms logged here, there's a single entry so sum - # is the exact value for that entry. - results.AddValue(scalar.ScalarValue( - results.current_page, h['display_name'], h['units'], - result['sum'])) + # Histogram data may not be available + if h['name'] not in self._histogram_delta: + continue + results.AddValue(histogram.HistogramValue( + results.current_page, h['display_name'], h['units'], + raw_value_json=self._histogram_delta[h['name']], important=False, + description=h.get('description'))) |