Chromium Code Reviews| Index: tools/perf/measurements/smoothness.py |
| diff --git a/tools/perf/measurements/smoothness.py b/tools/perf/measurements/smoothness.py |
| index a84a4acb29204c70fc9cc0627727bbbbafb73f5d..d95c78d20da360ba40d43abb9b334c852b2b0812 100644 |
| --- a/tools/perf/measurements/smoothness.py |
| +++ b/tools/perf/measurements/smoothness.py |
| @@ -4,14 +4,36 @@ |
| from metrics import power |
| from metrics import smoothness |
| +from metrics import timeline_interaction_record as tir_module |
| +from telemetry.core.timeline.model import TimelineModel |
| from telemetry.page import page_measurement |
| +import telemetry.core.timeline.bounds as timeline_bounds |
| + |
| + |
| +class MissingDisplayFrameRateError(page_measurement.MeasurementFailure): |
| + def __init__(self, name): |
| + super(MissingDisplayFrameRateError, self).__init__( |
| + 'Missing display frame rate metrics: ' + name) |
| + |
| + |
| +def _GetSyntheticDelayCategoriesFromPage(page): |
|
nduca
2014/03/07 20:05:56
Lets put this code somewhere common. Maybe we pass
|
| + if not hasattr(page, 'synthetic_delays'): |
| + return [] |
| + result = [] |
| + for delay, options in page.synthetic_delays.items(): |
| + options = '%f;%s' % (options.get('target_duration', 0), |
| + options.get('mode', 'static')) |
| + result.append('DELAY(%s;%s)' % (delay, options)) |
| + return result |
| class Smoothness(page_measurement.PageMeasurement): |
| def __init__(self): |
| super(Smoothness, self).__init__('smoothness') |
| self._smoothness_metric = None |
| self._power_metric = None |
| + self._timeline_model = None |
| + self._actions = [] |
| def CustomizeBrowserOptions(self, options): |
| options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
| @@ -24,15 +46,43 @@ class Smoothness(page_measurement.PageMeasurement): |
| self._power_metric = power.PowerMetric() |
| self._power_metric.Start(page, tab) |
| self._smoothness_metric = smoothness.SmoothnessMetric() |
| - self._smoothness_metric.Start(page, tab) |
| + # Start tracing for smoothness metric |
|
nduca
2014/03/07 20:05:56
end with period.
|
| + custom_categories = ['webkit.console', 'benchmark'] |
| + custom_categories += _GetSyntheticDelayCategoriesFromPage(page) |
| + tab.browser.StartTracing(','.join(custom_categories), 60) |
| + if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| + tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
| def DidRunAction(self, page, tab, action): |
| - self._smoothness_metric.AddActionToIncludeInMetric(action) |
| + self._actions.append(action) |
| def DidRunActions(self, page, tab): |
| self._power_metric.Stop(page, tab) |
| - self._smoothness_metric.Stop(page, tab) |
| + # Stop tracing for smoothness metric |
| + if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| + tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
| + tracing_timeline_data = tab.browser.StopTracing() |
| + self._timeline_model = TimelineModel(timeline_data=tracing_timeline_data) |
| def MeasurePage(self, page, tab, results): |
| self._power_metric.AddResults(tab, results) |
| - self._smoothness_metric.AddResults(tab, results) |
| + # Add results of smoothness metric. This computes the smoothness metric for |
| + # the time range between the first action starts and the last action ends. |
| + # To get the measurement for each action, use |
| + # measurement.TimelineBasedMeasurement. |
| + time_bounds = timeline_bounds.Bounds() |
| + for action in self._actions: |
| + time_bounds.AddBounds( |
| + action.GetActiveRangeOnTimeline(self._timeline_model)) |
| + interaction_record = tir_module.TimelineInteractionRecord.\ |
| + FromBounds(time_bounds) |
| + renderer_thread = self._timeline_model.GetRendererThreadFromTab(tab) |
| + self._smoothness_metric.AddResults(self._timeline_model, |
| + renderer_thread, |
| + interaction_record, |
| + results) |
| + if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
| + for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
| + if r.value is None: |
| + raise MissingDisplayFrameRateError(r.name) |
| + results.Add(r.name, r.unit, r.value) |