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 core
import perf_benchmark
9 from telemetry
import benchmark
10 from telemetry
.core
import util
11 from telemetry
import page
as page_module
12 from telemetry
.page
import page_test
13 from telemetry
.page
import shared_page_state
14 from telemetry
import story
15 from telemetry
.value
import list_of_scalar_values
17 from page_sets
import webgl_supported_shared_state
20 BLINK_PERF_BASE_DIR
= os
.path
.join(util
.GetChromiumSrcDir(),
21 'third_party', 'WebKit', 'PerformanceTests')
22 SKIPPED_FILE
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Skipped')
25 def CreateStorySetFromPath(path
, skipped_file
,
26 shared_page_state_class
=(
27 shared_page_state
.SharedPageState
)):
28 assert os
.path
.exists(path
)
34 if not path
.endswith('.html'):
36 if '../' in open(path
, 'r').read():
37 # If the page looks like it references its parent dir, include it.
38 serving_dirs
.add(os
.path
.dirname(os
.path
.dirname(path
)))
39 page_urls
.append('file://' + path
.replace('\\', '/'))
41 def _AddDir(dir_path
, skipped
):
42 for candidate_path
in os
.listdir(dir_path
):
43 if candidate_path
== 'resources':
45 candidate_path
= os
.path
.join(dir_path
, candidate_path
)
46 if candidate_path
.startswith(skipped
):
48 if os
.path
.isdir(candidate_path
):
49 _AddDir(candidate_path
, skipped
)
51 _AddPage(candidate_path
)
53 if os
.path
.isdir(path
):
55 if os
.path
.exists(skipped_file
):
56 for line
in open(skipped_file
, 'r').readlines():
58 if line
and not line
.startswith('#'):
59 skipped_path
= os
.path
.join(os
.path
.dirname(skipped_file
), line
)
60 skipped
.append(skipped_path
.replace('/', os
.sep
))
61 _AddDir(path
, tuple(skipped
))
64 ps
= story
.StorySet(base_dir
=os
.getcwd()+os
.sep
,
65 serving_dirs
=serving_dirs
)
67 ps
.AddStory(page_module
.Page(
69 shared_page_state_class
=shared_page_state_class
))
73 class _BlinkPerfMeasurement(page_test
.PageTest
):
74 """Tuns a blink performance test and reports the results."""
76 super(_BlinkPerfMeasurement
, self
).__init
__()
77 with
open(os
.path
.join(os
.path
.dirname(__file__
),
78 'blink_perf.js'), 'r') as f
:
79 self
._blink
_perf
_js
= f
.read()
81 def WillNavigateToPage(self
, page
, tab
):
82 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
84 def CustomizeBrowserOptions(self
, options
):
85 options
.AppendExtraBrowserArgs([
86 '--js-flags=--expose_gc',
87 '--enable-experimental-web-platform-features',
88 '--disable-gesture-requirement-for-media-playback'
90 if 'content-shell' in options
.browser_type
:
91 options
.AppendExtraBrowserArgs('--expose-internals-for-testing')
93 def ValidateAndMeasurePage(self
, page
, tab
, results
):
94 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
96 log
= tab
.EvaluateJavaScript('document.getElementById("log").innerHTML')
98 for line
in log
.splitlines():
99 if not line
.startswith('values '):
102 values
= [float(v
.replace(',', '')) for v
in parts
[1:-1]]
104 metric
= page
.display_name
.split('.')[0].replace('/', '_')
105 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
106 results
.current_page
, metric
, units
, values
))
113 class _BlinkPerfFullFrameMeasurement(_BlinkPerfMeasurement
):
115 super(_BlinkPerfFullFrameMeasurement
, self
).__init
__()
116 self
._blink
_perf
_js
+= '\nwindow.fullFrameMeasurement = true;'
118 def CustomizeBrowserOptions(self
, options
):
119 super(_BlinkPerfFullFrameMeasurement
, self
).CustomizeBrowserOptions(
121 # Full layout measurement needs content_shell with internals testing API.
122 assert 'content-shell' in options
.browser_type
123 options
.AppendExtraBrowserArgs(['--expose-internals-for-testing'])
125 @benchmark.Disabled
# http://crbug.com/500958
126 class BlinkPerfBindings(perf_benchmark
.PerfBenchmark
):
128 test
= _BlinkPerfMeasurement
132 return 'blink_perf.bindings'
134 def CreateStorySet(self
, options
):
135 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Bindings')
136 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
139 @benchmark.Enabled('content-shell')
140 class BlinkPerfBlinkGC(perf_benchmark
.PerfBenchmark
):
142 test
= _BlinkPerfMeasurement
146 return 'blink_perf.blink_gc'
148 def CreateStorySet(self
, options
):
149 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'BlinkGC')
150 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
153 class BlinkPerfCSS(perf_benchmark
.PerfBenchmark
):
155 test
= _BlinkPerfMeasurement
159 return 'blink_perf.css'
161 def CreateStorySet(self
, options
):
162 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'CSS')
163 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
166 @benchmark.Disabled('xp', # http://crbug.com/488059
167 'android') # http://crbug.com/496707
168 class BlinkPerfCanvas(perf_benchmark
.PerfBenchmark
):
170 test
= _BlinkPerfMeasurement
174 return 'blink_perf.canvas'
176 def CreateStorySet(self
, options
):
177 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Canvas')
178 story_set
= CreateStorySetFromPath(
180 shared_page_state_class
=(
181 webgl_supported_shared_state
.WebGLSupportedSharedState
))
182 # WebGLSupportedSharedState requires the skipped_gpus property to
183 # be set on each page.
184 for page
in story_set
:
185 page
.skipped_gpus
= []
189 class BlinkPerfDOM(perf_benchmark
.PerfBenchmark
):
191 test
= _BlinkPerfMeasurement
195 return 'blink_perf.dom'
197 def CreateStorySet(self
, options
):
198 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'DOM')
199 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
202 @benchmark.Disabled('release_x64') # http://crbug.com/480999
203 class BlinkPerfEvents(perf_benchmark
.PerfBenchmark
):
205 test
= _BlinkPerfMeasurement
209 return 'blink_perf.events'
211 def CreateStorySet(self
, options
):
212 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Events')
213 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
216 @benchmark.Disabled('win8') # http://crbug.com/462350
217 class BlinkPerfLayout(perf_benchmark
.PerfBenchmark
):
219 test
= _BlinkPerfMeasurement
223 return 'blink_perf.layout'
225 def CreateStorySet(self
, options
):
226 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Layout')
227 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
230 @benchmark.Enabled('content-shell')
231 class BlinkPerfLayoutFullLayout(BlinkPerfLayout
):
232 tag
= 'layout_full_frame'
233 test
= _BlinkPerfFullFrameMeasurement
237 return 'blink_perf.layout_full_frame'
240 class BlinkPerfMutation(perf_benchmark
.PerfBenchmark
):
242 test
= _BlinkPerfMeasurement
246 return 'blink_perf.mutation'
248 def CreateStorySet(self
, options
):
249 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Mutation')
250 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
253 @benchmark.Disabled('win') # crbug.com/488493
254 class BlinkPerfParser(perf_benchmark
.PerfBenchmark
):
256 test
= _BlinkPerfMeasurement
260 return 'blink_perf.parser'
262 def CreateStorySet(self
, options
):
263 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Parser')
264 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
267 class BlinkPerfSVG(perf_benchmark
.PerfBenchmark
):
269 test
= _BlinkPerfMeasurement
273 return 'blink_perf.svg'
275 def CreateStorySet(self
, options
):
276 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'SVG')
277 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
280 @benchmark.Enabled('content-shell')
281 class BlinkPerfSVGFullLayout(BlinkPerfSVG
):
282 tag
= 'svg_full_frame'
283 test
= _BlinkPerfFullFrameMeasurement
287 return 'blink_perf.svg_full_frame'
290 class BlinkPerfShadowDOM(perf_benchmark
.PerfBenchmark
):
292 test
= _BlinkPerfMeasurement
296 return 'blink_perf.shadow_dom'
298 def CreateStorySet(self
, options
):
299 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'ShadowDOM')
300 return CreateStorySetFromPath(path
, SKIPPED_FILE
)
303 # This benchmark is for local testing, doesn't need to run on bots.
304 @benchmark.Disabled()
305 class BlinkPerfXMLHttpRequest(perf_benchmark
.PerfBenchmark
):
306 tag
= 'xml_http_request'
307 test
= _BlinkPerfMeasurement
311 return 'blink_perf.xml_http_request'
313 def CreateStorySet(self
, options
):
314 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'XMLHttpRequest')
315 return CreateStorySetFromPath(path
, SKIPPED_FILE
)