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 spaceport.io's PerfMarks benchmark.""" 6 7 import logging 8 import os 9 import sys 10 11 from telemetry import test 12 from telemetry.core import util 13 from telemetry.page import page_measurement 14 from telemetry.page import page_set 15 16 17 class _SpaceportMeasurement(page_measurement.PageMeasurement): 18 def CustomizeBrowserOptions(self, options): 19 options.AppendExtraBrowserArgs('--disable-gpu-vsync') 20 21 def MeasurePage(self, _, tab, results): 22 tab.WaitForJavaScriptExpression( 23 '!document.getElementById("start-performance-tests").disabled', 60) 24 25 tab.ExecuteJavaScript(""" 26 window.__results = {}; 27 window.console.log = function(str) { 28 if (!str) return; 29 var key_val = str.split(': '); 30 if (!key_val.length == 2) return; 31 __results[key_val[0]] = key_val[1]; 32 }; 33 document.getElementById('start-performance-tests').click(); 34 """) 35 36 num_results = 0 37 num_tests_in_spaceport = 24 38 while num_results < num_tests_in_spaceport: 39 tab.WaitForJavaScriptExpression( 40 'Object.keys(window.__results).length > %d' % num_results, 180) 41 num_results = tab.EvaluateJavaScript( 42 'Object.keys(window.__results).length') 43 logging.info('Completed test %d of %d' % 44 (num_results, num_tests_in_spaceport)) 45 46 result_dict = eval(tab.EvaluateJavaScript( 47 'JSON.stringify(window.__results)')) 48 for key in result_dict: 49 chart, trace = key.split('.', 1) 50 results.Add(trace, 'objects (bigger is better)', float(result_dict[key]), 51 chart_name=chart, data_type='unimportant') 52 results.Add('Score', 'objects (bigger is better)', 53 [float(x) for x in result_dict.values()]) 54 55 56 class Spaceport(test.Test): 57 """spaceport.io's PerfMarks benchmark.""" 58 test = _SpaceportMeasurement 59 60 # crbug.com/166703: This test frequently times out on Windows. 61 enabled = sys.platform != 'darwin' and not sys.platform.startswith('win') 62 63 def CreatePageSet(self, options): 64 spaceport_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test', 65 'data', 'third_party', 'spaceport') 66 return page_set.PageSet.FromDict( 67 {'pages': [{'url': 'file://index.html'}]}, 68 spaceport_dir) 69