| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2016 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 a profiling benchmark for a PGO build. | |
| 7 | |
| 8 This wrapper script is required so we can find the path to pgosweep.exe. | |
| 9 """ | |
| 10 | |
| 11 import json | |
| 12 import optparse | |
| 13 import os | |
| 14 import subprocess | |
| 15 import sys | |
| 16 | |
| 17 | |
| 18 def find_pgosweep(chrome_checkout_dir, target_bits): | |
| 19 """Find the directory containing pgosweep.exe.""" | |
| 20 win_toolchain_json_file = os.path.join(chrome_checkout_dir, 'build', | |
| 21 'win_toolchain.json') | |
| 22 if not os.path.exists(win_toolchain_json_file): | |
| 23 print 'The toolchain JSON file is missing.' | |
| 24 return | |
| 25 with open(win_toolchain_json_file) as temp_f: | |
| 26 toolchain_data = json.load(temp_f) | |
| 27 if not os.path.isdir(toolchain_data['path']): | |
| 28 print 'The toolchain JSON file is invalid.' | |
| 29 return | |
| 30 | |
| 31 pgo_sweep_dir = os.path.join(toolchain_data['path'], 'VC', 'bin') | |
| 32 if target_bits == 64: | |
| 33 pgo_sweep_dir = os.path.join(pgo_sweep_dir, 'amd64') | |
| 34 | |
| 35 if not os.path.exists(os.path.join(pgo_sweep_dir, 'pgosweep.exe')): | |
| 36 print 'pgosweep.exe is missing from %s.' % pgo_sweep_dir | |
| 37 return | |
| 38 | |
| 39 return pgo_sweep_dir | |
| 40 | |
| 41 | |
| 42 def main(): | |
| 43 parser = optparse.OptionParser(usage='%prog [options]') | |
| 44 parser.add_option( | |
| 45 '--checkout-dir', help='The Chrome checkout directory.') | |
| 46 parser.add_option( | |
| 47 '--browser-type', help='The browser type (to be passed to Telemetry\'s ' | |
| 48 'benchmark runner).') | |
| 49 parser.add_option('--target-bits', help='The target\'s bitness.', type=int) | |
| 50 parser.add_option('--benchmark', help='The benchmark to run.') | |
| 51 parser.add_option('--build-dir', help='Chrome build directory.') | |
| 52 options, _ = parser.parse_args() | |
| 53 | |
| 54 if not options.checkout_dir: | |
| 55 parser.error('--checkout-dir is required') | |
| 56 if not options.browser_type: | |
| 57 parser.error('--browser-type is required') | |
| 58 if not options.target_bits: | |
| 59 parser.error('--target-bits is required') | |
| 60 if not options.benchmark: | |
| 61 parser.error('--benchmark is required') | |
| 62 if not options.build_dir: | |
| 63 parser.error('--build-dir is required') | |
| 64 | |
| 65 # Starts by finding the directory containing pgosweep.exe | |
| 66 pgo_sweep_dir = find_pgosweep(options.checkout_dir, options.target_bits) | |
| 67 if not pgo_sweep_dir: | |
| 68 return 1 | |
| 69 | |
| 70 # Then find the run_benchmark script. | |
| 71 chrome_run_benchmark_script = os.path.join(options.checkout_dir, 'tools', | |
| 72 'perf', 'run_benchmark') | |
| 73 if not os.path.exists(chrome_run_benchmark_script): | |
| 74 print ('Unable to find the run_benchmark script (%s doesn\'t exist) ' % | |
| 75 chrome_run_benchmark_script) | |
| 76 return 1 | |
| 77 | |
| 78 # Augment the PATH to make sure that the benchmarking script can find | |
| 79 # pgosweep.exe and its runtime libraries. | |
| 80 env = os.environ.copy() | |
| 81 env['PATH'] = str(os.pathsep.join([pgo_sweep_dir, options.build_dir, | |
| 82 os.environ['PATH']])) | |
| 83 env['PogoSafeMode'] = '1' | |
| 84 # Apply a scaling factor of 0.5 to the PGO profiling buffers for the 32-bit | |
| 85 # builds, without this the buffers will be too large and the process will | |
| 86 # fail to start. See crbug.com/632864#c22. | |
| 87 if options.target_bits == 32: | |
| 88 env['VCPROFILE_ALLOC_SCALE'] = '0.5' | |
| 89 | |
| 90 benchmark_command = [ | |
| 91 sys.executable, | |
| 92 chrome_run_benchmark_script, | |
| 93 '--browser', options.browser_type, | |
| 94 '--profiler', 'win_pgo_profiler', | |
| 95 options.benchmark | |
| 96 ] | |
| 97 return subprocess.call(benchmark_command, env=env) | |
| 98 | |
| 99 | |
| 100 if __name__ == '__main__': | |
| 101 sys.exit(main()) | |
| OLD | NEW |