[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 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. |
| 5 | |
| 6 | """Run Performance Test Bisect Tool |
| 7 | |
| 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. |
| 12 | |
| 13 | """ |
| 14 | |
| 15 | import imp |
| 16 | import optparse |
| 17 | import os |
| 18 | import subprocess |
| 19 | import sys |
[email protected] | d6f9b9ef | 2013-05-29 17:13:01 | [diff] [blame] | 20 | import traceback |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 21 | |
[email protected] | 2a75ef7 | 2013-06-06 17:39:03 | [diff] [blame] | 22 | CROS_BOARD_ENV = 'BISECT_CROS_BOARD' |
| 23 | CROS_IP_ENV = 'BISECT_CROS_IP' |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 24 | |
[email protected] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 25 | def LoadConfigFile(path_to_file): |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 26 | """Attempts to load the file 'run-bisect-perf-regression.cfg' as a module |
| 27 | and grab the global config dict. |
| 28 | |
[email protected] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 29 | Args: |
| 30 | path_to_file: Path to the run-bisect-perf-regression.cfg file. |
| 31 | |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 32 | 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] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 40 | execfile(os.path.join(path_to_file, 'run-bisect-perf-regression.cfg'), |
| 41 | local_vars) |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 42 | |
| 43 | return local_vars['config'] |
| 44 | except: |
[email protected] | d6f9b9ef | 2013-05-29 17:13:01 | [diff] [blame] | 45 | print |
| 46 | traceback.print_exc() |
| 47 | print |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 48 | return None |
| 49 | |
| 50 | |
[email protected] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 51 | def RunBisectionScript(config, working_directory, path_to_file, path_to_goma): |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 52 | """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] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 57 | 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] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 61 | path_to_goma: Path to goma directory. |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 62 | |
| 63 | Returns: |
| 64 | 0 on success, otherwise 1. |
| 65 | """ |
| 66 | |
[email protected] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 67 | cmd = ['python', os.path.join(path_to_file, 'bisect-perf-regression.py'), |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 68 | '-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] | f3a100d | 2013-03-06 23:23:46 | [diff] [blame] | 75 | 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] | 2bf1515 | 2013-03-28 21:40:39 | [diff] [blame] | 81 | if config['max_time_minutes']: |
| 82 | cmd.extend(['--repeat_test_max_time', config['max_time_minutes']]) |
| 83 | |
[email protected] | bda7af4 | 2013-06-10 23:49:42 | [diff] [blame] | 84 | cmd.extend(['--build_preference', 'ninja']) |
[email protected] | 2deb10d | 2013-03-15 19:29:50 | [diff] [blame] | 85 | |
[email protected] | 2a75ef7 | 2013-06-06 17:39:03 | [diff] [blame] | 86 | 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] | bda7af4 | 2013-06-10 23:49:42 | [diff] [blame] | 98 | if '--browser=android' in config['command']: |
| 99 | cmd.extend(['--target_platform', 'android']) |
| 100 | |
[email protected] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 101 | 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] | 8f6173ec | 2013-03-18 19:07:58 | [diff] [blame] | 115 | # 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] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 120 | 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] | 2deb10d | 2013-03-15 19:29:50 | [diff] [blame] | 126 | cmd = [str(c) for c in cmd] |
| 127 | |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 128 | return_code = subprocess.call(cmd) |
| 129 | |
[email protected] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 130 | if path_to_goma: |
| 131 | subprocess.call([goma_file, 'stop']) |
| 132 | |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 133 | 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 | |
| 141 | def 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] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 153 | 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] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 157 | (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] | cada4c2 | 2013-02-26 00:27:46 | [diff] [blame] | 165 | path_to_file = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 166 | |
| 167 | config = LoadConfigFile(path_to_file) |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 168 | if not config: |
[email protected] | d6f9b9ef | 2013-05-29 17:13:01 | [diff] [blame] | 169 | print 'Error: Could not load config file. Double check your changes to '\ |
| 170 | 'run-bisect-perf-regression.cfg for syntax errors.' |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 171 | print |
| 172 | return 1 |
| 173 | |
[email protected] | e69075f | 2013-03-01 02:21:45 | [diff] [blame] | 174 | return RunBisectionScript(config, opts.working_directory, path_to_file, |
| 175 | opts.path_to_goma) |
[email protected] | 8997afd | 2013-02-21 17:20:04 | [diff] [blame] | 176 | |
| 177 | |
| 178 | if __name__ == '__main__': |
| 179 | sys.exit(main()) |