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 action_name_to_run
='RunPageInteractions')
18 self
._power
_metric
= None
20 def CustomizeBrowserOptions(self
, options
):
21 options
.AppendExtraBrowserArgs('--enable-gpu-benchmarking')
22 power
.PowerMetric
.CustomizeBrowserOptions(options
)
24 def WillStartBrowser(self
, platform
):
25 self
._power
_metric
= power
.PowerMetric(platform
)
27 def WillNavigateToPage(self
, page
, tab
):
28 tab
.ExecuteJavaScript("""
30 chrome.gpuBenchmarking &&
31 chrome.gpuBenchmarking.clearImageCache) {
32 chrome.gpuBenchmarking.clearImageCache();
35 self
._power
_metric
.Start(page
, tab
)
37 options
= tracing_options
.TracingOptions()
38 options
.enable_chrome_trace
= True
39 # FIXME: Remove the timeline category when impl-side painting is on
41 category_filter
= tracing_category_filter
.TracingCategoryFilter(
42 'disabled-by-default-devtools.timeline')
44 # FIXME: Remove webkit.console when blink.console lands in chromium and
45 # the ref builds are updated. crbug.com/386847
46 # FIXME: Remove the devtools.timeline category when impl-side painting is
55 category_filter
.AddIncludedCategory(c
)
56 tab
.browser
.platform
.tracing_controller
.Start(options
, category_filter
)
58 def StopBrowserAfterPage(self
, browser
, page
):
59 return not browser
.tabs
[0].ExecuteJavaScript("""
61 chrome.gpuBenchmarking &&
62 chrome.gpuBenchmarking.clearImageCache;
65 def ValidateAndMeasurePage(self
, page
, tab
, results
):
66 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
67 timeline_model
= model
.TimelineModel(timeline_data
)
68 self
._power
_metric
.Stop(page
, tab
)
69 self
._power
_metric
.AddResults(tab
, results
)
72 return tab
.EvaluateJavaScript('isDone')
74 decode_image_events
= timeline_model
.GetAllEventsOfName(
75 'ImageFrameGenerator::decode')
76 # FIXME: Remove this when impl-side painting is on everywhere.
77 if not decode_image_events
:
78 decode_image_events
= timeline_model
.GetAllEventsOfName('Decode Image')
80 # If it is a real image page, then store only the last-minIterations
83 'image_decoding_measurement_limit_results_to_min_iterations') and
84 page
.image_decoding_measurement_limit_results_to_min_iterations
):
86 min_iterations
= tab
.EvaluateJavaScript('minIterations')
87 decode_image_events
= decode_image_events
[-min_iterations
:]
89 durations
= [d
.duration
for d
in decode_image_events
]
90 assert durations
, 'Failed to find image decode trace events.'
92 image_decoding_avg
= sum(durations
) / len(durations
)
93 results
.AddValue(scalar
.ScalarValue(
94 results
.current_page
, 'ImageDecoding_avg', 'ms', image_decoding_avg
,
95 description
='Average decode time for images in 4 different '
96 'formats: gif, png, jpg, and webp. The image files are '
97 'located at chrome/test/data/image_decoding.'))
98 results
.AddValue(scalar
.ScalarValue(
99 results
.current_page
, 'ImageLoading_avg', 'ms',
100 tab
.EvaluateJavaScript('averageLoadingTimeMs()')))
102 def CleanUpAfterPage(self
, page
, tab
):
103 tracing_controller
= tab
.browser
.platform
.tracing_controller
104 if tracing_controller
.is_tracing_running
:
105 tracing_controller
.Stop()