| OLD | NEW |
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 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 from metrics import power | 5 from metrics import power |
| 6 from telemetry.page import page_measurement | 6 from telemetry.page import page_measurement |
| 7 from telemetry.timeline import model | 7 from telemetry.timeline import model |
| 8 | 8 |
| 9 | 9 |
| 10 class ImageDecoding(page_measurement.PageMeasurement): | 10 class ImageDecoding(page_measurement.PageMeasurement): |
| 11 def __init__(self): | 11 def __init__(self): |
| 12 super(ImageDecoding, self).__init__() | 12 super(ImageDecoding, self).__init__() |
| 13 self._power_metric = power.PowerMetric() | 13 self._power_metric = None |
| 14 | 14 |
| 15 def CustomizeBrowserOptions(self, options): | 15 def CustomizeBrowserOptions(self, options): |
| 16 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') | 16 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
| 17 power.PowerMetric.CustomizeBrowserOptions(options) | 17 power.PowerMetric.CustomizeBrowserOptions(options) |
| 18 | 18 |
| 19 def WillStartBrowser(self, browser): |
| 20 self._power_metric = power.PowerMetric(browser) |
| 21 |
| 19 def WillNavigateToPage(self, page, tab): | 22 def WillNavigateToPage(self, page, tab): |
| 20 tab.ExecuteJavaScript(""" | 23 tab.ExecuteJavaScript(""" |
| 21 if (window.chrome && | 24 if (window.chrome && |
| 22 chrome.gpuBenchmarking && | 25 chrome.gpuBenchmarking && |
| 23 chrome.gpuBenchmarking.clearImageCache) { | 26 chrome.gpuBenchmarking.clearImageCache) { |
| 24 chrome.gpuBenchmarking.clearImageCache(); | 27 chrome.gpuBenchmarking.clearImageCache(); |
| 25 } | 28 } |
| 26 """) | 29 """) |
| 27 self._power_metric.Start(page, tab) | 30 self._power_metric.Start(page, tab) |
| 28 # FIXME: bare 'devtools' is for compatibility with older reference versions | 31 # FIXME: bare 'devtools' is for compatibility with older reference versions |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 assert durations, 'Failed to find "Decode Image" trace events.' | 67 assert durations, 'Failed to find "Decode Image" trace events.' |
| 65 | 68 |
| 66 image_decoding_avg = sum(durations) / len(durations) | 69 image_decoding_avg = sum(durations) / len(durations) |
| 67 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) | 70 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) |
| 68 results.Add('ImageLoading_avg', 'ms', | 71 results.Add('ImageLoading_avg', 'ms', |
| 69 tab.EvaluateJavaScript('averageLoadingTimeMs()')) | 72 tab.EvaluateJavaScript('averageLoadingTimeMs()')) |
| 70 | 73 |
| 71 def CleanUpAfterPage(self, page, tab): | 74 def CleanUpAfterPage(self, page, tab): |
| 72 if tab.browser.is_tracing_running: | 75 if tab.browser.is_tracing_running: |
| 73 tab.browser.StopTracing() | 76 tab.browser.StopTracing() |
| OLD | NEW |