Revert of [telemetry] Script for finding all Telemetry dependencies. (https://coderev...
[chromium-blink-merge.git] / tools / perf / run_measurement
blobb91b59476c017609871e9963066dd58b6f50a9fa
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.
6 import imp
7 import os
8 import sys
9 import urllib2
12 BASE_URL = 'http://src.chromium.org/chrome/trunk/'
13 DEPS_FILE = 'bootstrap_deps'
15 SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
16 # Directory containing src/ in a Chromium checkout.
17 CHECKOUT_BASE_PATH = os.path.join(SCRIPT_PATH, os.pardir, os.pardir, os.pardir)
18 # Directory in which to save bootstrap files.
19 BOOTSTRAP_BASE_PATH = os.path.join(SCRIPT_PATH, 'support', 'bootstrap_files')
21 CROS_DIR = os.path.join('src', 'tools', 'cros')
22 PERF_DIR = os.path.join('src', 'tools', 'perf')
23 TELEMETRY_DIR = os.path.join('src', 'tools', 'telemetry')
24 TELEMETRY_TOOLS_DIR = os.path.join('src', 'tools', 'telemetry_tools')
27 def _GetBasePath():
28 """Find the location of our Chromium or bootstrap checkout.
30 It tries to import Telemetry. If the import succeeds,
31 we assume that's the correct location.
33 Returns:
34 The path containing the src/ directory, or None if no checkout is found.
35 """
36 module_name = 'telemetry'
37 module_path = TELEMETRY_DIR
39 try:
40 paths = [os.path.join(CHECKOUT_BASE_PATH, module_path)]
41 imp.find_module(module_name, paths)
42 return CHECKOUT_BASE_PATH
43 except ImportError:
44 pass
46 try:
47 paths = [os.path.join(BOOTSTRAP_BASE_PATH, module_path)]
48 imp.find_module(module_name, paths)
49 return BOOTSTRAP_BASE_PATH
50 except ImportError:
51 pass
53 return None
56 def _Bootstrap(bootstrap_deps_url):
57 """Grab all the deps listed in the file at bootstrap_deps_url."""
58 bootstrap_txt = urllib2.urlopen(
59 BASE_URL + 'src/tools/telemetry_tools/telemetry_bootstrap.py').read()
60 bootstrap = imp.new_module('bootstrap')
61 exec bootstrap_txt in bootstrap.__dict__
62 bootstrap.DownloadDeps(BOOTSTRAP_BASE_PATH, bootstrap_deps_url)
65 def ListBootstrapDeps(base_path, subdir):
66 """List the deps required for telemetry."""
67 sys.path.append(os.path.join(base_path, TELEMETRY_TOOLS_DIR))
68 import telemetry_bootstrap
70 deps_file = os.path.join(base_path, subdir, DEPS_FILE)
71 return telemetry_bootstrap.ListAllDepsPaths(deps_file)
74 def Main():
75 if not _GetBasePath():
76 _Bootstrap(BASE_URL + 'src/tools/perf/' + DEPS_FILE)
78 new_base_path = _GetBasePath()
79 new_perf_path = os.path.join(new_base_path, PERF_DIR)
80 new_telemetry_path = os.path.join(new_base_path, TELEMETRY_DIR)
82 if '--print-bootstrap-deps-cros' in sys.argv:
83 print ListBootstrapDeps(new_base_path, CROS_DIR)
84 return 0
86 if '--print-bootstrap-deps' in sys.argv:
87 print ListBootstrapDeps(new_base_path, PERF_DIR)
88 return 0
90 sys.path.append(new_perf_path)
91 import page_sets
92 page_set_filenames = page_sets.GetAllPageSetFilenames()
94 old_benchmark_names = {
95 "image_decoding_benchmark": "image_decoding",
96 "image_decoding_measurement": "image_decoding",
97 "loading_benchmark": "loading",
98 "loading_measurement": "loading",
99 "media_measurement": "media",
100 "memory_benchmark": "memory",
101 "memory_measurement": "memory",
102 "rasterize_and_record_benchmark": "rasterize_and_record",
103 "rasterize_and_record_measurement": "rasterize_and_record",
104 "robohornetpro": "robohornet_pro",
105 "scrolling_benchmark": "smoothness",
106 "smoothness_benchmark": "smoothness",
107 "smoothness_measurement": "smoothness",
108 "startup_benchmark": "startup_warm_blank_page",
109 "startup_measurement": "startup",
110 "tab_switching_measurement": "tab_switching",
113 sys.path.append(new_telemetry_path)
114 from telemetry.page import page_measurement_runner
115 # There are bots that are hard-coded to run some specific named tests.
116 # Convert these to the current naming conventions by overriding them
117 # in the runner.
118 class MeasurementRunner(page_measurement_runner.PageMeasurementRunner):
119 def GetModernizedTestName(self, arg):
120 if arg not in old_benchmark_names:
121 return arg
122 sys.stderr.write(
123 'An old name %s was given. Please use %s in the future.\n' % (
124 arg,
125 old_benchmark_names.get(arg)))
126 return old_benchmark_names[arg]
128 runner = MeasurementRunner()
129 return runner.Run(new_perf_path, page_set_filenames)
132 if __name__ == '__main__':
133 sys.exit(Main())