Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / tools / perf / benchmarks / blink_perf.py
blob20d3a025ebceeb4bfbb020b69684339d4fe674d4
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.
5 import os
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)
22 page_urls = []
23 serving_dirs = set()
25 def _AddPage(path):
26 if not path.endswith('.html'):
27 return
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':
36 continue
37 candidate_path = os.path.join(dir_path, candidate_path)
38 if candidate_path.startswith(skipped):
39 continue
40 if os.path.isdir(candidate_path):
41 _AddDir(candidate_path, skipped)
42 else:
43 _AddPage(candidate_path)
45 if os.path.isdir(path):
46 skipped = []
47 if os.path.exists(skipped_file):
48 for line in open(skipped_file, 'r').readlines():
49 line = line.strip()
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))
54 else:
55 _AddPage(path)
56 ps = page_set.PageSet(file_path=os.getcwd()+os.sep, serving_dirs=serving_dirs)
57 for url in page_urls:
58 ps.AddPageWithDefaultRunNavigate(url)
59 return ps
62 class _BlinkPerfMeasurement(page_test.PageTest):
63 """Tuns a blink performance test and reports the results."""
64 def __init__(self):
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 '):
87 continue
88 parts = line.split()
89 values = [float(v.replace(',', '')) for v in parts[1:-1]]
90 units = parts[-1]
91 metric = page.display_name.split('.')[0].replace('/', '_')
92 results.AddValue(list_of_scalar_values.ListOfScalarValues(
93 results.current_page, metric, units, values))
95 break
97 print log
100 class BlinkPerfAnimation(benchmark.Benchmark):
101 tag = 'animation'
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):
110 tag = 'bindings'
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):
119 tag = 'css'
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):
128 tag = 'canvas'
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):
137 tag = 'dom'
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):
146 tag = 'events'
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):
155 tag = 'interactive'
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):
164 tag = 'layout'
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):
173 tag = 'mutation'
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):
182 tag = 'parser'
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):
191 tag = 'svg'
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):
200 tag = 'shadow_dom'
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)