Disable flaky test ExtensionActionContextMenuTest.RunInspectPopup
[chromium-blink-merge.git] / tools / run-bisect-perf-regression.py
blob880794216694fa11a48079f481bc4ef77809bd19
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 goma_file = ''
76 if path_to_goma:
77 path_to_goma = os.path.abspath(path_to_goma)
79 if os.name == 'nt':
80 os.environ['CC'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
81 os.environ['CXX'] = os.path.join(path_to_goma, 'gomacc.exe') + ' cl.exe'
82 goma_file = os.path.join(path_to_goma, 'goma_ctl.bat')
83 else:
84 os.environ['PATH'] = os.pathsep.join([path_to_goma, os.environ['PATH']])
85 goma_file = os.path.join(path_to_goma, 'goma_ctl.sh')
87 cmd.append('--use_goma')
89 return_code = subprocess.call([goma_file, 'start'])
90 if return_code:
91 print 'Error: goma failed to start.'
92 print
93 return return_code
95 return_code = subprocess.call(cmd)
97 if path_to_goma:
98 subprocess.call([goma_file, 'stop'])
100 if return_code:
101 print 'Error: bisect-perf-regression.py returned with error %d' %\
102 return_code
103 print
105 return return_code
108 def main():
110 usage = ('%prog [options] [-- chromium-options]\n'
111 'Used by a trybot to run the bisection script using the parameters'
112 ' provided in the run-bisect-perf-regression.cfg file.')
114 parser = optparse.OptionParser(usage=usage)
115 parser.add_option('-w', '--working_directory',
116 type='str',
117 help='A working directory to supply to the bisection '
118 'script, which will use it as the location to checkout '
119 'a copy of the chromium depot.')
120 parser.add_option('-p', '--path_to_goma',
121 type='str',
122 help='Path to goma directory. If this is supplied, goma '
123 'builds will be enabled.')
124 (opts, args) = parser.parse_args()
126 if not opts.working_directory:
127 print 'Error: missing required parameter: --working_directory'
128 print
129 parser.print_help()
130 return 1
132 path_to_file = os.path.abspath(os.path.dirname(sys.argv[0]))
134 config = LoadConfigFile(path_to_file)
135 if not config:
136 print 'Error: Could not load config file.'
137 print
138 return 1
140 return RunBisectionScript(config, opts.working_directory, path_to_file,
141 opts.path_to_goma)
144 if __name__ == '__main__':
145 sys.exit(main())