[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / benchmarks / kraken.py
blob724dcf87402421a3f43df1ff21a74a03dc6a4dcc
1 # Copyright 2012 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 """Runs Mozilla's Kraken JavaScript benchmark."""
7 import os
9 from telemetry import benchmark
10 from telemetry import page as page_module
11 from telemetry.page import page_set
12 from telemetry.page import page_test
13 from telemetry.value import list_of_scalar_values
14 from telemetry.value import scalar
16 from metrics import power
19 DESCRIPTIONS = {
20 'ai-astar':
21 'This benchmark uses the [A* search algorithm]'
22 '(http://en.wikipedia.org/wiki/A*_search_algorithm) to automatically '
23 'plot an efficient path between two points, in the presence of '
24 'obstacles. Adapted from code by [Brian Gringstead]'
25 '(http://www.briangrinstead.com/blog/astar-search-algorithm-in-'
26 'javascript).',
27 'audio-beat-detection':
28 'This benchmark performs [beat detection]'
29 '(http://en.wikipedia.org/wiki/Beat_detection) on an Audio sample '
30 'using [code](http://beatdetektor.svn.sourceforge.net/viewvc'
31 '/beatdetektor/trunk/core/js/beatdetektor.js?revision=18&view=markup) '
32 'from [BeatDetektor](http://www.cubicproductions.com/index.php'
33 '?option=com_content&view=article&id=67&Itemid=82) and '
34 '[DSP.js](http://github.com/corbanbrook/dsp.js/).',
35 'audio-dft':
36 'This benchmark performs a [Discrete Fourier Transform]'
37 '(http://en.wikipedia.org/wiki/Discrete_Fourier_transform) on an '
38 'Audio sample using code from [DSP.js]'
39 '(http://github.com/corbanbrook/dsp.js).',
40 'audio-fft':
41 'This benchmark performs a [Fast Fourier Transform]'
42 '(http://en.wikipedia.org/wiki/Fast_Fourier_transform) on an Audio '
43 'sample using code from [DSP.js]'
44 '(http://github.com/corbanbrook/dsp.js/).',
45 'audio-oscillator':
46 'This benchmark generates a soundwave using code from [DSP.js]'
47 '(http://github.com/corbanbrook/dsp.js/).',
48 'imaging-darkroom':
49 'This benchmark performs a variety of photo manipulations such as '
50 'Fill, Brightness, Contrast, Saturation, and Temperature.',
51 'imaging-desaturate':
52 'This benchmark [desaturates]'
53 '(http://en.wikipedia.org/wiki/Colorfulness) a photo using code from '
54 '[Pixastic](http://www.pixastic.com/).',
55 'imaging-gaussian-blur':
56 'This benchmark performs a [Gaussian blur]'
57 '(http://en.wikipedia.org/wiki/Gaussian_blur) on a photo.',
58 'json-parse-financial':
59 'This benchmark parses [JSON](http://www.json.org) records.',
60 'json-stringify-tinderbox':
61 'This benchmark serializes [Tinderbox]'
62 '(http://tests.themasta.com/tinderboxpushlog/?tree=Firefox) build '
63 'data to [JSON](http://www.json.org).',
67 def _Mean(l):
68 return float(sum(l)) / len(l) if len(l) > 0 else 0.0
71 class _KrakenMeasurement(page_test.PageTest):
72 def __init__(self):
73 super(_KrakenMeasurement, self).__init__()
74 self._power_metric = None
76 def CustomizeBrowserOptions(self, options):
77 power.PowerMetric.CustomizeBrowserOptions(options)
79 def WillStartBrowser(self, platform):
80 self._power_metric = power.PowerMetric(platform)
82 def DidNavigateToPage(self, page, tab):
83 self._power_metric.Start(page, tab)
85 def ValidateAndMeasurePage(self, page, tab, results):
86 tab.WaitForJavaScriptExpression(
87 'document.title.indexOf("Results") != -1', 700)
88 tab.WaitForDocumentReadyStateToBeComplete()
90 self._power_metric.Stop(page, tab)
91 self._power_metric.AddResults(tab, results)
93 js_get_results = """
94 var formElement = document.getElementsByTagName("input")[0];
95 decodeURIComponent(formElement.value.split("?")[1]);
96 """
97 result_dict = eval(tab.EvaluateJavaScript(js_get_results))
98 total = 0
99 for key in result_dict:
100 if key == 'v':
101 continue
102 results.AddValue(list_of_scalar_values.ListOfScalarValues(
103 results.current_page, key, 'ms', result_dict[key], important=False,
104 description=DESCRIPTIONS.get(key)))
105 total += _Mean(result_dict[key])
107 # TODO(tonyg/nednguyen): This measurement shouldn't calculate Total. The
108 # results system should do that for us.
109 results.AddValue(scalar.ScalarValue(
110 results.current_page, 'Total', 'ms', total,
111 description='Total of the means of the results for each type '
112 'of benchmark in [Mozilla\'s Kraken JavaScript benchmark]'
113 '(http://krakenbenchmark.mozilla.org/)'))
116 class Kraken(benchmark.Benchmark):
117 """Mozilla's Kraken JavaScript benchmark.
119 http://krakenbenchmark.mozilla.org/
121 test = _KrakenMeasurement
123 @classmethod
124 def Name(cls):
125 return 'kraken'
127 def CreatePageSet(self, options):
128 ps = page_set.PageSet(
129 archive_data_file='../page_sets/data/kraken.json',
130 file_path=os.path.abspath(__file__),
131 bucket=page_set.PARTNER_BUCKET)
132 ps.AddUserStory(page_module.Page(
133 'http://krakenbenchmark.mozilla.org/kraken-1.1/driver.html',
134 ps, ps.base_dir))
135 return ps