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
.page
import page_set
10 from telemetry
.page
import page_test
11 from telemetry
.value
import list_of_scalar_values
14 BLINK_PERF_BASE_DIR
= os
.path
.join(util
.GetChromiumSrcDir(),
15 'third_party', 'WebKit', 'PerformanceTests')
16 SKIPPED_FILE
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Skipped')
19 def _CreatePageSetFromPath(path
, skipped_file
):
20 assert os
.path
.exists(path
)
26 if not path
.endswith('.html'):
28 if '../' in open(path
, 'r').read():
29 # If the page looks like it references its parent dir, include it.
30 serving_dirs
.add(os
.path
.dirname(os
.path
.dirname(path
)))
31 page_urls
.append('file://' + path
.replace('\\', '/'))
33 def _AddDir(dir_path
, skipped
):
34 for candidate_path
in os
.listdir(dir_path
):
35 if candidate_path
== 'resources':
37 candidate_path
= os
.path
.join(dir_path
, candidate_path
)
38 if candidate_path
.startswith(skipped
):
40 if os
.path
.isdir(candidate_path
):
41 _AddDir(candidate_path
, skipped
)
43 _AddPage(candidate_path
)
45 if os
.path
.isdir(path
):
47 if os
.path
.exists(skipped_file
):
48 for line
in open(skipped_file
, 'r').readlines():
50 if line
and not line
.startswith('#'):
51 skipped_path
= os
.path
.join(os
.path
.dirname(skipped_file
), line
)
52 skipped
.append(skipped_path
.replace('/', os
.sep
))
53 _AddDir(path
, tuple(skipped
))
56 ps
= page_set
.PageSet(file_path
=os
.getcwd()+os
.sep
, serving_dirs
=serving_dirs
)
58 ps
.AddPageWithDefaultRunNavigate(url
)
62 class _BlinkPerfMeasurement(page_test
.PageTest
):
63 """Tuns a blink performance test and reports the results."""
65 super(_BlinkPerfMeasurement
, self
).__init
__('')
66 with
open(os
.path
.join(os
.path
.dirname(__file__
),
67 'blink_perf.js'), 'r') as f
:
68 self
._blink
_perf
_js
= f
.read()
70 def WillNavigateToPage(self
, page
, tab
):
71 page
.script_to_evaluate_on_commit
= self
._blink
_perf
_js
73 def CustomizeBrowserOptions(self
, options
):
74 options
.AppendExtraBrowserArgs([
75 '--js-flags=--expose_gc',
76 '--enable-experimental-web-platform-features',
77 '--disable-gesture-requirement-for-media-playback'
80 def ValidateAndMeasurePage(self
, page
, tab
, results
):
81 tab
.WaitForJavaScriptExpression('testRunner.isDone', 600)
83 log
= tab
.EvaluateJavaScript('document.getElementById("log").innerHTML')
85 for line
in log
.splitlines():
86 if not line
.startswith('values '):
89 values
= [float(v
.replace(',', '')) for v
in parts
[1:-1]]
91 metric
= page
.display_name
.split('.')[0].replace('/', '_')
92 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
93 results
.current_page
, metric
, units
, values
))
100 class BlinkPerfAnimation(benchmark
.Benchmark
):
102 test
= _BlinkPerfMeasurement
104 def CreatePageSet(self
, options
):
105 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Animation')
106 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
109 class BlinkPerfBindings(benchmark
.Benchmark
):
111 test
= _BlinkPerfMeasurement
113 def CreatePageSet(self
, options
):
114 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Bindings')
115 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
118 class BlinkPerfCSS(benchmark
.Benchmark
):
120 test
= _BlinkPerfMeasurement
122 def CreatePageSet(self
, options
):
123 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'CSS')
124 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
127 class BlinkPerfCanvas(benchmark
.Benchmark
):
129 test
= _BlinkPerfMeasurement
131 def CreatePageSet(self
, options
):
132 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Canvas')
133 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
136 class BlinkPerfDOM(benchmark
.Benchmark
):
138 test
= _BlinkPerfMeasurement
140 def CreatePageSet(self
, options
):
141 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'DOM')
142 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
145 class BlinkPerfEvents(benchmark
.Benchmark
):
147 test
= _BlinkPerfMeasurement
149 def CreatePageSet(self
, options
):
150 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Events')
151 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
154 class BlinkPerfInteractive(benchmark
.Benchmark
):
156 test
= _BlinkPerfMeasurement
158 def CreatePageSet(self
, options
):
159 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Interactive')
160 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
163 class BlinkPerfLayout(benchmark
.Benchmark
):
165 test
= _BlinkPerfMeasurement
167 def CreatePageSet(self
, options
):
168 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Layout')
169 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
172 class BlinkPerfMutation(benchmark
.Benchmark
):
174 test
= _BlinkPerfMeasurement
176 def CreatePageSet(self
, options
):
177 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Mutation')
178 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
181 class BlinkPerfParser(benchmark
.Benchmark
):
183 test
= _BlinkPerfMeasurement
185 def CreatePageSet(self
, options
):
186 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'Parser')
187 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
190 class BlinkPerfSVG(benchmark
.Benchmark
):
192 test
= _BlinkPerfMeasurement
194 def CreatePageSet(self
, options
):
195 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'SVG')
196 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
199 class BlinkPerfShadowDOM(benchmark
.Benchmark
):
201 test
= _BlinkPerfMeasurement
203 def CreatePageSet(self
, options
):
204 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'ShadowDOM')
205 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)
208 class BlinkPerfXMLHttpRequest(benchmark
.Benchmark
):
209 tag
= 'xml_http_request'
210 test
= _BlinkPerfMeasurement
212 def CreatePageSet(self
, options
):
213 path
= os
.path
.join(BLINK_PERF_BASE_DIR
, 'XMLHttpRequest')
214 return _CreatePageSetFromPath(path
, SKIPPED_FILE
)