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