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.
7 from telemetry
import benchmark
8 from telemetry
.core
import util
9 from telemetry
import page
as page_module
10 from telemetry
.page
import page_set
11 from telemetry
.page
import page_test
12 from telemetry
.value
import list_of_scalar_values
15 BLINK_PERF_BASE_DIR
= os
.path
.join(util
.GetChromiumSrcDir(),
16 'third_party', 'WebKit', 'PerformanceTests')
17 SKIPPED_FILE
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Skipped')
20 def CreatePageSetFromPath(path
, skipped_file
):
21 assert os
.path
.exists(path
)
27 if not path
.endswith('.html'):
29 if '../' in open(path
, 'r').read():
30 # If the page looks like it references its parent dir, include it.
31 serving_dirs
.add(os
.path
.dirname(os
.path
.dirname(path
)))
32 page_urls
.append('file://' + path
.replace('\\', '/'))
34 def _AddDir(dir_path
, skipped
):
35 for candidate_path
in os
.listdir(dir_path
):
36 if candidate_path
== 'resources':
38 candidate_path
= os
.path
.join(dir_path
, candidate_path
)
39 if candidate_path
.startswith(skipped
):
41 if os
.path
.isdir(candidate_path
):
42 _AddDir(candidate_path
, skipped
)
44 _AddPage(candidate_path
)
46 if os
.path
.isdir(path
):
48 if os
.path
.exists(skipped_file
):
49 for line
in open(skipped_file
, 'r').readlines():
51 if line
and not line
.startswith('#'):
52 skipped_path
= os
.path
.join(os
.path
.dirname(skipped_file
), line
)
53 skipped
.append(skipped_path
.replace('/', os
.sep
))
54 _AddDir(path
, tuple(skipped
))
57 ps
= page_set
.PageSet(file_path
=os
.getcwd()+os
.sep
,
58 serving_dirs
=serving_dirs
)
60 ps
.AddUserStory(page_module
.Page(url
, ps
, ps
.base_dir
))
64 class _BlinkPerfMeasurement(page_test
.PageTest
):
65 """Tuns a blink performance test and reports the results."""
67 super(_BlinkPerfMeasurement
, self
).__init
__()
68 with
open(os
.path
.join(os
.path
.dirname(__file__
),
69 'blink_perf.js'), 'r') as f
:
70 self
._blink
_perf
_js
= f
.read()
72 def WillNavigateToPage(self
, page
, tab
):
73 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
75 def CustomizeBrowserOptions(self
, options
):
76 options
.AppendExtraBrowserArgs([
77 '--js-flags=--expose_gc',
78 '--enable-experimental-web-platform-features',
79 '--disable-gesture-requirement-for-media-playback'
81 if 'content-shell' in options
.browser_type
:
82 options
.AppendExtraBrowserArgs('--expose-internals-for-testing')
84 def ValidateAndMeasurePage(self
, page
, tab
, results
):
85 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
87 log
= tab
.EvaluateJavaScript('document.getElementById("log").innerHTML')
89 for line
in log
.splitlines():
90 if not line
.startswith('values '):
93 values
= [float(v
.replace(',', '')) for v
in parts
[1:-1]]
95 metric
= page
.display_name
.split('.')[0].replace('/', '_')
96 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
97 results
.current_page
, metric
, units
, values
))
104 class _BlinkPerfFullFrameMeasurement(_BlinkPerfMeasurement
):
106 super(_BlinkPerfFullFrameMeasurement
, self
).__init
__()
107 self
._blink
_perf
_js
+= '\nwindow.fullFrameMeasurement = true;'
109 def CustomizeBrowserOptions(self
, options
):
110 super(_BlinkPerfFullFrameMeasurement
, self
).CustomizeBrowserOptions(
112 # Full layout measurement needs content_shell with internals testing API.
113 assert 'content-shell' in options
.browser_type
114 options
.AppendExtraBrowserArgs(['--expose-internals-for-testing'])
117 class BlinkPerfAnimation(benchmark
.Benchmark
):
119 test
= _BlinkPerfMeasurement
123 return 'blink_perf.animation'
125 def CreatePageSet(self
, options
):
126 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Animation')
127 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
130 class BlinkPerfBindings(benchmark
.Benchmark
):
132 test
= _BlinkPerfMeasurement
136 return 'blink_perf.bindings'
138 def CreatePageSet(self
, options
):
139 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Bindings')
140 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
143 @benchmark.Enabled('content-shell')
144 class BlinkPerfBlinkGC(benchmark
.Benchmark
):
146 test
= _BlinkPerfMeasurement
150 return 'blink_perf.blink_gc'
152 def CreatePageSet(self
, options
):
153 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'BlinkGC')
154 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
157 class BlinkPerfCSS(benchmark
.Benchmark
):
159 test
= _BlinkPerfMeasurement
163 return 'blink_perf.css'
165 def CreatePageSet(self
, options
):
166 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'CSS')
167 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
170 @benchmark.Disabled('win') # crbug.com/455796
171 class BlinkPerfCanvas(benchmark
.Benchmark
):
173 test
= _BlinkPerfMeasurement
177 return 'blink_perf.canvas'
179 def CreatePageSet(self
, options
):
180 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Canvas')
181 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
184 class BlinkPerfDOM(benchmark
.Benchmark
):
186 test
= _BlinkPerfMeasurement
190 return 'blink_perf.dom'
192 def CreatePageSet(self
, options
):
193 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'DOM')
194 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
197 class BlinkPerfEvents(benchmark
.Benchmark
):
199 test
= _BlinkPerfMeasurement
203 return 'blink_perf.events'
205 def CreatePageSet(self
, options
):
206 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Events')
207 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
210 @benchmark.Disabled('win8') # http://crbug.com/462350
211 class BlinkPerfLayout(benchmark
.Benchmark
):
213 test
= _BlinkPerfMeasurement
217 return 'blink_perf.layout'
219 def CreatePageSet(self
, options
):
220 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Layout')
221 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
224 @benchmark.Enabled('content-shell')
225 class BlinkPerfLayoutFullLayout(BlinkPerfLayout
):
226 tag
= 'layout_full_frame'
227 test
= _BlinkPerfFullFrameMeasurement
231 return 'blink_perf.layout_full_frame'
234 class BlinkPerfMutation(benchmark
.Benchmark
):
236 test
= _BlinkPerfMeasurement
240 return 'blink_perf.mutation'
242 def CreatePageSet(self
, options
):
243 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Mutation')
244 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
247 class BlinkPerfParser(benchmark
.Benchmark
):
249 test
= _BlinkPerfMeasurement
253 return 'blink_perf.parser'
255 def CreatePageSet(self
, options
):
256 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Parser')
257 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
260 class BlinkPerfSVG(benchmark
.Benchmark
):
262 test
= _BlinkPerfMeasurement
266 return 'blink_perf.svg'
268 def CreatePageSet(self
, options
):
269 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'SVG')
270 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
273 @benchmark.Enabled('content-shell')
274 class BlinkPerfSVGFullLayout(BlinkPerfSVG
):
275 tag
= 'svg_full_frame'
276 test
= _BlinkPerfFullFrameMeasurement
280 return 'blink_perf.svg_full_frame'
283 class BlinkPerfShadowDOM(benchmark
.Benchmark
):
285 test
= _BlinkPerfMeasurement
289 return 'blink_perf.shadow_dom'
291 def CreatePageSet(self
, options
):
292 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'ShadowDOM')
293 return CreatePageSetFromPath(path
, SKIPPED_FILE
)
296 # This benchmark is for local testing, doesn't need to run on bots.
297 @benchmark.Disabled()
298 class BlinkPerfXMLHttpRequest(benchmark
.Benchmark
):
299 tag
= 'xml_http_request'
300 test
= _BlinkPerfMeasurement
304 return 'blink_perf.xml_http_request'
306 def CreatePageSet(self
, options
):
307 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'XMLHttpRequest')
308 return CreatePageSetFromPath(path
, SKIPPED_FILE
)