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.
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_test
13 from telemetry
import story
14 from telemetry
.value
import scalar
16 from metrics
import power
19 class _DromaeoMeasurement(page_test
.PageTest
):
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"',
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);' +
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_ || "[]"'))
66 chars
= [' ', '.', '-', '/', '(', ')', '*']
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
):
82 results
.AddValue(scalar
.ScalarValue(
83 results
.current_page
, Escape(name
), 'runs/s', value
, important
))
87 AddResult('%s/%s' % (data
['collection'], data
['name']),
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
107 def CreateStorySet(self
, options
):
108 """Makes a PageSet for Dromaeo benchmarks."""
109 # Subclasses are expected to define class members called query_param and
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
115 archive_data_file
=archive_data_file
,
116 base_dir
=os
.path
.dirname(os
.path
.abspath(__file__
)),
117 cloud_storage_bucket
=story
.PUBLIC_BUCKET
)
118 url
= 'http://dromaeo.com?%s' % self
.query_param
119 ps
.AddStory(page_module
.Page(
120 url
, ps
, ps
.base_dir
, make_javascript_deterministic
=False))
124 class DromaeoDomCoreAttr(_DromaeoBenchmark
):
125 """Dromaeo DOMCore attr JavaScript benchmark.
127 Tests setting and getting DOM node attributes.
130 query_param
= 'dom-attr'
134 return 'dromaeo.domcoreattr'
137 @benchmark.Disabled('xp') # crbug.com/501625
138 class DromaeoDomCoreModify(_DromaeoBenchmark
):
139 """Dromaeo DOMCore modify JavaScript benchmark.
141 Tests creating and injecting DOM nodes.
143 tag
= 'domcoremodify'
144 query_param
= 'dom-modify'
148 return 'dromaeo.domcoremodify'
151 class DromaeoDomCoreQuery(_DromaeoBenchmark
):
152 """Dromaeo DOMCore query JavaScript benchmark.
154 Tests querying DOM elements in a document.
157 query_param
= 'dom-query'
161 return 'dromaeo.domcorequery'
164 class DromaeoDomCoreTraverse(_DromaeoBenchmark
):
165 """Dromaeo DOMCore traverse JavaScript benchmark.
167 Tests traversing a DOM structure.
169 tag
= 'domcoretraverse'
170 query_param
= 'dom-traverse'
174 return 'dromaeo.domcoretraverse'
177 @benchmark.Disabled('win') # crbug.com/523276
178 class DromaeoJslibAttrJquery(_DromaeoBenchmark
):
179 """Dromaeo JSLib attr jquery JavaScript benchmark.
181 Tests setting and getting DOM node attributes using the jQuery JavaScript
184 tag
= 'jslibattrjquery'
185 query_param
= 'jslib-attr-jquery'
189 return 'dromaeo.jslibattrjquery'
192 class DromaeoJslibAttrPrototype(_DromaeoBenchmark
):
193 """Dromaeo JSLib attr prototype JavaScript benchmark.
195 Tests setting and getting DOM node attributes using the jQuery JavaScript
198 tag
= 'jslibattrprototype'
199 query_param
= 'jslib-attr-prototype'
203 return 'dromaeo.jslibattrprototype'
206 @benchmark.Disabled('win') # crbug.com/523276
207 class DromaeoJslibEventJquery(_DromaeoBenchmark
):
208 """Dromaeo JSLib event jquery JavaScript benchmark.
210 Tests binding, removing, and triggering DOM events using the jQuery JavaScript
213 tag
= 'jslibeventjquery'
214 query_param
= 'jslib-event-jquery'
218 return 'dromaeo.jslibeventjquery'
221 class DromaeoJslibEventPrototype(_DromaeoBenchmark
):
222 """Dromaeo JSLib event prototype JavaScript benchmark.
224 Tests binding, removing, and triggering DOM events using the Prototype
227 tag
= 'jslibeventprototype'
228 query_param
= 'jslib-event-prototype'
232 return 'dromaeo.jslibeventprototype'
235 # xp: crbug.com/389731
236 # win7: http://crbug.com/479796
237 # linux: http://crbug.com/513853
238 # android: http://crbug.com/503138
239 # win8: crbug.com/529330
240 @benchmark.Disabled('xp', 'win7', 'linux', 'android', 'win8')
241 class DromaeoJslibModifyJquery(_DromaeoBenchmark
):
242 """Dromaeo JSLib modify jquery JavaScript benchmark.
244 Tests creating and injecting DOM nodes into a document using the jQuery
247 tag
= 'jslibmodifyjquery'
248 query_param
= 'jslib-modify-jquery'
252 return 'dromaeo.jslibmodifyjquery'
255 class DromaeoJslibModifyPrototype(_DromaeoBenchmark
):
256 """Dromaeo JSLib modify prototype JavaScript benchmark.
258 Tests creating and injecting DOM nodes into a document using the Prototype
261 tag
= 'jslibmodifyprototype'
262 query_param
= 'jslib-modify-prototype'
266 return 'dromaeo.jslibmodifyprototype'
269 class DromaeoJslibStyleJquery(_DromaeoBenchmark
):
270 """Dromaeo JSLib style jquery JavaScript benchmark.
272 Tests getting and setting CSS information on DOM elements using the jQuery
275 tag
= 'jslibstylejquery'
276 query_param
= 'jslib-style-jquery'
280 return 'dromaeo.jslibstylejquery'
283 class DromaeoJslibStylePrototype(_DromaeoBenchmark
):
284 """Dromaeo JSLib style prototype JavaScript benchmark.
286 Tests getting and setting CSS information on DOM elements using the jQuery
289 tag
= 'jslibstyleprototype'
290 query_param
= 'jslib-style-prototype'
294 return 'dromaeo.jslibstyleprototype'
297 class DromaeoJslibTraverseJquery(_DromaeoBenchmark
):
298 """Dromaeo JSLib traverse jquery JavaScript benchmark.
301 Tests getting and setting CSS information on DOM elements using the Prototype
304 tag
= 'jslibtraversejquery'
305 query_param
= 'jslib-traverse-jquery'
309 return 'dromaeo.jslibtraversejquery'
312 class DromaeoJslibTraversePrototype(_DromaeoBenchmark
):
313 """Dromaeo JSLib traverse prototype JavaScript benchmark.
315 Tests traversing a DOM structure using the jQuery JavaScript Library.
317 tag
= 'jslibtraverseprototype'
318 query_param
= 'jslib-traverse-prototype'
322 return 'dromaeo.jslibtraverseprototype'
325 class DromaeoCSSQueryJquery(_DromaeoBenchmark
):
326 """Dromaeo CSS Query jquery JavaScript benchmark.
328 Tests traversing a DOM structure using the Prototype JavaScript Library.
330 tag
= 'cssqueryjquery'
331 query_param
= 'cssquery-jquery'
335 return 'dromaeo.cssqueryjquery'