Use null rather than empty frame to lock Surface resources
[chromium-blink-merge.git] / tools / perf / benchmarks / dromaeo.py
blobef5ed0730064943b620f8afcd4bb7fddeaddcf95
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 math
6 import os
8 from telemetry import benchmark
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 scalar
14 from metrics import power
17 class _DromaeoMeasurement(page_test.PageTest):
18 def __init__(self):
19 super(_DromaeoMeasurement, self).__init__()
20 self._power_metric = None
22 def CustomizeBrowserOptions(self, options):
23 power.PowerMetric.CustomizeBrowserOptions(options)
25 def WillStartBrowser(self, platform):
26 self._power_metric = power.PowerMetric(platform)
28 def DidNavigateToPage(self, page, tab):
29 self._power_metric.Start(page, tab)
31 def ValidateAndMeasurePage(self, page, tab, results):
32 tab.WaitForJavaScriptExpression(
33 'window.document.getElementById("pause") &&' +
34 'window.document.getElementById("pause").value == "Run"',
35 120)
37 # Start spying on POST request that will report benchmark results, and
38 # intercept result data.
39 tab.ExecuteJavaScript('(function() {' +
40 ' var real_jquery_ajax_ = window.jQuery;' +
41 ' window.results_ = "";' +
42 ' window.jQuery.ajax = function(request) {' +
43 ' if (request.url == "store.php") {' +
44 ' window.results_ =' +
45 ' decodeURIComponent(request.data);' +
46 ' window.results_ = window.results_.substring(' +
47 ' window.results_.indexOf("=") + 1, ' +
48 ' window.results_.lastIndexOf("&"));' +
49 ' real_jquery_ajax_(request);' +
50 ' }' +
51 ' };' +
52 '})();')
53 # Starts benchmark.
54 tab.ExecuteJavaScript('window.document.getElementById("pause").click();')
56 tab.WaitForJavaScriptExpression('!!window.results_', 600)
58 self._power_metric.Stop(page, tab)
59 self._power_metric.AddResults(tab, results)
61 score = eval(tab.EvaluateJavaScript('window.results_ || "[]"'))
63 def Escape(k):
64 chars = [' ', '.', '-', '/', '(', ')', '*']
65 for c in chars:
66 k = k.replace(c, '_')
67 return k
69 def AggregateData(container, key, value):
70 if key not in container:
71 container[key] = {'count': 0, 'sum': 0}
72 container[key]['count'] += 1
73 container[key]['sum'] += math.log(value)
75 suffix = page.url[page.url.index('?') + 1 :]
76 def AddResult(name, value):
77 important = False
78 if name == suffix:
79 important = True
80 results.AddValue(scalar.ScalarValue(
81 results.current_page, Escape(name), 'runs/s', value, important))
83 aggregated = {}
84 for data in score:
85 AddResult('%s/%s' % (data['collection'], data['name']),
86 data['mean'])
88 top_name = data['collection'].split('-', 1)[0]
89 AggregateData(aggregated, top_name, data['mean'])
91 collection_name = data['collection']
92 AggregateData(aggregated, collection_name, data['mean'])
94 for key, value in aggregated.iteritems():
95 AddResult(key, math.exp(value['sum'] / value['count']))
97 class _DromaeoBenchmark(benchmark.Benchmark):
98 """A base class for Dromaeo benchmarks."""
99 test = _DromaeoMeasurement
101 @classmethod
102 def Name(cls):
103 return 'dromaeo'
105 def CreatePageSet(self, options):
106 """Makes a PageSet for Dromaeo benchmarks."""
107 # Subclasses are expected to define class members called query_param and
108 # tag.
109 if not hasattr(self, 'query_param') or not hasattr(self, 'tag'):
110 raise NotImplementedError('query_param or tag not in Dromaeo benchmark.')
111 archive_data_file = '../page_sets/data/dromaeo.%s.json' % self.tag
112 ps = page_set.PageSet(
113 archive_data_file=archive_data_file,
114 file_path=os.path.abspath(__file__), bucket=page_set.PUBLIC_BUCKET)
115 url = 'http://dromaeo.com?%s' % self.query_param
116 ps.AddUserStory(page_module.Page(
117 url, ps, ps.base_dir, make_javascript_deterministic=False))
118 return ps
121 class DromaeoDomCoreAttr(_DromaeoBenchmark):
122 """Dromaeo DOMCore attr JavaScript benchmark.
124 Tests setting and getting DOM node attributes.
126 tag = 'domcoreattr'
127 query_param = 'dom-attr'
129 @classmethod
130 def Name(cls):
131 return 'dromaeo.domcoreattr'
134 class DromaeoDomCoreModify(_DromaeoBenchmark):
135 """Dromaeo DOMCore modify JavaScript benchmark.
137 Tests creating and injecting DOM nodes.
139 tag = 'domcoremodify'
140 query_param = 'dom-modify'
142 @classmethod
143 def Name(cls):
144 return 'dromaeo.domcoremodify'
147 class DromaeoDomCoreQuery(_DromaeoBenchmark):
148 """Dromaeo DOMCore query JavaScript benchmark.
150 Tests querying DOM elements in a document.
152 tag = 'domcorequery'
153 query_param = 'dom-query'
155 @classmethod
156 def Name(cls):
157 return 'dromaeo.domcorequery'
160 class DromaeoDomCoreTraverse(_DromaeoBenchmark):
161 """Dromaeo DOMCore traverse JavaScript benchmark.
163 Tests traversing a DOM structure.
165 tag = 'domcoretraverse'
166 query_param = 'dom-traverse'
168 @classmethod
169 def Name(cls):
170 return 'dromaeo.domcoretraverse'
173 class DromaeoJslibAttrJquery(_DromaeoBenchmark):
174 """Dromaeo JSLib attr jquery JavaScript benchmark.
176 Tests setting and getting DOM node attributes using the jQuery JavaScript
177 Library.
179 tag = 'jslibattrjquery'
180 query_param = 'jslib-attr-jquery'
182 @classmethod
183 def Name(cls):
184 return 'dromaeo.jslibattrjquery'
187 class DromaeoJslibAttrPrototype(_DromaeoBenchmark):
188 """Dromaeo JSLib attr prototype JavaScript benchmark.
190 Tests setting and getting DOM node attributes using the jQuery JavaScript
191 Library.
193 tag = 'jslibattrprototype'
194 query_param = 'jslib-attr-prototype'
196 @classmethod
197 def Name(cls):
198 return 'dromaeo.jslibattrprototype'
201 class DromaeoJslibEventJquery(_DromaeoBenchmark):
202 """Dromaeo JSLib event jquery JavaScript benchmark.
204 Tests binding, removing, and triggering DOM events using the jQuery JavaScript
205 Library.
207 tag = 'jslibeventjquery'
208 query_param = 'jslib-event-jquery'
210 @classmethod
211 def Name(cls):
212 return 'dromaeo.jslibeventjquery'
215 @benchmark.Disabled('android', 'linux') # http://crbug.com/476592
216 class DromaeoJslibEventPrototype(_DromaeoBenchmark):
217 """Dromaeo JSLib event prototype JavaScript benchmark.
219 Tests binding, removing, and triggering DOM events using the Prototype
220 JavaScript Library.
222 tag = 'jslibeventprototype'
223 query_param = 'jslib-event-prototype'
225 @classmethod
226 def Name(cls):
227 return 'dromaeo.jslibeventprototype'
230 @benchmark.Disabled('xp') # crbug.com/389731
231 class DromaeoJslibModifyJquery(_DromaeoBenchmark):
232 """Dromaeo JSLib modify jquery JavaScript benchmark.
234 Tests creating and injecting DOM nodes into a document using the jQuery
235 JavaScript Library.
237 tag = 'jslibmodifyjquery'
238 query_param = 'jslib-modify-jquery'
240 @classmethod
241 def Name(cls):
242 return 'dromaeo.jslibmodifyjquery'
245 class DromaeoJslibModifyPrototype(_DromaeoBenchmark):
246 """Dromaeo JSLib modify prototype JavaScript benchmark.
248 Tests creating and injecting DOM nodes into a document using the Prototype
249 JavaScript Library.
251 tag = 'jslibmodifyprototype'
252 query_param = 'jslib-modify-prototype'
254 @classmethod
255 def Name(cls):
256 return 'dromaeo.jslibmodifyprototype'
259 class DromaeoJslibStyleJquery(_DromaeoBenchmark):
260 """Dromaeo JSLib style jquery JavaScript benchmark.
262 Tests getting and setting CSS information on DOM elements using the jQuery
263 JavaScript Library.
265 tag = 'jslibstylejquery'
266 query_param = 'jslib-style-jquery'
268 @classmethod
269 def Name(cls):
270 return 'dromaeo.jslibstylejquery'
273 class DromaeoJslibStylePrototype(_DromaeoBenchmark):
274 """Dromaeo JSLib style prototype JavaScript benchmark.
276 Tests getting and setting CSS information on DOM elements using the jQuery
277 JavaScript Library.
279 tag = 'jslibstyleprototype'
280 query_param = 'jslib-style-prototype'
282 @classmethod
283 def Name(cls):
284 return 'dromaeo.jslibstyleprototype'
287 class DromaeoJslibTraverseJquery(_DromaeoBenchmark):
288 """Dromaeo JSLib traverse jquery JavaScript benchmark.
291 Tests getting and setting CSS information on DOM elements using the Prototype
292 JavaScript Library.
294 tag = 'jslibtraversejquery'
295 query_param = 'jslib-traverse-jquery'
297 @classmethod
298 def Name(cls):
299 return 'dromaeo.jslibtraversejquery'
302 class DromaeoJslibTraversePrototype(_DromaeoBenchmark):
303 """Dromaeo JSLib traverse prototype JavaScript benchmark.
305 Tests traversing a DOM structure using the jQuery JavaScript Library.
307 tag = 'jslibtraverseprototype'
308 query_param = 'jslib-traverse-prototype'
310 @classmethod
311 def Name(cls):
312 return 'dromaeo.jslibtraverseprototype'
315 class DromaeoCSSQueryJquery(_DromaeoBenchmark):
316 """Dromaeo CSS Query jquery JavaScript benchmark.
318 Tests traversing a DOM structure using the Prototype JavaScript Library.
320 tag = 'cssqueryjquery'
321 query_param = 'cssquery-jquery'
323 @classmethod
324 def Name(cls):
325 return 'dromaeo.cssqueryjquery'