Add debug shortcuts that toggles options to shows debug borders and fps counters
[chromium-blink-merge.git] / tools / run-bisect-perf-regression.py
blob78e570a788c6a1147593ffac1e82324b916f57d8
1 #!/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.
6 """Run Performance Test Bisect Tool
8 This script is used by a trybot to run the src/tools/bisect-perf-regression.py
9 script with the parameters specified in run-bisect-perf-regression.cfg. It will
10 check out a copy of the depot in a subdirectory 'bisect' of the working
11 directory provided, and run the bisect-perf-regression.py script there.
13 """
15 import imp
16 import optparse
17 import os
18 import subprocess
19 import sys
22 def LoadConfigFile(path_to_file):
23 """Attempts to load the file 'run-bisect-perf-regression.cfg' as a module
24 and grab the global config dict.
26 Args:
27 path_to_file: Path to the run-bisect-perf-regression.cfg file.
29 Returns:
30 The config dict which should be formatted as follows:
31 {'command': string, 'good_revision': string, 'bad_revision': string
32 'metric': string}.
33 Returns None on failure.
34 """
35 try:
36 local_vars = {}
37 execfile(os.path.join(path_to_file, 'run-bisect-perf-regression.cfg'),
38 local_vars)
40 return local_vars['config']
41 except:
42 return None
45 def RunBisectionScript(config, working_directory, path_to_file, path_to_goma):
46 """Attempts to execute src/tools/bisect-perf-regression.py with the parameters
47 passed in.
49 Args:
50 config: A dict containing the parameters to pass to the script.
51 working_directory: A working directory to provide to the
52 bisect-perf-regression.py script, where it will store it's own copy of
53 the depot.
54 path_to_file: Path to the bisect-perf-regression.py script.
55 path_to_goma: Path to goma directory.
57 Returns:
58 0 on success, otherwise 1.
59 """
61 cmd = ['python', os.path.join(path_to_file, 'bisect-perf-regression.py'),
62 '-c', config['command'],
63 '-g', config['good_revision'],
64 '-b', config['bad_revision'],
65 '-m', config['metric'],
66 '--working_directory', working_directory,
67 '--output_buildbot_annotations']
69 if config['repeat_count']:
70 cmd.extend(['-r', config['repeat_count']])
72 if config['truncate_percent']:
73 cmd.extend(['-t', config['truncate_percent']])
75 if config['max_time_minutes']:
76 cmd.extend(['--repeat_test_max_time', config['max_time_minutes']])
78 if os.name == 'nt':
79 cmd.extend(['--build_preference', 'ninja'])
80 else:
81 cmd.extend(['--build_preference', 'make'])
83 goma_file = ''
84 if path_to_goma:
85 path_to_goma = os.path.abspath(path_to_goma)
87 if os.name == 'nt':
88 os.environ['CC'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
89 os.environ['CXX'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
90 goma_file = os.path.join(path_to_goma, 'goma_ctl.bat')
91 else:
92 os.environ['PATH'] = os.pathsep.join([path_to_goma, os.environ['PATH']])
93 goma_file = os.path.join(path_to_goma, 'goma_ctl.sh')
95 cmd.append('--use_goma')
97 # Sometimes goma is lingering around if something went bad on a previous
98 # run. Stop it before starting a new process. Can ignore the return code
99 # since it will return an error if it wasn't running.
100 subprocess.call([goma_file, 'stop'])
102 return_code = subprocess.call([goma_file, 'start'])
103 if return_code:
104 print 'Error: goma failed to start.'
105 print
106 return return_code
108 cmd = [str(c) for c in cmd]
110 return_code = subprocess.call(cmd)
112 if path_to_goma:
113 subprocess.call([goma_file, 'stop'])
115 if return_code:
116 print 'Error: bisect-perf-regression.py returned with error %d' %\
117 return_code
118 print
120 return return_code
123 def main():
125 usage = ('%prog [options] [-- chromium-options]\n'
126 'Used by a trybot to run the bisection script using the parameters'
127 ' provided in the run-bisect-perf-regression.cfg file.')
129 parser = optparse.OptionParser(usage=usage)
130 parser.add_option('-w', '--working_directory',
131 type='str',
132 help='A working directory to supply to the bisection '
133 'script, which will use it as the location to checkout '
134 'a copy of the chromium depot.')
135 parser.add_option('-p', '--path_to_goma',
136 type='str',
137 help='Path to goma directory. If this is supplied, goma '
138 'builds will be enabled.')
139 (opts, args) = parser.parse_args()
141 if not opts.working_directory:
142 print 'Error: missing required parameter: --working_directory'
143 print
144 parser.print_help()
145 return 1
147 path_to_file = os.path.abspath(os.path.dirname(sys.argv[0]))
149 config = LoadConfigFile(path_to_file)
150 if not config:
151 print 'Error: Could not load config file.'
152 print
153 return 1
155 return RunBisectionScript(config, opts.working_directory, path_to_file,
156 opts.path_to_goma)
159 if __name__ == '__main__':
160 sys.exit(main())