| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import collections | 5 import collections |
| 6 import json | 6 import json |
| 7 | 7 |
| 8 from telemetry import multi_page_benchmark | 8 from telemetry.core import util |
| 9 from telemetry import util | 9 from telemetry.page import multi_page_benchmark |
| 10 | 10 |
| 11 | 11 |
| 12 class SunSpiderBenchark(multi_page_benchmark.MultiPageBenchmark): | 12 class SunSpiderBenchark(multi_page_benchmark.MultiPageBenchmark): |
| 13 def MeasurePage(self, _, tab, results): | 13 def MeasurePage(self, _, tab, results): |
| 14 js_is_done = """ | 14 js_is_done = """ |
| 15 window.location.pathname.indexOf('sunspider-results') >= 0""" | 15 window.location.pathname.indexOf('sunspider-results') >= 0""" |
| 16 def _IsDone(): | 16 def _IsDone(): |
| 17 return tab.EvaluateJavaScript(js_is_done) | 17 return tab.EvaluateJavaScript(js_is_done) |
| 18 util.WaitFor(_IsDone, 300, poll_interval=5) | 18 util.WaitFor(_IsDone, 300, poll_interval=5) |
| 19 | 19 |
| 20 js_get_results = 'JSON.stringify(output);' | 20 js_get_results = 'JSON.stringify(output);' |
| 21 js_results = json.loads(tab.EvaluateJavaScript(js_get_results)) | 21 js_results = json.loads(tab.EvaluateJavaScript(js_get_results)) |
| 22 r = collections.defaultdict(list) | 22 r = collections.defaultdict(list) |
| 23 totals = [] | 23 totals = [] |
| 24 # js_results is: [{'foo': v1, 'bar': v2}, | 24 # js_results is: [{'foo': v1, 'bar': v2}, |
| 25 # {'foo': v3, 'bar': v4}, | 25 # {'foo': v3, 'bar': v4}, |
| 26 # ...] | 26 # ...] |
| 27 for result in js_results: | 27 for result in js_results: |
| 28 total = 0 | 28 total = 0 |
| 29 for key, value in result.iteritems(): | 29 for key, value in result.iteritems(): |
| 30 r[key].append(value) | 30 r[key].append(value) |
| 31 total += value | 31 total += value |
| 32 totals.append(total) | 32 totals.append(total) |
| 33 for key, values in r.iteritems(): | 33 for key, values in r.iteritems(): |
| 34 results.Add('t', 'ms', values, chart_name=key, data_type='unimportant') | 34 results.Add('t', 'ms', values, chart_name=key, data_type='unimportant') |
| 35 results.Add('t', 'ms', totals, chart_name='total') | 35 results.Add('t', 'ms', totals, chart_name='total') |
| OLD | NEW |