Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / perf / benchmarks / octane.py
1 # Copyright (c) 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.
4
5 """Runs Octane 2.0 javascript benchmark.
6
7 Octane 2.0 is a modern benchmark that measures a JavaScript engine's performance
8 by running a suite of tests representative of today's complex and demanding web
9 applications. Octane's goal is to measure the performance of JavaScript code
10 found in large, real-world web applications.
11 Octane 2.0 consists of 17 tests, four more than Octane v1.
12 """
13
14 import os
15
16 from metrics import power
17 from metrics import statistics
18 from telemetry import test
19 from telemetry.page import page_measurement
20 from telemetry.page import page_set
21
22 _GB = 1024 * 1024 * 1024
23
24 class _OctaneMeasurement(page_measurement.PageMeasurement):
25   def __init__(self):
26     super(_OctaneMeasurement, self).__init__()
27     self._power_metric = power.PowerMetric()
28
29   def CustomizeBrowserOptions(self, options):
30     power.PowerMetric.CustomizeBrowserOptions(options)
31
32
33   def WillNavigateToPage(self, page, tab):
34     if tab.browser.memory_stats['SystemTotalPhysicalMemory'] < 1 * _GB:
35       skipBenchmarks = '"zlib"'
36     else:
37       skipBenchmarks = ''
38     page.script_to_evaluate_on_commit = """
39         var __results = [];
40         var __real_log = window.console.log;
41         window.console.log = function(msg) {
42           __results.push(msg);
43           __real_log.apply(this, [msg]);
44         }
45         skipBenchmarks = [%s]
46         """ % (skipBenchmarks)
47
48   def DidNavigateToPage(self, page, tab):
49     self._power_metric.Start(page, tab)
50
51   def MeasurePage(self, page, tab, results):
52     tab.WaitForJavaScriptExpression(
53         'completed && !document.getElementById("progress-bar-container")', 1200)
54
55     self._power_metric.Stop(page, tab)
56     self._power_metric.AddResults(tab, results)
57
58     results_log = tab.EvaluateJavaScript('__results')
59     all_scores = []
60     for output in results_log:
61       # Split the results into score and test name.
62       # results log e.g., "Richards: 18343"
63       score_and_name = output.split(': ', 2)
64       assert len(score_and_name) == 2, \
65         'Unexpected result format "%s"' % score_and_name
66       if 'Skipped' not in score_and_name[1]:
67         name = score_and_name[0]
68         score = int(score_and_name[1])
69         results.Add(name, 'score', score, data_type='unimportant')
70         # Collect all test scores to compute geometric mean.
71         all_scores.append(score)
72     total = statistics.GeometricMean(all_scores)
73     results.AddSummary('Score', 'score', total, chart_name='Total')
74
75
76 class Octane(test.Test):
77   """Google's Octane JavaScript benchmark."""
78   test = _OctaneMeasurement
79
80   def CreatePageSet(self, options):
81     return page_set.PageSet.FromDict({
82       'archive_data_file': '../page_sets/data/octane.json',
83       'make_javascript_deterministic': False,
84       'pages': [{
85           'url':
86           'http://octane-benchmark.googlecode.com/svn/latest/index.html?auto=1'
87           }
88         ]
89       }, os.path.abspath(__file__))
90