Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / tools / perf / measurements / image_decoding.py
blob3139f1cf4bc9e6bdf167058beb3a065e165accaa
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
3 # found in the LICENSE file.
5 from metrics import power
6 from telemetry.page import page_measurement
9 class ImageDecoding(page_measurement.PageMeasurement):
10 def __init__(self):
11 super(ImageDecoding, self).__init__()
12 self._power_metric = power.PowerMetric()
14 def CustomizeBrowserOptions(self, options):
15 options.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
16 power.PowerMetric.CustomizeBrowserOptions(options)
18 def WillNavigateToPage(self, page, tab):
19 tab.ExecuteJavaScript("""
20 if (window.chrome &&
21 chrome.gpuBenchmarking &&
22 chrome.gpuBenchmarking.clearImageCache) {
23 chrome.gpuBenchmarking.clearImageCache();
25 """)
27 def DidNavigateToPage(self, page, tab):
28 self._power_metric.Start(page, tab)
29 tab.StartTimelineRecording()
31 def StopBrowserAfterPage(self, browser, page):
32 return not browser.tabs[0].ExecuteJavaScript("""
33 window.chrome &&
34 chrome.gpuBenchmarking &&
35 chrome.gpuBenchmarking.clearImageCache;
36 """)
38 def MeasurePage(self, page, tab, results):
39 tab.StopTimelineRecording()
40 self._power_metric.Stop(page, tab)
41 self._power_metric.AddResults(tab, results)
43 def _IsDone():
44 return tab.EvaluateJavaScript('isDone')
46 decode_image_events = \
47 tab.timeline_model.GetAllEventsOfName('DecodeImage')
49 # If it is a real image page, then store only the last-minIterations
50 # decode tasks.
51 if (hasattr(page,
52 'image_decoding_measurement_limit_results_to_min_iterations') and
53 page.image_decoding_measurement_limit_results_to_min_iterations):
54 assert _IsDone()
55 min_iterations = tab.EvaluateJavaScript('minIterations')
56 decode_image_events = decode_image_events[-min_iterations:]
58 durations = [d.duration for d in decode_image_events]
59 if not durations:
60 return
61 image_decoding_avg = sum(durations) / len(durations)
62 results.Add('ImageDecoding_avg', 'ms', image_decoding_avg)
63 results.Add('ImageLoading_avg', 'ms',
64 tab.EvaluateJavaScript('averageLoadingTimeMs()'))