1 # Copyright 2013 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.
8 from telemetry
.core
.util
import TimeoutException
9 from telemetry
.page
import page_test
10 from telemetry
.value
import scalar
13 class RasterizeAndRecordMicro(page_test
.PageTest
):
14 def __init__(self
, start_wait_time
=2, rasterize_repeat
=100, record_repeat
=100,
15 timeout
=120, report_detailed_results
=False):
16 super(RasterizeAndRecordMicro
, self
).__init
__('')
17 self
._chrome
_branch
_number
= None
18 self
._start
_wait
_time
= start_wait_time
19 self
._rasterize
_repeat
= rasterize_repeat
20 self
._record
_repeat
= record_repeat
21 self
._timeout
= timeout
22 self
._report
_detailed
_results
= report_detailed_results
24 def CustomizeBrowserOptions(self
, options
):
25 options
.AppendExtraBrowserArgs([
26 '--enable-impl-side-painting',
27 '--enable-threaded-compositing',
28 '--enable-gpu-benchmarking'
31 def DidStartBrowser(self
, browser
):
32 # TODO(vmpstr): Remove this temporary workaround when reference build has
33 # been updated to branch 1713 or later.
34 backend
= browser
._browser
_backend
# pylint: disable=W0212
35 self
._chrome
_branch
_number
= getattr(backend
, 'chrome_branch_number', None)
36 if (not self
._chrome
_branch
_number
or
37 (sys
.platform
!= 'android' and self
._chrome
_branch
_number
< 1713)):
38 raise page_test
.TestNotSupportedOnPlatformFailure(
39 'rasterize_and_record_micro requires Chrome branch 1713 '
40 'or later. Skipping measurement.')
42 def ValidateAndMeasurePage(self
, page
, tab
, results
):
44 tab
.WaitForDocumentReadyStateToBeComplete()
45 except TimeoutException
:
47 time
.sleep(self
._start
_wait
_time
)
50 tab
.ExecuteJavaScript("""
51 window.benchmark_results = {};
52 window.benchmark_results.done = false;
53 window.benchmark_results.id =
54 chrome.gpuBenchmarking.runMicroBenchmark(
55 "rasterize_and_record_benchmark",
57 window.benchmark_results.done = true;
58 window.benchmark_results.results = value;
60 "record_repeat_count": %i,
61 "rasterize_repeat_count": %i
63 """ % (self
._record
_repeat
, self
._rasterize
_repeat
))
65 benchmark_id
= tab
.EvaluateJavaScript('window.benchmark_results.id')
66 if (not benchmark_id
):
67 raise page_test
.MeasurementFailure(
68 'Failed to schedule rasterize_and_record_micro')
70 tab
.WaitForJavaScriptExpression(
71 'window.benchmark_results.done', self
._timeout
)
73 data
= tab
.EvaluateJavaScript('window.benchmark_results.results')
75 pixels_recorded
= data
['pixels_recorded']
76 record_time
= data
['record_time_ms']
77 pixels_rasterized
= data
['pixels_rasterized']
78 rasterize_time
= data
['rasterize_time_ms']
80 results
.AddValue(scalar
.ScalarValue(
81 results
.current_page
, 'pixels_recorded', 'pixels', pixels_recorded
))
82 results
.AddValue(scalar
.ScalarValue(
83 results
.current_page
, 'record_time', 'ms', record_time
))
84 results
.AddValue(scalar
.ScalarValue(
85 results
.current_page
, 'pixels_rasterized', 'pixels', pixels_rasterized
))
86 results
.AddValue(scalar
.ScalarValue(
87 results
.current_page
, 'rasterize_time', 'ms', rasterize_time
))
89 # TODO(skyostil): Remove this temporary workaround when reference build has
90 # been updated to branch 1931 or later.
91 if ((self
._chrome
_branch
_number
and self
._chrome
_branch
_number
>= 1931) or
92 sys
.platform
== 'android'):
93 record_time_sk_null_canvas
= data
['record_time_sk_null_canvas_ms']
94 record_time_painting_disabled
= data
['record_time_painting_disabled_ms']
95 results
.AddValue(scalar
.ScalarValue(
96 results
.current_page
, 'record_time_sk_null_canvas', 'ms',
97 record_time_sk_null_canvas
))
98 results
.AddValue(scalar
.ScalarValue(
99 results
.current_page
, 'record_time_painting_disabled', 'ms',
100 record_time_painting_disabled
))
102 if self
._report
_detailed
_results
:
103 pixels_rasterized_with_non_solid_color
= \
104 data
['pixels_rasterized_with_non_solid_color']
105 pixels_rasterized_as_opaque
= \
106 data
['pixels_rasterized_as_opaque']
107 total_layers
= data
['total_layers']
108 total_picture_layers
= data
['total_picture_layers']
109 total_picture_layers_with_no_content
= \
110 data
['total_picture_layers_with_no_content']
111 total_picture_layers_off_screen
= \
112 data
['total_picture_layers_off_screen']
114 results
.AddValue(scalar
.ScalarValue(
115 results
.current_page
, 'pixels_rasterized_with_non_solid_color',
116 'pixels', pixels_rasterized_with_non_solid_color
))
117 results
.AddValue(scalar
.ScalarValue(
118 results
.current_page
, 'pixels_rasterized_as_opaque', 'pixels',
119 pixels_rasterized_as_opaque
))
120 results
.AddValue(scalar
.ScalarValue(
121 results
.current_page
, 'total_layers', 'count', total_layers
))
122 results
.AddValue(scalar
.ScalarValue(
123 results
.current_page
, 'total_picture_layers', 'count',
124 total_picture_layers
))
125 results
.AddValue(scalar
.ScalarValue(
126 results
.current_page
, 'total_picture_layers_with_no_content', 'count',
127 total_picture_layers_with_no_content
))
128 results
.AddValue(scalar
.ScalarValue(
129 results
.current_page
, 'total_picture_layers_off_screen', 'count',
130 total_picture_layers_off_screen
))