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 25 matching lines...) Expand all Loading... |
36 | 36 |
37 def CustomizeBrowserOptions(self, options): | 37 def CustomizeBrowserOptions(self, options): |
38 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) | 38 smoothness.SmoothnessMetrics.CustomizeBrowserOptions(options) |
39 if self.force_enable_threaded_compositing: | 39 if self.force_enable_threaded_compositing: |
40 options.AppendExtraBrowserArgs('--enable-threaded-compositing') | 40 options.AppendExtraBrowserArgs('--enable-threaded-compositing') |
41 | 41 |
42 def CanRunForPage(self, page): | 42 def CanRunForPage(self, page): |
43 return hasattr(page, 'smoothness') | 43 return hasattr(page, 'smoothness') |
44 | 44 |
45 def WillRunAction(self, page, tab, action): | 45 def WillRunAction(self, page, tab, action): |
46 # TODO(ernstm): remove 'webkit' category when | 46 # We don't need to start tracing, if a trace profiler is already running. |
47 # https://codereview.chromium.org/23848006/ has landed. | 47 # Note that all trace event categories are enabled in this case, which |
48 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) | 48 # increases the risk of a trace buffer overflow. |
| 49 if self.options.profiler != 'trace': |
| 50 tab.browser.StartTracing('webkit.console,benchmark', 60) |
49 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 51 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
50 tab.browser.platform.StartRawDisplayFrameRateMeasurement() | 52 tab.browser.platform.StartRawDisplayFrameRateMeasurement() |
51 self._metrics = smoothness.SmoothnessMetrics(tab) | 53 self._metrics = smoothness.SmoothnessMetrics(tab) |
52 if action.CanBeBound(): | 54 if action.CanBeBound(): |
53 self._metrics.BindToAction(action) | 55 self._metrics.BindToAction(action) |
54 else: | 56 else: |
55 self._metrics.Start() | 57 self._metrics.Start() |
56 | 58 |
57 def DidRunAction(self, page, tab, action): | 59 def DidRunAction(self, page, tab, action): |
58 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 60 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
59 tab.browser.platform.StopRawDisplayFrameRateMeasurement() | 61 tab.browser.platform.StopRawDisplayFrameRateMeasurement() |
60 if not action.CanBeBound(): | 62 if not action.CanBeBound(): |
61 self._metrics.Stop() | 63 self._metrics.Stop() |
| 64 # Always stop tracing at this point. If a trace profiler is running, it will |
| 65 # be stopped here. |
62 tab.browser.StopTracing() | 66 tab.browser.StopTracing() |
63 | 67 |
64 def FindTimelineMarker(self, timeline): | 68 def FindTimelineMarker(self, timeline): |
65 events = [s for | 69 events = [s for |
66 s in timeline.GetAllEventsOfName( | 70 s in timeline.GetAllEventsOfName( |
67 smoothness.TIMELINE_MARKER) | 71 smoothness.TIMELINE_MARKER) |
68 if s.parent_slice == None] | 72 if s.parent_slice == None] |
69 if len(events) != 1: | 73 if len(events) != 1: |
70 raise MissingTimelineMarker() | 74 raise MissingTimelineMarker() |
71 return events[0] | 75 return events[0] |
72 | 76 |
73 def MeasurePage(self, page, tab, results): | 77 def MeasurePage(self, page, tab, results): |
74 rendering_stats_deltas = self._metrics.deltas | 78 rendering_stats_deltas = self._metrics.deltas |
75 | 79 |
76 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): | 80 if not (rendering_stats_deltas['numFramesSentToScreen'] > 0): |
77 raise DidNotScrollException() | 81 raise DidNotScrollException() |
78 | 82 |
79 loading.LoadingMetric().AddResults(tab, results) | 83 loading.LoadingMetric().AddResults(tab, results) |
80 | 84 |
81 smoothness.CalcFirstPaintTimeResults(results, tab) | 85 smoothness.CalcFirstPaintTimeResults(results, tab) |
82 | 86 |
83 timeline = tab.browser.GetTraceResultAndReset().AsTimelineModel() | 87 # Fetch the results without resetting, if a trace profiler is running. The |
| 88 # profiler needs to read the results later on. |
| 89 if self.options.profiler == 'trace': |
| 90 timeline = tab.browser.GetTraceResult().AsTimelineModel() |
| 91 else: |
| 92 timeline = tab.browser.GetTraceResultAndReset().AsTimelineModel() |
84 timeline_marker = self.FindTimelineMarker(timeline) | 93 timeline_marker = self.FindTimelineMarker(timeline) |
85 benchmark_stats = GpuRenderingStats(timeline_marker, | 94 benchmark_stats = GpuRenderingStats(timeline_marker, |
86 rendering_stats_deltas, | 95 rendering_stats_deltas, |
87 self._metrics.is_using_gpu_benchmarking) | 96 self._metrics.is_using_gpu_benchmarking) |
88 smoothness.CalcResults(benchmark_stats, results) | 97 smoothness.CalcResults(benchmark_stats, results) |
89 | 98 |
90 if self.options.report_all_results: | 99 if self.options.report_all_results: |
91 for k, v in rendering_stats_deltas.iteritems(): | 100 for k, v in rendering_stats_deltas.iteritems(): |
92 results.Add(k, '', v) | 101 results.Add(k, '', v) |
93 | 102 |
94 if tab.browser.platform.IsRawDisplayFrameRateSupported(): | 103 if tab.browser.platform.IsRawDisplayFrameRateSupported(): |
95 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): | 104 for r in tab.browser.platform.GetRawDisplayFrameRateMeasurements(): |
96 if r.value is None: | 105 if r.value is None: |
97 raise MissingDisplayFrameRate(r.name) | 106 raise MissingDisplayFrameRate(r.name) |
98 results.Add(r.name, r.unit, r.value) | 107 results.Add(r.name, r.unit, r.value) |
OLD | NEW |