Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 | 4 |
| 5 import time | 5 import time |
| 6 | 6 |
| 7 from metrics import smoothness | 7 from metrics import smoothness |
| 8 from telemetry.page import page_measurement | 8 from telemetry.page import page_measurement |
| 9 | 9 |
| 10 class StatsCollector(object): | 10 class StatsCollector(object): |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 # first frame requested has more variance in the number of pixels | 141 # first frame requested has more variance in the number of pixels |
| 142 # rasterized. | 142 # rasterized. |
| 143 tab.ExecuteJavaScript(""" | 143 tab.ExecuteJavaScript(""" |
| 144 window.__rafFired = false; | 144 window.__rafFired = false; |
| 145 window.webkitRequestAnimationFrame(function() { | 145 window.webkitRequestAnimationFrame(function() { |
| 146 chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers(); | 146 chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers(); |
| 147 window.__rafFired = true; | 147 window.__rafFired = true; |
| 148 }); | 148 }); |
| 149 """) | 149 """) |
| 150 | 150 |
| 151 tab.browser.StartTracing('webkit,webkit.console,benchmark', 60) | 151 # We don't need to start tracing, if a trace profiler is already running. |
| 152 # Note that all trace event categories are enabled in this case, which | |
| 153 # increases the risk of a trace buffer overflow. | |
| 154 if self.options.profiler != 'trace': | |
|
tonyg
2013/09/11 21:31:44
Making this Measurement aware of profilers which a
| |
| 155 tab.browser.StartTracing('webkit.console,benchmark', 60) | |
| 152 self._metrics.Start() | 156 self._metrics.Start() |
| 153 | 157 |
| 154 tab.ExecuteJavaScript(""" | 158 tab.ExecuteJavaScript(""" |
| 155 console.time("measureNextFrame"); | 159 console.time("measureNextFrame"); |
| 156 window.__rafFired = false; | 160 window.__rafFired = false; |
| 157 window.webkitRequestAnimationFrame(function() { | 161 window.webkitRequestAnimationFrame(function() { |
| 158 chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers(); | 162 chrome.gpuBenchmarking.setNeedsDisplayOnAllLayers(); |
| 159 window.__rafFired = true; | 163 window.__rafFired = true; |
| 160 }); | 164 }); |
| 161 """) | 165 """) |
| 162 # Wait until the frame was drawn. | 166 # Wait until the frame was drawn. |
| 163 # Needs to be adjusted for every device and for different | 167 # Needs to be adjusted for every device and for different |
| 164 # raster_record_repeat counts. | 168 # raster_record_repeat counts. |
| 165 # TODO(ernstm): replace by call-back. | 169 # TODO(ernstm): replace by call-back. |
| 166 time.sleep(float(self.options.stop_wait_time)) | 170 time.sleep(float(self.options.stop_wait_time)) |
| 167 tab.ExecuteJavaScript('console.timeEnd("measureNextFrame")') | 171 tab.ExecuteJavaScript('console.timeEnd("measureNextFrame")') |
| 168 | 172 |
| 173 # Always stop tracing at this point. If a trace profiler is running, it will | |
| 174 # be stopped here. | |
| 169 tab.browser.StopTracing() | 175 tab.browser.StopTracing() |
| 170 self._metrics.Stop() | 176 self._metrics.Stop() |
| 171 | 177 |
| 172 timeline = tab.browser.GetTraceResultAndReset().AsTimelineModel() | 178 # Fetch the results without resetting, if a trace profiler is running. The |
| 179 # profiler needs to read the results later on. | |
| 180 if self.options.profiler == 'trace': | |
| 181 timeline = tab.browser.GetTraceResult().AsTimelineModel() | |
| 182 else: | |
| 183 timeline = tab.browser.GetTraceResultAndReset().AsTimelineModel() | |
| 173 collector = StatsCollector(timeline) | 184 collector = StatsCollector(timeline) |
| 174 collector.GatherRenderingStats() | 185 collector.GatherRenderingStats() |
| 175 | 186 |
| 176 rendering_stats = self._metrics.end_values | 187 rendering_stats = self._metrics.end_values |
| 177 | 188 |
| 178 results.Add('best_rasterize_time', 'seconds', | 189 results.Add('best_rasterize_time', 'seconds', |
| 179 collector.total_best_rasterize_time / 1.e3, | 190 collector.total_best_rasterize_time / 1.e3, |
| 180 data_type='unimportant') | 191 data_type='unimportant') |
| 181 results.Add('best_record_time', 'seconds', | 192 results.Add('best_record_time', 'seconds', |
| 182 collector.total_best_record_time / 1.e3, | 193 collector.total_best_record_time / 1.e3, |
| 183 data_type='unimportant') | 194 data_type='unimportant') |
| 184 results.Add('total_pixels_rasterized', 'pixels', | 195 results.Add('total_pixels_rasterized', 'pixels', |
| 185 collector.total_pixels_rasterized, | 196 collector.total_pixels_rasterized, |
| 186 data_type='unimportant') | 197 data_type='unimportant') |
| 187 results.Add('total_pixels_recorded', 'pixels', | 198 results.Add('total_pixels_recorded', 'pixels', |
| 188 collector.total_pixels_recorded, | 199 collector.total_pixels_recorded, |
| 189 data_type='unimportant') | 200 data_type='unimportant') |
| 190 | 201 |
| 191 if self.options.report_all_results: | 202 if self.options.report_all_results: |
| 192 for k, v in rendering_stats.iteritems(): | 203 for k, v in rendering_stats.iteritems(): |
| 193 results.Add(k, '', v) | 204 results.Add(k, '', v) |
| OLD | NEW |