| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 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 from metrics import power | 5 from metrics import power |
| 6 from metrics import smoothness | 6 from metrics import smoothness |
| 7 from metrics import timeline_interaction_record as tir_module |
| 8 from telemetry.core.timeline.model import TimelineModel |
| 7 from telemetry.page import page_measurement | 9 from telemetry.page import page_measurement |
| 8 | 10 |
| 11 import telemetry.core.timeline.bounds as timeline_bounds |
| 12 |
| 13 |
| 14 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): |
| 15 def __init__(self, name): |
| 16 super(MissingDisplayFrameRateError, self).__init__( |
| 17 'Missing display frame rate metrics: ' + name) |
| 18 |
| 9 | 19 |
| 10 class Smoothness(page_measurement.PageMeasurement): | 20 class Smoothness(page_measurement.PageMeasurement): |
| 11 def __init__(self): | 21 def __init__(self): |
| 12 super(Smoothness, self).__init__('smoothness') | 22 super(Smoothness, self).__init__('smoothness') |
| 13 self._smoothness_metric = None | 23 self._smoothness_metric = None |
| 14 self._power_metric = None | 24 self._power_metric = None |
| 25 self._timeline_model = None |
| 26 self._actions = [] |
| 15 | 27 |
| 16 def CustomizeBrowserOptions(self, options): | 28 def CustomizeBrowserOptions(self, options): |
| 17 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') | 29 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
| 18 power.PowerMetric.CustomizeBrowserOptions(options) | 30 power.PowerMetric.CustomizeBrowserOptions(options) |
| 19 | 31 |
| 20 def CanRunForPage(self, page): | 32 def CanRunForPage(self, page): |
| 21 return hasattr(page, 'smoothness') | 33 return hasattr(page, 'smoothness') |
| 22 | 34 |
| 23 def WillRunActions(self, page, tab): | 35 def WillRunActions(self, page, tab): |
| 24 self._power_metric = power.PowerMetric() | 36 self._power_metric = power.PowerMetric() |
| 25 self._power_metric.Start(page, tab) | 37 self._power_metric.Start(page, tab) |
| 26 self._smoothness_metric = smoothness.SmoothnessMetric() | 38 self._smoothness_metric = smoothness.SmoothnessMetric() |
| 27 self._smoothness_metric.Start(page, tab) | 39 # Start tracing for smoothness metric. |
| 40 custom_categories = ['webkit.console', 'benchmark'] |
| 41 custom_categories += page.GetSyntheticDelayCategories() |
| 42 tab.browser.StartTracing(','.join(custom_categories), 60) |
| 43 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 44 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
| 28 | 45 |
| 29 def DidRunAction(self, page, tab, action): | 46 def DidRunAction(self, page, tab, action): |
| 30 self._smoothness_metric.AddActionToIncludeInMetric(action) | 47 self._actions.append(action) |
| 31 | 48 |
| 32 def DidRunActions(self, page, tab): | 49 def DidRunActions(self, page, tab): |
| 33 self._power_metric.Stop(page, tab) | 50 self._power_metric.Stop(page, tab) |
| 34 self._smoothness_metric.Stop(page, tab) | 51 # Stop tracing for smoothness metric. |
| 52 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 53 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| 54 tracing_timeline_data = tab.browser.StopTracing() |
| 55 self._timeline_model = TimelineModel(timeline_data=tracing_timeline_data) |
| 35 | 56 |
| 36 def MeasurePage(self, page, tab, results): | 57 def MeasurePage(self, page, tab, results): |
| 37 self._power_metric.AddResults(tab, results) | 58 self._power_metric.AddResults(tab, results) |
| 38 self._smoothness_metric.AddResults(tab, results) | 59 # Add results of smoothness metric. This computes the smoothness metric for |
| 60 # the time range between the first action starts and the last action ends. |
| 61 # To get the measurement for each action, use |
| 62 # measurement.TimelineBasedMeasurement. |
| 63 time_bounds = timeline_bounds.Bounds() |
| 64 for action in self._actions: |
| 65 time_bounds.AddBounds( |
| 66 action.GetActiveRangeOnTimeline(self._timeline_model)) |
| 67 # Create an interaction_record for this legacy measurement. Since we don't |
| 68 # wrap the results that is sent to smoothnes metric, the logical_name will |
| 69 # not be used. |
| 70 interaction_record = tir_module.TimelineInteractionRecord( |
| 71 'smoothness_interaction', time_bounds.min, time_bounds.max) |
| 72 renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab) |
| 73 self._smoothness_metric.AddResults(self._timeline_model, |
| 74 renderer_thread, |
| 75 interaction_record, |
| 76 results) |
| 77 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| 78 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
| 79 if r.value is None: |
| 80 raise MissingDisplayFrameRateError(r.name) |
| 81 results.Add(r.name, r.unit, r.value) |
| OLD | NEW |