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 3 # found in the LICENSE file. 4 5 from metrics import smoothness 6 from metrics import timeline 7 from telemetry.page import page_measurement 8 9 10 class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): 11 def __init__(self, name): 12 super(MissingDisplayFrameRateError, self).__init__( 13 'Missing display frame rate metrics: ' + name) 14 15 16 class Smoothness(page_measurement.PageMeasurement): 17 def __init__(self): 18 super(Smoothness, self).__init__('smoothness') 19 self._metric = None 20 21 def AddCommandLineOptions(self, parser): 22 metric_choices = ['smoothness', 'timeline'] 23 parser.add_option('--metric', dest='metric', type='choice', 24 choices=metric_choices, 25 default='smoothness', 26 help=('Metric to use in the measurement. ' + 27 'Supported values: ' + ', '.join(metric_choices))) 28 29 def CustomizeBrowserOptions(self, options): 30 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') 31 32 def CanRunForPage(self, page): 33 return hasattr(page, 'smoothness') 34 35 def WillRunActions(self, page, tab): 36 if self.options.metric == 'smoothness': 37 self._metric = smoothness.SmoothnessMetric() 38 elif self.options.metric == 'timeline': 39 self._metric = timeline.ThreadTimesTimelineMetric() 40 41 self._metric.Start(page, tab) 42 43 if tab.browser.platform.IsRawDisplayFrameRateSupported(): 44 tab.browser.platform.StartRawDisplayFrameRateMeasurement() 45 46 def DidRunAction(self, page, tab, action): 47 timeline_marker_name = action.GetTimelineMarkerName() 48 if self.options.metric == 'smoothness' and timeline_marker_name: 49 self._metric.AddTimelineMarkerNameToIncludeInMetric(timeline_marker_name) 50 51 def DidRunActions(self, page, tab): 52 if tab.browser.platform.IsRawDisplayFrameRateSupported(): 53 tab.browser.platform.StopRawDisplayFrameRateMeasurement() 54 self._metric.Stop(page, tab) 55 56 def MeasurePage(self, page, tab, results): 57 self._metric.AddResults(tab, results) 58 59 if tab.browser.platform.IsRawDisplayFrameRateSupported(): 60 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): 61 if r.value is None: 62 raise MissingDisplayFrameRateError(r.name) 63 results.Add(r.name, r.unit, r.value) 64