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
):
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("""
21 chrome.gpuBenchmarking &&
22 chrome.gpuBenchmarking.clearImageCache) {
23 chrome.gpuBenchmarking.clearImageCache();
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("""
34 chrome.gpuBenchmarking &&
35 chrome.gpuBenchmarking.clearImageCache;
38 def MeasurePage(self
, page
, tab
, results
):
39 tab
.StopTimelineRecording()
40 self
._power
_metric
.Stop(page
, tab
)
41 self
._power
_metric
.AddResults(tab
, results
)
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
52 'image_decoding_measurement_limit_results_to_min_iterations') and
53 page
.image_decoding_measurement_limit_results_to_min_iterations
):
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
]
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()'))