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 from metrics import loading | 4 from metrics import loading |
5 from metrics import smoothness | 5 from metrics import smoothness |
6 from metrics.gpu_rendering_stats import GpuRenderingStats | 6 from metrics.gpu_rendering_stats import GpuRenderingStats |
7 from telemetry.page import page_measurement | 7 from telemetry.page import page_measurement |
8 | 8 |
9 | 9 |
10 class DidNotScrollException(page_measurement.MeasurementFailure): | 10 class DidNotScrollException(page_measurement.MeasurementFailure): |
(...skipping 10 matching lines...) Expand all Loading... |
21 class MissingTimelineMarker(page_measurement.MeasurementFailure): | 21 class MissingTimelineMarker(page_measurement.MeasurementFailure): |
22 def __init__(self): | 22 def __init__(self): |
23 super(MissingTimelineMarker, self).__init__('Timeline marker not found') | 23 super(MissingTimelineMarker, self).__init__('Timeline marker not found') |
24 | 24 |
25 | 25 |
26 class Smoothness(page_measurement.PageMeasurement): | 26 class Smoothness(page_measurement.PageMeasurement): |
27 def __init__(self): | 27 def __init__(self): |
28 super(Smoothness, self).__init__('smoothness') | 28 super(Smoothness, self).__init__('smoothness') |
29 self.force_enable_threaded_compositing = False | 29 self.force_enable_threaded_compositing = False |
30 self._metrics = None | 30 self._metrics = None |
| 31 self._trace_result = None |
31 | 32 |
32 def AddCommandLineOptions(self, parser): | 33 def AddCommandLineOptions(self, parser): |
33 parser.add_option('--report-all-results', dest='report_all_results', | 34 parser.add_option('--report-all-results', dest='report_all_results', |
34 action='store_true', | 35 action='store_true', |
35 help='Reports all data collected, not just FPS') | 36 help='Reports all data collected, not just FPS') |
36 | 37 |
37 def CustomizeBrowserOptions(self, options): | 38 def CustomizeBrowserOptions(self, options): |
38 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) | 39 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) |
39 if self.force_enable_threaded_compositing: | 40 if self.force_enable_threaded_compositing: |
40 options.AppendExtraBrowserArgs('--enable-threaded-compositing') | 41 options.AppendExtraBrowserArgs('--enable-threaded-compositing') |
41 | 42 |
42 def CanRunForPage(self, page): | 43 def CanRunForPage(self, page): |
43 return hasattr(page, 'smoothness') | 44 return hasattr(page, 'smoothness') |
44 | 45 |
45 def WillRunAction(self, page, tab, action): | 46 def WillRunAction(self, page, tab, action): |
46 # TODO(ernstm): remove 'webkit' category when | 47 tab.browser.StartTracing('webkit.console,benchmark', 60) |
47 # https://codereview.chromium.org/23848006/ has landed. | |
48 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) | |
49 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 48 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
50 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 49 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
51 self._metrics = smoothness.SmoothnessMetrics(tab) | 50 self._metrics = smoothness.SmoothnessMetrics(tab) |
52 if action.CanBeBound(): | 51 if action.CanBeBound(): |
53 self._metrics.BindToAction(action) | 52 self._metrics.BindToAction(action) |
54 else: | 53 else: |
55 self._metrics.Start() | 54 self._metrics.Start() |
56 | 55 |
57 def DidRunAction(self, page, tab, action): | 56 def DidRunAction(self, page, tab, action): |
58 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 57 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
59 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 58 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
60 if not action.CanBeBound(): | 59 if not action.CanBeBound(): |
61 self._metrics.Stop() | 60 self._metrics.Stop() |
62 tab.browser.StopTracing() | 61 self._trace_result = tab.browser.StopTracing() |
63 | 62 |
64 def FindTimelineMarker(self, timeline): | 63 def FindTimelineMarker(self, timeline): |
65 events = [s for | 64 events = [s for |
66 s in timeline.GetAllEventsOfName( | 65 s in timeline.GetAllEventsOfName( |
67 smoothness.TIMELINE_MARKER) | 66 smoothness.TIMELINE_MARKER) |
68 if s.parent_slice == None] | 67 if s.parent_slice == None] |
69 if len(events) != 1: | 68 if len(events) != 1: |
70 raise MissingTimelineMarker() | 69 raise MissingTimelineMarker() |
71 return events[0] | 70 return events[0] |
72 | 71 |
73 def MeasurePage(self, page, tab, results): | 72 def MeasurePage(self, page, tab, results): |
74 rendering_stats_deltas = self._metrics.deltas | 73 rendering_stats_deltas = self._metrics.deltas |
75 | 74 |
76 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): | 75 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): |
77 raise DidNotScrollException() | 76 raise DidNotScrollException() |
78 | 77 |
79 loading.LoadingMetric().AddResults(tab, results) | 78 loading.LoadingMetric().AddResults(tab, results) |
80 | 79 |
81 smoothness.CalcFirstPaintTimeResults(results, tab) | 80 smoothness.CalcFirstPaintTimeResults(results, tab) |
82 | 81 |
83 timeline = tab.browser.GetTraceResultAndReset().AsTimelineModel() | 82 timeline_marker = self.FindTimelineMarker( |
84 timeline_marker = self.FindTimelineMarker(timeline) | 83 self._trace_result.AsTimelineModel()) |
85 benchmark_stats = GpuRenderingStats(timeline_marker, | 84 benchmark_stats = GpuRenderingStats(timeline_marker, |
86 rendering_stats_deltas, | 85 rendering_stats_deltas, |
87 self._metrics.is_using_gpu_benchmarking) | 86 self._metrics.is_using_gpu_benchmarking) |
88 smoothness.CalcResults(benchmark_stats, results) | 87 smoothness.CalcResults(benchmark_stats, results) |
89 | 88 |
90 if self.options.report_all_results: | 89 if self.options.report_all_results: |
91 for k, v in rendering_stats_deltas.iteritems(): | 90 for k, v in rendering_stats_deltas.iteritems(): |
92 results.Add(k, '', v) | 91 results.Add(k, '', v) |
93 | 92 |
94 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 93 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
95 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 94 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
96 if r.value is None: | 95 if r.value is None: |
97 raise MissingDisplayFrameRate(r.name) | 96 raise MissingDisplayFrameRate(r.name) |
98 results.Add(r.name, r.unit, r.value) | 97 results.Add(r.name, r.unit, r.value) |
OLD | NEW |