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 from telemetry.page import page_measurement | 5 from telemetry.page import page_measurement |
6 | 6 |
7 | 7 |
8 class ImageDecoding(page_measurement.PageMeasurement): | 8 class ImageDecoding(page_measurement.PageMeasurement): |
9 def CustomizeBrowserOptions(self, options): | 9 def CustomizeBrowserOptions(self, options): |
10 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') | 10 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') |
11 | 11 |
12 def WillNavigateToPage(self, page, tab): | 12 def WillNavigateToPage(self, page, tab): |
13 tab.ExecuteJavaScript(""" | 13 tab.ExecuteJavaScript(""" |
14 if (window.chrome && | 14 if (window.chrome && |
15 chrome.gpuBenchmarking && | 15 chrome.gpuBenchmarking && |
16 chrome.gpuBenchmarking.clearImageCache) { | 16 chrome.gpuBenchmarking.clearImageCache) { |
17 chrome.gpuBenchmarking.clearImageCache(); | 17 chrome.gpuBenchmarking.clearImageCache(); |
18 } | 18 } |
19 """) | 19 """) |
20 tab.StartTimelineRecording() | 20 tab.StartTimelineRecording() |
21 | 21 |
22 def NeedsBrowserRestartAfterEachRun(self, browser): | 22 def NeedsBrowserRestartBeforeNextPage(self, browser): |
23 return not browser.tabs[0].ExecuteJavaScript(""" | 23 return not browser.tabs[0].ExecuteJavaScript(""" |
24 window.chrome && | 24 window.chrome && |
25 chrome.gpuBenchmarking && | 25 chrome.gpuBenchmarking && |
26 chrome.gpuBenchmarking.clearImageCache; | 26 chrome.gpuBenchmarking.clearImageCache; |
27 """) | 27 """) |
28 | 28 |
29 def MeasurePage(self, page, tab, results): | 29 def MeasurePage(self, page, tab, results): |
30 tab.StopTimelineRecording() | 30 tab.StopTimelineRecording() |
31 def _IsDone(): | 31 def _IsDone(): |
32 return tab.EvaluateJavaScript('isDone') | 32 return tab.EvaluateJavaScript('isDone') |
(...skipping 11 matching lines...) Expand all Loading... |
44 decode_image_events = decode_image_events[-min_iterations:] | 44 decode_image_events = decode_image_events[-min_iterations:] |
45 | 45 |
46 durations = [d.duration for d in decode_image_events] | 46 durations = [d.duration for d in decode_image_events] |
47 if not durations: | 47 if not durations: |
48 results.Add('ImageDecoding_avg', 'ms', 'unsupported') | 48 results.Add('ImageDecoding_avg', 'ms', 'unsupported') |
49 return | 49 return |
50 image_decoding_avg = sum(durations) / len(durations) | 50 image_decoding_avg = sum(durations) / len(durations) |
51 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) | 51 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg) |
52 results.Add('ImageLoading_avg', 'ms', | 52 results.Add('ImageLoading_avg', 'ms', |
53 tab.EvaluateJavaScript('averageLoadingTimeMs()')) | 53 tab.EvaluateJavaScript('averageLoadingTimeMs()')) |
OLD | NEW |