blob: 77f1748d2d30b6079fd2cbe8a193d36ba4fbcfcc [file] [log] [blame]
[email protected]8997afd2013-02-21 17:20:041#!/usr/bin/env python
2# Copyright (c) 2013 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.
5
6"""Run Performance Test Bisect Tool
7
8This script is used by a trybot to run the src/tools/bisect-perf-regression.py
9script with the parameters specified in run-bisect-perf-regression.cfg. It will
10check out a copy of the depot in a subdirectory 'bisect' of the working
11directory provided, and run the bisect-perf-regression.py script there.
12
13"""
14
15import imp
16import optparse
17import os
18import subprocess
19import sys
[email protected]d6f9b9ef2013-05-29 17:13:0120import traceback
[email protected]8997afd2013-02-21 17:20:0421
[email protected]2a75ef72013-06-06 17:39:0322CROS_BOARD_ENV = 'BISECT_CROS_BOARD'
23CROS_IP_ENV = 'BISECT_CROS_IP'
[email protected]8997afd2013-02-21 17:20:0424
[email protected]cada4c22013-02-26 00:27:4625def LoadConfigFile(path_to_file):
[email protected]8997afd2013-02-21 17:20:0426 """Attempts to load the file 'run-bisect-perf-regression.cfg' as a module
27 and grab the global config dict.
28
[email protected]cada4c22013-02-26 00:27:4629 Args:
30 path_to_file: Path to the run-bisect-perf-regression.cfg file.
31
[email protected]8997afd2013-02-21 17:20:0432 Returns:
33 The config dict which should be formatted as follows:
34 {'command': string, 'good_revision': string, 'bad_revision': string
35 'metric': string}.
36 Returns None on failure.
37 """
38 try:
39 local_vars = {}
[email protected]cada4c22013-02-26 00:27:4640 execfile(os.path.join(path_to_file, 'run-bisect-perf-regression.cfg'),
41 local_vars)
[email protected]8997afd2013-02-21 17:20:0442
43 return local_vars['config']
44 except:
[email protected]d6f9b9ef2013-05-29 17:13:0145 print
46 traceback.print_exc()
47 print
[email protected]8997afd2013-02-21 17:20:0448 return None
49
50
[email protected]e69075f2013-03-01 02:21:4551def RunBisectionScript(config, working_directory, path_to_file, path_to_goma):
[email protected]8997afd2013-02-21 17:20:0452 """Attempts to execute src/tools/bisect-perf-regression.py with the parameters
53 passed in.
54
55 Args:
56 config: A dict containing the parameters to pass to the script.
[email protected]cada4c22013-02-26 00:27:4657 working_directory: A working directory to provide to the
58 bisect-perf-regression.py script, where it will store it's own copy of
59 the depot.
60 path_to_file: Path to the bisect-perf-regression.py script.
[email protected]e69075f2013-03-01 02:21:4561 path_to_goma: Path to goma directory.
[email protected]8997afd2013-02-21 17:20:0462
63 Returns:
64 0 on success, otherwise 1.
65 """
66
[email protected]cada4c22013-02-26 00:27:4667 cmd = ['python', os.path.join(path_to_file, 'bisect-perf-regression.py'),
[email protected]8997afd2013-02-21 17:20:0468 '-c', config['command'],
69 '-g', config['good_revision'],
70 '-b', config['bad_revision'],
71 '-m', config['metric'],
72 '--working_directory', working_directory,
73 '--output_buildbot_annotations']
74
[email protected]f3a100d2013-03-06 23:23:4675 if config['repeat_count']:
76 cmd.extend(['-r', config['repeat_count']])
77
78 if config['truncate_percent']:
79 cmd.extend(['-t', config['truncate_percent']])
80
[email protected]2bf15152013-03-28 21:40:3981 if config['max_time_minutes']:
82 cmd.extend(['--repeat_test_max_time', config['max_time_minutes']])
83
[email protected]bda7af42013-06-10 23:49:4284 cmd.extend(['--build_preference', 'ninja'])
[email protected]2deb10d2013-03-15 19:29:5085
[email protected]2a75ef72013-06-06 17:39:0386 if '--browser=cros' in config['command']:
87 cmd.extend(['--target_platform', 'cros'])
88
89 if os.environ[CROS_BOARD_ENV] and os.environ[CROS_IP_ENV]:
90 cmd.extend(['--cros_board', os.environ[CROS_BOARD_ENV]])
91 cmd.extend(['--cros_remote_ip', os.environ[CROS_IP_ENV]])
92 else:
93 print 'Error: Cros build selected, but BISECT_CROS_IP or'\
94 'BISECT_CROS_BOARD undefined.'
95 print
96 return 1
97
[email protected]bda7af42013-06-10 23:49:4298 if '--browser=android' in config['command']:
99 cmd.extend(['--target_platform', 'android'])
100
[email protected]e69075f2013-03-01 02:21:45101 goma_file = ''
102 if path_to_goma:
103 path_to_goma = os.path.abspath(path_to_goma)
104
105 if os.name == 'nt':
106 os.environ['CC'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
107 os.environ['CXX'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
108 goma_file = os.path.join(path_to_goma, 'goma_ctl.bat')
109 else:
110 os.environ['PATH'] = os.pathsep.join([path_to_goma, os.environ['PATH']])
111 goma_file = os.path.join(path_to_goma, 'goma_ctl.sh')
112
113 cmd.append('--use_goma')
114
[email protected]8f6173ec2013-03-18 19:07:58115 # Sometimes goma is lingering around if something went bad on a previous
116 # run. Stop it before starting a new process. Can ignore the return code
117 # since it will return an error if it wasn't running.
118 subprocess.call([goma_file, 'stop'])
119
[email protected]e69075f2013-03-01 02:21:45120 return_code = subprocess.call([goma_file, 'start'])
121 if return_code:
122 print 'Error: goma failed to start.'
123 print
124 return return_code
125
[email protected]2deb10d2013-03-15 19:29:50126 cmd = [str(c) for c in cmd]
127
[email protected]8997afd2013-02-21 17:20:04128 return_code = subprocess.call(cmd)
129
[email protected]e69075f2013-03-01 02:21:45130 if path_to_goma:
131 subprocess.call([goma_file, 'stop'])
132
[email protected]8997afd2013-02-21 17:20:04133 if return_code:
134 print 'Error: bisect-perf-regression.py returned with error %d' %\
135 return_code
136 print
137
138 return return_code
139
140
141def main():
142
143 usage = ('%prog [options] [-- chromium-options]\n'
144 'Used by a trybot to run the bisection script using the parameters'
145 ' provided in the run-bisect-perf-regression.cfg file.')
146
147 parser = optparse.OptionParser(usage=usage)
148 parser.add_option('-w', '--working_directory',
149 type='str',
150 help='A working directory to supply to the bisection '
151 'script, which will use it as the location to checkout '
152 'a copy of the chromium depot.')
[email protected]e69075f2013-03-01 02:21:45153 parser.add_option('-p', '--path_to_goma',
154 type='str',
155 help='Path to goma directory. If this is supplied, goma '
156 'builds will be enabled.')
[email protected]8997afd2013-02-21 17:20:04157 (opts, args) = parser.parse_args()
158
159 if not opts.working_directory:
160 print 'Error: missing required parameter: --working_directory'
161 print
162 parser.print_help()
163 return 1
164
[email protected]cada4c22013-02-26 00:27:46165 path_to_file = os.path.abspath(os.path.dirname(sys.argv[0]))
166
167 config = LoadConfigFile(path_to_file)
[email protected]8997afd2013-02-21 17:20:04168 if not config:
[email protected]d6f9b9ef2013-05-29 17:13:01169 print 'Error: Could not load config file. Double check your changes to '\
170 'run-bisect-perf-regression.cfg for syntax errors.'
[email protected]8997afd2013-02-21 17:20:04171 print
172 return 1
173
[email protected]e69075f2013-03-01 02:21:45174 return RunBisectionScript(config, opts.working_directory, path_to_file,
175 opts.path_to_goma)
[email protected]8997afd2013-02-21 17:20:04176
177
178if __name__ == '__main__':
179 sys.exit(main())