1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5import imp 6import os 7import sys 8import urllib 9 10# Directory path in which to save bootstrap files. 11BOOTSTRAPPED_FILES_DIR = 'support/bootstrap_files' 12PERF_DIR = 'src/tools/perf' 13DEPS_FILE = 'bootstrap_deps' 14BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 15 16def BootstrapIfNeeded(module_name, module_path, module_deps_url): 17 """Ensures that the given module_name is available, grab from URL if not.""" 18 try: 19 imp.find_module(module_name) 20 return 21 except ImportError: 22 sys.path.append(os.path.join(BASE_DIR, BOOTSTRAPPED_FILES_DIR, module_path)) 23 try: 24 imp.find_module(module_name) 25 return 26 except ImportError: 27 bootstrap_txt = urllib.urlopen('http://src.chromium.org/viewvc/chrome/' + 28 'trunk/src/tools/telemetry_tools/' + 29 'telemetry_bootstrap.py').read() 30 bootstrap = imp.new_module('bootstrap') 31 exec bootstrap_txt in bootstrap.__dict__ 32 bootstrap.DownloadDepsURL(os.path.join(BASE_DIR, BOOTSTRAPPED_FILES_DIR), 33 module_deps_url) 34 return 35 36def ListBootstrapDeps(): 37 """List the deps required for telemetry. 38 39 Returns: a list of telemetry deps. 40 """ 41 # Add telemetry_tools to sys.path for the import below 42 telemetry_tools_path = os.path.join(BASE_DIR, os.pardir, 'telemetry_tools') 43 sys.path.append(telemetry_tools_path) 44 45 import perf_tools 46 import telemetry_bootstrap 47 deps_file = os.path.join(os.path.dirname(perf_tools.__file__), DEPS_FILE) 48 return telemetry_bootstrap.ListAllDepsPaths(open(deps_file).read()) 49 50def main(): 51 BootstrapIfNeeded('perf_tools', PERF_DIR, 52 'http://src.chromium.org/viewvc/chrome/trunk/src/tools' 53 '/perf/perf_tools/' + DEPS_FILE) 54 55 # Add telemetry to sys.path for the import below 56 telemetry_path = os.path.join(BASE_DIR, os.pardir, 'telemetry') 57 sys.path.append(telemetry_path) 58 59 if '--print-bootstrap-deps' in sys.argv: 60 print ListBootstrapDeps() 61 sys.exit(0) 62 63 from telemetry.page import page_measurement_runner 64 import page_sets 65 page_set_filenames = page_sets.GetAllPageSetFilenames() 66 67 old_benchmark_names = { 68 "image_decoding_benchmark": "image_decoding", 69 "image_decoding_measurement": "image_decoding", 70 "loading_benchmark": "loading", 71 "loading_measurement": "loading", 72 "media_measurement": "media", 73 "memory_benchmark": "memory", 74 "memory_measurement": "memory", 75 "rasterize_and_record_benchmark": "rasterize_and_record", 76 "rasterize_and_record_measurement": "rasterize_and_record", 77 "robohornetpro": "robohornet_pro", 78 "scrolling_benchmark": "smoothness", 79 "smoothness_benchmark": "smoothness", 80 "smoothness_measurement": "smoothness", 81 "startup_benchmark": "startup_warm_blank_page", 82 "startup_measurement": "startup", 83 "tab_switching_measurement": "tab_switching", 84 } 85 86 # There are bots that are hard-coded to run some specific named tests. 87 # Convert these to the current naming conventions by overriding them in the runner. 88 class MeasurementRunner(page_measurement_runner.PageMeasurementRunner): 89 def GetModernizedTestName(self, arg): 90 if arg not in old_benchmark_names: 91 return arg 92 sys.stderr.write( 93 'An old name %s was given. Please use %s in the future.\n' % ( 94 arg, 95 old_benchmark_names.get(arg))) 96 return old_benchmark_names[arg] 97 98 runner = MeasurementRunner() 99 sys.exit(runner.Run(BASE_DIR, page_set_filenames)) 100 101if __name__ == '__main__': 102 sys.exit(main()) 103