Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / tools / perf / benchmarks / dromaeo.py
blobd3dd3cad618afa7aff0f1e010cfd576c6c486b44
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 core import perf_benchmark
10 from telemetry import benchmark
11 from telemetry import page as page_module
12 from telemetry.page import page_set
13 from telemetry.page import page_test
14 from telemetry.value import scalar
16 from metrics import power
19 class _DromaeoMeasurement(page_test.PageTest):
20 def __init__(self):
21 super(_DromaeoMeasurement, self).__init__()
22 self._power_metric = None
24 def CustomizeBrowserOptions(self, options):
25 power.PowerMetric.CustomizeBrowserOptions(options)
27 def WillStartBrowser(self, platform):
28 self._power_metric = power.PowerMetric(platform)
30 def DidNavigateToPage(self, page, tab):
31 self._power_metric.Start(page, tab)
33 def ValidateAndMeasurePage(self, page, tab, results):
34 tab.WaitForJavaScriptExpression(
35 'window.document.getElementById("pause") &&' +
36 'window.document.getElementById("pause").value == "Run"',
37 120)
39 # Start spying on POST request that will report benchmark results, and
40 # intercept result data.
41 tab.ExecuteJavaScript('(function() {' +
42 ' var real_jquery_ajax_ = window.jQuery;' +
43 ' window.results_ = "";' +
44 ' window.jQuery.ajax = function(request) {' +
45 ' if (request.url == "store.php") {' +
46 ' window.results_ =' +
47 ' decodeURIComponent(request.data);' +
48 ' window.results_ = window.results_.substring(' +
49 ' window.results_.indexOf("=") + 1, ' +
50 ' window.results_.lastIndexOf("&"));' +
51 ' real_jquery_ajax_(request);' +
52 ' }' +
53 ' };' +
54 '})();')
55 # Starts benchmark.
56 tab.ExecuteJavaScript('window.document.getElementById("pause").click();')
58 tab.WaitForJavaScriptExpression('!!window.results_', 600)
60 self._power_metric.Stop(page, tab)
61 self._power_metric.AddResults(tab, results)
63 score = eval(tab.EvaluateJavaScript('window.results_ || "[]"'))
65 def Escape(k):
66 chars = [' ', '.', '-', '/', '(', ')', '*']
67 for c in chars:
68 k = k.replace(c, '_')
69 return k
71 def AggregateData(container, key, value):
72 if key not in container:
73 container[key] = {'count': 0, 'sum': 0}
74 container[key]['count'] += 1
75 container[key]['sum'] += math.log(value)
77 suffix = page.url[page.url.index('?') + 1 :]
78 def AddResult(name, value):
79 important = False
80 if name == suffix:
81 important = True
82 results.AddValue(scalar.ScalarValue(
83 results.current_page, Escape(name), 'runs/s', value, important))
85 aggregated = {}
86 for data in score:
87 AddResult('%s/%s' % (data['collection'], data['name']),
88 data['mean'])
90 top_name = data['collection'].split('-', 1)[0]
91 AggregateData(aggregated, top_name, data['mean'])
93 collection_name = data['collection']
94 AggregateData(aggregated, collection_name, data['mean'])
96 for key, value in aggregated.iteritems():
97 AddResult(key, math.exp(value['sum'] / value['count']))
99 class _DromaeoBenchmark(perf_benchmark.PerfBenchmark):
100 """A base class for Dromaeo benchmarks."""
101 test = _DromaeoMeasurement
103 @classmethod
104 def Name(cls):
105 return 'dromaeo'
107 def CreatePageSet(self, options):
108 """Makes a PageSet for Dromaeo benchmarks."""
109 # Subclasses are expected to define class members called query_param and
110 # tag.
111 if not hasattr(self, 'query_param') or not hasattr(self, 'tag'):
112 raise NotImplementedError('query_param or tag not in Dromaeo benchmark.')
113 archive_data_file = '../page_sets/data/dromaeo.%s.json' % self.tag
114 ps = page_set.PageSet(
115 archive_data_file=archive_data_file,
116 file_path=os.path.abspath(__file__), bucket=page_set.PUBLIC_BUCKET)
117 url = 'http://dromaeo.com?%s' % self.query_param
118 ps.AddUserStory(page_module.Page(
119 url, ps, ps.base_dir, make_javascript_deterministic=False))
120 return ps
123 class DromaeoDomCoreAttr(_DromaeoBenchmark):
124 """Dromaeo DOMCore attr JavaScript benchmark.
126 Tests setting and getting DOM node attributes.
128 tag = 'domcoreattr'
129 query_param = 'dom-attr'
131 @classmethod
132 def Name(cls):
133 return 'dromaeo.domcoreattr'
136 class DromaeoDomCoreModify(_DromaeoBenchmark):
137 """Dromaeo DOMCore modify JavaScript benchmark.
139 Tests creating and injecting DOM nodes.
141 tag = 'domcoremodify'
142 query_param = 'dom-modify'
144 @classmethod
145 def Name(cls):
146 return 'dromaeo.domcoremodify'
149 class DromaeoDomCoreQuery(_DromaeoBenchmark):
150 """Dromaeo DOMCore query JavaScript benchmark.
152 Tests querying DOM elements in a document.
154 tag = 'domcorequery'
155 query_param = 'dom-query'
157 @classmethod
158 def Name(cls):
159 return 'dromaeo.domcorequery'
162 class DromaeoDomCoreTraverse(_DromaeoBenchmark):
163 """Dromaeo DOMCore traverse JavaScript benchmark.
165 Tests traversing a DOM structure.
167 tag = 'domcoretraverse'
168 query_param = 'dom-traverse'
170 @classmethod
171 def Name(cls):
172 return 'dromaeo.domcoretraverse'
175 class DromaeoJslibAttrJquery(_DromaeoBenchmark):
176 """Dromaeo JSLib attr jquery JavaScript benchmark.
178 Tests setting and getting DOM node attributes using the jQuery JavaScript
179 Library.
181 tag = 'jslibattrjquery'
182 query_param = 'jslib-attr-jquery'
184 @classmethod
185 def Name(cls):
186 return 'dromaeo.jslibattrjquery'
189 class DromaeoJslibAttrPrototype(_DromaeoBenchmark):
190 """Dromaeo JSLib attr prototype JavaScript benchmark.
192 Tests setting and getting DOM node attributes using the jQuery JavaScript
193 Library.
195 tag = 'jslibattrprototype'
196 query_param = 'jslib-attr-prototype'
198 @classmethod
199 def Name(cls):
200 return 'dromaeo.jslibattrprototype'
203 class DromaeoJslibEventJquery(_DromaeoBenchmark):
204 """Dromaeo JSLib event jquery JavaScript benchmark.
206 Tests binding, removing, and triggering DOM events using the jQuery JavaScript
207 Library.
209 tag = 'jslibeventjquery'
210 query_param = 'jslib-event-jquery'
212 @classmethod
213 def Name(cls):
214 return 'dromaeo.jslibeventjquery'
217 class DromaeoJslibEventPrototype(_DromaeoBenchmark):
218 """Dromaeo JSLib event prototype JavaScript benchmark.
220 Tests binding, removing, and triggering DOM events using the Prototype
221 JavaScript Library.
223 tag = 'jslibeventprototype'
224 query_param = 'jslib-event-prototype'
226 @classmethod
227 def Name(cls):
228 return 'dromaeo.jslibeventprototype'
231 # xp: crbug.com/389731
232 # win7: http://crbug.com/479796
233 @benchmark.Disabled('xp', 'win7')
234 class DromaeoJslibModifyJquery(_DromaeoBenchmark):
235 """Dromaeo JSLib modify jquery JavaScript benchmark.
237 Tests creating and injecting DOM nodes into a document using the jQuery
238 JavaScript Library.
240 tag = 'jslibmodifyjquery'
241 query_param = 'jslib-modify-jquery'
243 @classmethod
244 def Name(cls):
245 return 'dromaeo.jslibmodifyjquery'
248 class DromaeoJslibModifyPrototype(_DromaeoBenchmark):
249 """Dromaeo JSLib modify prototype JavaScript benchmark.
251 Tests creating and injecting DOM nodes into a document using the Prototype
252 JavaScript Library.
254 tag = 'jslibmodifyprototype'
255 query_param = 'jslib-modify-prototype'
257 @classmethod
258 def Name(cls):
259 return 'dromaeo.jslibmodifyprototype'
262 class DromaeoJslibStyleJquery(_DromaeoBenchmark):
263 """Dromaeo JSLib style jquery JavaScript benchmark.
265 Tests getting and setting CSS information on DOM elements using the jQuery
266 JavaScript Library.
268 tag = 'jslibstylejquery'
269 query_param = 'jslib-style-jquery'
271 @classmethod
272 def Name(cls):
273 return 'dromaeo.jslibstylejquery'
276 class DromaeoJslibStylePrototype(_DromaeoBenchmark):
277 """Dromaeo JSLib style prototype JavaScript benchmark.
279 Tests getting and setting CSS information on DOM elements using the jQuery
280 JavaScript Library.
282 tag = 'jslibstyleprototype'
283 query_param = 'jslib-style-prototype'
285 @classmethod
286 def Name(cls):
287 return 'dromaeo.jslibstyleprototype'
290 class DromaeoJslibTraverseJquery(_DromaeoBenchmark):
291 """Dromaeo JSLib traverse jquery JavaScript benchmark.
294 Tests getting and setting CSS information on DOM elements using the Prototype
295 JavaScript Library.
297 tag = 'jslibtraversejquery'
298 query_param = 'jslib-traverse-jquery'
300 @classmethod
301 def Name(cls):
302 return 'dromaeo.jslibtraversejquery'
305 class DromaeoJslibTraversePrototype(_DromaeoBenchmark):
306 """Dromaeo JSLib traverse prototype JavaScript benchmark.
308 Tests traversing a DOM structure using the jQuery JavaScript Library.
310 tag = 'jslibtraverseprototype'
311 query_param = 'jslib-traverse-prototype'
313 @classmethod
314 def Name(cls):
315 return 'dromaeo.jslibtraverseprototype'
318 class DromaeoCSSQueryJquery(_DromaeoBenchmark):
319 """Dromaeo CSS Query jquery JavaScript benchmark.
321 Tests traversing a DOM structure using the Prototype JavaScript Library.
323 tag = 'cssqueryjquery'
324 query_param = 'cssquery-jquery'
326 @classmethod
327 def Name(cls):
328 return 'dromaeo.cssqueryjquery'