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 import logging | 4 import logging |
5 | 5 |
6 from metrics import smoothness | 6 from metrics import smoothness |
7 from metrics.gpu_rendering_stats import GpuRenderingStats | 7 from metrics.rendering_stats import RenderingStats |
8 from telemetry.page import page_measurement | 8 from telemetry.page import page_measurement |
9 | 9 |
10 | 10 |
11 class DidNotScrollException(page_measurement.MeasurementFailure): | 11 class DidNotScrollException(page_measurement.MeasurementFailure): |
12 def __init__(self): | 12 def __init__(self): |
13 super(DidNotScrollException, self).__init__('Page did not scroll') | 13 super(DidNotScrollException, self).__init__('Page did not scroll') |
14 | 14 |
15 | 15 |
16 class MissingDisplayFrameRate(page_measurement.MeasurementFailure): | 16 class MissingDisplayFrameRate(page_measurement.MeasurementFailure): |
17 def __init__(self, name): | 17 def __init__(self, name): |
18 super(MissingDisplayFrameRate, self).__init__( | 18 super(MissingDisplayFrameRate, self).__init__( |
19 'Missing display frame rate metrics: ' + name) | 19 'Missing display frame rate metrics: ' + name) |
20 | 20 |
21 | 21 |
22 class Smoothness(page_measurement.PageMeasurement): | 22 class Smoothness(page_measurement.PageMeasurement): |
23 def __init__(self): | 23 def __init__(self): |
24 super(Smoothness, self).__init__('smoothness') | 24 super(Smoothness, self).__init__('smoothness') |
25 self.force_enable_threaded_compositing = False | |
26 self._metrics = None | 25 self._metrics = None |
27 self._trace_result = None | 26 self._trace_result = None |
28 | 27 |
29 def AddCommandLineOptions(self, parser): | |
30 parser.add_option('--report-all-results', dest='report_all_results', | |
31 action='store_true', | |
32 help='Reports all data collected, not just FPS') | |
33 | |
34 def CustomizeBrowserOptions(self, options): | 28 def CustomizeBrowserOptions(self, options): |
35 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) | 29 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) |
36 if self.force_enable_threaded_compositing: | |
37 options.AppendExtraBrowserArgs('--enable-threaded-compositing') | |
38 | 30 |
39 def CanRunForPage(self, page): | 31 def CanRunForPage(self, page): |
40 return hasattr(page, 'smoothness') | 32 return hasattr(page, 'smoothness') |
41 | 33 |
42 def WillRunAction(self, page, tab, action): | 34 def WillRunAction(self, page, tab, action): |
43 # TODO(ermst): Remove "webkit" category after Blink r157377 is picked up by | 35 # TODO(ermst): Remove "webkit" category after Blink r157377 is picked up by |
44 # the reference builds. | 36 # the reference builds. |
45 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) | 37 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) |
46 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 38 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
47 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 39 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
48 self._metrics = smoothness.SmoothnessMetrics(tab) | 40 self._metrics = smoothness.SmoothnessMetrics(tab) |
49 if action.CanBeBound(): | 41 if action.CanBeBound(): |
50 self._metrics.BindToAction(action) | 42 self._metrics.BindToAction(action) |
51 else: | 43 else: |
52 self._metrics.Start() | 44 self._metrics.Start() |
53 | 45 |
54 def DidRunAction(self, page, tab, action): | 46 def DidRunAction(self, page, tab, action): |
55 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 47 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
56 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 48 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
57 if not action.CanBeBound(): | 49 if not action.CanBeBound(): |
58 self._metrics.Stop() | 50 self._metrics.Stop() |
59 self._trace_result = tab.browser.StopTracing() | 51 self._trace_result = tab.browser.StopTracing() |
60 | 52 |
61 def MeasurePage(self, page, tab, results): | 53 def MeasurePage(self, page, tab, results): |
62 rendering_stats_deltas = self._metrics.deltas | 54 rendering_stats_deltas = self._metrics.deltas |
63 | 55 |
64 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): | 56 # TODO(ernstm): remove numFramesSentToScreen when RenderingStats |
| 57 # cleanup CL was picked up by the reference build. |
| 58 if 'frameCount' in rendering_stats_deltas: |
| 59 frame_count = rendering_stats_deltas.get('frameCount', 0) |
| 60 else: |
| 61 frame_count = rendering_stats_deltas.get('numFramesSentToScreen', 0) |
| 62 |
| 63 if not (frame_count > 0): |
65 raise DidNotScrollException() | 64 raise DidNotScrollException() |
66 | 65 |
67 timeline = self._trace_result.AsTimelineModel() | 66 timeline = self._trace_result.AsTimelineModel() |
68 smoothness_marker = smoothness.FindTimelineMarker(timeline, | 67 smoothness_marker = smoothness.FindTimelineMarker(timeline, |
69 smoothness.TIMELINE_MARKER) | 68 smoothness.TIMELINE_MARKER) |
70 # TODO(dominikg): remove try..except once CL 23532057 has been rolled to the | 69 # TODO(dominikg): remove try..except once CL 23532057 has been rolled to the |
71 # reference builds? | 70 # reference builds? |
72 try: | 71 try: |
73 gesture_marker = smoothness.FindTimelineMarker(timeline, | 72 gesture_marker = smoothness.FindTimelineMarker(timeline, |
74 smoothness.SYNTHETIC_GESTURE_MARKER) | 73 smoothness.SYNTHETIC_GESTURE_MARKER) |
75 except smoothness.MissingTimelineMarker: | 74 except smoothness.MissingTimelineMarker: |
76 logging.warning( | 75 logging.warning( |
77 'No gesture marker found in timeline; using smoothness marker instead.') | 76 'No gesture marker found in timeline; using smoothness marker instead.') |
78 gesture_marker = smoothness_marker | 77 gesture_marker = smoothness_marker |
79 benchmark_stats = GpuRenderingStats(smoothness_marker, | 78 benchmark_stats = RenderingStats(smoothness_marker, |
80 gesture_marker, | 79 gesture_marker, |
81 rendering_stats_deltas, | 80 rendering_stats_deltas, |
82 self._metrics.is_using_gpu_benchmarking) | 81 self._metrics.is_using_gpu_benchmarking) |
83 smoothness.CalcResults(benchmark_stats, results) | 82 smoothness.CalcResults(benchmark_stats, results) |
84 | 83 |
85 if self.options.report_all_results: | |
86 for k, v in rendering_stats_deltas.iteritems(): | |
87 results.Add(k, '', v) | |
88 | |
89 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 84 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
90 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 85 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
91 if r.value is None: | 86 if r.value is None: |
92 raise MissingDisplayFrameRate(r.name) | 87 raise MissingDisplayFrameRate(r.name) |
93 results.Add(r.name, r.unit, r.value) | 88 results.Add(r.name, r.unit, r.value) |
OLD | NEW |