| OLD | NEW |
| (Empty) |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import json | |
| 6 | |
| 7 from telemetry.value import histogram | |
| 8 from telemetry.value import histogram_util | |
| 9 from telemetry.value import scalar | |
| 10 | |
| 11 from metrics import Metric | |
| 12 | |
| 13 HISTOGRAMS_TO_RECORD = [ | |
| 14 { | |
| 15 'name': 'MediaRouter.Ui.Dialog.LoadedWithData', 'units': 'ms', | |
| 16 'display_name': 'dialog_loaded_with_data', | |
| 17 'type': histogram_util.BROWSER_HISTOGRAM, | |
| 18 'description': 'The latency to render the media router dialog with data.', | |
| 19 }, | |
| 20 { | |
| 21 'name': 'MediaRouter.Ui.Dialog.Paint', 'units': 'ms', | |
| 22 'display_name': 'dialog_paint', | |
| 23 'type': histogram_util.BROWSER_HISTOGRAM, | |
| 24 'description': 'The latency to paint the media router dialog.', | |
| 25 }] | |
| 26 | |
| 27 | |
| 28 class MediaRouterMetric(Metric): | |
| 29 "A metric for media router dialog latency from histograms." | |
| 30 | |
| 31 def __init__(self): | |
| 32 super(MediaRouterMetric, self).__init__() | |
| 33 self._histogram_start = dict() | |
| 34 self._histogram_delta = dict() | |
| 35 self._started = False | |
| 36 | |
| 37 def Start(self, page, tab): | |
| 38 self._started = True | |
| 39 | |
| 40 for h in HISTOGRAMS_TO_RECORD: | |
| 41 histogram_data = histogram_util.GetHistogram( | |
| 42 h['type'], h['name'], tab) | |
| 43 # Histogram data may not be available | |
| 44 if not histogram_data: | |
| 45 continue | |
| 46 self._histogram_start[h['name']] = histogram_data | |
| 47 | |
| 48 def Stop(self, page, tab): | |
| 49 assert self._started, 'Must call Start() first' | |
| 50 for h in HISTOGRAMS_TO_RECORD: | |
| 51 # Histogram data may not be available | |
| 52 if h['name'] not in self._histogram_start: | |
| 53 continue | |
| 54 histogram_data = histogram_util.GetHistogram( | |
| 55 h['type'], h['name'], tab) | |
| 56 | |
| 57 if not histogram_data: | |
| 58 continue | |
| 59 self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( | |
| 60 histogram_data, self._histogram_start[h['name']]) | |
| 61 | |
| 62 def AddResults(self, tab, results): | |
| 63 assert self._histogram_delta, 'Must call Stop() first' | |
| 64 for h in HISTOGRAMS_TO_RECORD: | |
| 65 # Histogram data may not be available | |
| 66 if h['name'] not in self._histogram_delta: | |
| 67 continue | |
| 68 results.AddValue(histogram.HistogramValue( | |
| 69 results.current_page, h['display_name'], h['units'], | |
| 70 raw_value_json=self._histogram_delta[h['name']], important=False, | |
| 71 description=h.get('description'))) | |
| OLD | NEW |