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
3 # found in the LICENSE file.
5 from metrics
import power
7 from telemetry
.core
.platform
import tracing_category_filter
8 from telemetry
.core
.platform
import tracing_options
9 from telemetry
.page
import page_test
10 from telemetry
.timeline
import model
11 from telemetry
.value
import scalar
14 class ImageDecoding(page_test
.PageTest
):
16 super(ImageDecoding
, self
).__init
__()
17 self
._power
_metric
= None
19 def CustomizeBrowserOptions(self
, options
):
20 options
.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
21 power
.PowerMetric
.CustomizeBrowserOptions(options
)
23 def WillStartBrowser(self
, platform
):
24 self
._power
_metric
= power
.PowerMetric(platform
)
26 def WillNavigateToPage(self
, page
, tab
):
27 tab
.ExecuteJavaScript("""
29 chrome.gpuBenchmarking &&
30 chrome.gpuBenchmarking.clearImageCache) {
31 chrome.gpuBenchmarking.clearImageCache();
34 self
._power
_metric
.Start(page
, tab
)
36 options
= tracing_options
.TracingOptions()
37 options
.enable_chrome_trace
= True
38 # FIXME: Remove the timeline category when impl-side painting is on
40 category_filter
= tracing_category_filter
.TracingCategoryFilter(
41 'disabled-by-default-devtools.timeline')
43 # FIXME: Remove webkit.console when blink.console lands in chromium and
44 # the ref builds are updated. crbug.com/386847
45 # FIXME: Remove the devtools.timeline category when impl-side painting is
54 category_filter
.AddIncludedCategory(c
)
55 tab
.browser
.platform
.tracing_controller
.Start(options
, category_filter
)
57 def StopBrowserAfterPage(self
, browser
, page
):
58 return not browser
.tabs
[0].ExecuteJavaScript("""
60 chrome.gpuBenchmarking &&
61 chrome.gpuBenchmarking.clearImageCache;
64 def ValidateAndMeasurePage(self
, page
, tab
, results
):
65 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
66 timeline_model
= model
.TimelineModel(timeline_data
)
67 self
._power
_metric
.Stop(page
, tab
)
68 self
._power
_metric
.AddResults(tab
, results
)
71 return tab
.EvaluateJavaScript('isDone')
73 decode_image_events
= timeline_model
.GetAllEventsOfName(
74 'ImageFrameGenerator::decode')
75 # FIXME: Remove this when impl-side painting is on everywhere.
76 if not decode_image_events
:
77 decode_image_events
= timeline_model
.GetAllEventsOfName('Decode Image')
79 # If it is a real image page, then store only the last-minIterations
82 'image_decoding_measurement_limit_results_to_min_iterations') and
83 page
.image_decoding_measurement_limit_results_to_min_iterations
):
85 min_iterations
= tab
.EvaluateJavaScript('minIterations')
86 decode_image_events
= decode_image_events
[-min_iterations
:]
88 durations
= [d
.duration
for d
in decode_image_events
]
89 assert durations
, 'Failed to find image decode trace events.'
91 image_decoding_avg
= sum(durations
) / len(durations
)
92 results
.AddValue(scalar
.ScalarValue(
93 results
.current_page
, 'ImageDecoding_avg', 'ms', image_decoding_avg
,
94 description
='Average decode time for images in 4 different '
95 'formats: gif, png, jpg, and webp. The image files are '
96 'located at chrome/test/data/image_decoding.'))
97 results
.AddValue(scalar
.ScalarValue(
98 results
.current_page
, 'ImageLoading_avg', 'ms',
99 tab
.EvaluateJavaScript('averageLoadingTimeMs()')))
101 def CleanUpAfterPage(self
, page
, tab
):
102 tracing_controller
= tab
.browser
.platform
.tracing_controller
103 if tracing_controller
.is_tracing_running
:
104 tracing_controller
.Stop()