OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Utility script to run the benchmarks during the profiling step of a PGO |
| 6 build. |
| 7 """ |
| 8 |
| 9 import json |
| 10 import optparse |
| 11 import os |
| 12 import subprocess |
| 13 import sys |
| 14 |
| 15 # Make sure that we're running as admin, this is required to run the Telemetry |
| 16 # benchmarks. |
| 17 from win32com.shell import shell |
| 18 if not shell.IsUserAnAdmin(): |
| 19 raise Exception('This script has to be run as admin.') |
| 20 |
| 21 |
| 22 _SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) |
| 23 _CHROME_BUILD_DIR = os.path.dirname(_SCRIPT_DIR) |
| 24 _CHROME_SRC_DIR = os.path.dirname(_CHROME_BUILD_DIR) |
| 25 |
| 26 |
| 27 # List of the benchmark that we run during the profiling step. |
| 28 _BENCHMARKS_TO_RUN = { |
| 29 'blink_perf.bindings', |
| 30 'blink_perf.canvas', |
| 31 'blink_perf.css', |
| 32 'blink_perf.dom', |
| 33 'blink_perf.paint', |
| 34 'blink_perf.svg', |
| 35 'blink_style.top_25', |
| 36 'dromaeo.cssqueryjquery', |
| 37 'dromaeo.domcoreattr', |
| 38 'dromaeo.domcoremodify', |
| 39 'dromaeo.domcorequery', |
| 40 'dromaeo.domcoretraverse', |
| 41 'dromaeo.jslibattrprototype', |
| 42 'dromaeo.jslibeventprototype', |
| 43 'dromaeo.jslibmodifyprototype', |
| 44 'dromaeo.jslibstyleprototype', |
| 45 'dromaeo.jslibtraversejquery', |
| 46 'dromaeo.jslibtraverseprototype', |
| 47 'indexeddb_perf', |
| 48 'media.tough_video_cases', |
| 49 'octane', |
| 50 'smoothness.top_25_smooth', |
| 51 'speedometer', |
| 52 'sunspider', |
| 53 } |
| 54 |
| 55 |
| 56 def FindPgosweep(target_cpu): |
| 57 """Find the directory containing pgosweep.exe. |
| 58 |
| 59 Note: |target_cpu| should be x86 or x64. |
| 60 """ |
| 61 if target_cpu not in ('x86', 'x64'): |
| 62 raise Exception('target_cpu should be x86 or x64.') |
| 63 win_toolchain_json_file = os.path.join(_CHROME_BUILD_DIR, |
| 64 'win_toolchain.json') |
| 65 if not os.path.exists(win_toolchain_json_file): |
| 66 raise Exception('The toolchain JSON file (%s) is missing.' % |
| 67 win_toolchain_json_file) |
| 68 with open(win_toolchain_json_file) as temp_f: |
| 69 toolchain_data = json.load(temp_f) |
| 70 if not os.path.isdir(toolchain_data['path']): |
| 71 raise Exception('The toolchain JSON file\'s "path" entry (%s) does not ' |
| 72 'refer to a path.' % win_toolchain_json_file) |
| 73 |
| 74 pgo_sweep_dir = os.path.join(toolchain_data['path'], 'VC', 'bin') |
| 75 if target_cpu == 'x64': |
| 76 pgo_sweep_dir = os.path.join(pgo_sweep_dir, 'amd64') |
| 77 |
| 78 if not os.path.exists(os.path.join(pgo_sweep_dir, 'pgosweep.exe')): |
| 79 raise Exception('pgosweep.exe is missing from %s.' % pgo_sweep_dir) |
| 80 |
| 81 return pgo_sweep_dir |
| 82 |
| 83 |
| 84 def RunBenchmarks(options): |
| 85 """Run the benchmarks.""" |
| 86 # Starts by finding the directory containing pgosweep.exe |
| 87 pgo_sweep_dir = FindPgosweep(options.target_cpu) |
| 88 |
| 89 # Find the run_benchmark script. |
| 90 chrome_run_benchmark_script = os.path.join(_CHROME_SRC_DIR, 'tools', |
| 91 'perf', 'run_benchmark') |
| 92 if not os.path.exists(chrome_run_benchmark_script): |
| 93 raise Exception('Unable to find the run_benchmark script ' |
| 94 '(%s doesn\'t exist) ' % chrome_run_benchmark_script) |
| 95 |
| 96 # Augment the PATH to make sure that the benchmarking script can find |
| 97 # pgosweep.exe and its runtime libraries. |
| 98 env = os.environ.copy() |
| 99 env['PATH'] = str(os.pathsep.join([pgo_sweep_dir, options.build_dir, |
| 100 os.environ['PATH']])) |
| 101 env['PogoSafeMode'] = '1' |
| 102 # Apply a scaling factor of 0.5 to the PGO profiling buffers for the 32-bit |
| 103 # builds, without this the buffers will be too large and the process will |
| 104 # fail to start. See crbug.com/632864#c22. |
| 105 if options.target_cpu == 'x86': |
| 106 env['VCPROFILE_ALLOC_SCALE'] = '0.5' |
| 107 |
| 108 # Run all the benchmarks. |
| 109 # TODO(sebmarchand): Make this run in parallel. |
| 110 for benchmark in _BENCHMARKS_TO_RUN: |
| 111 try: |
| 112 benchmark_command = [ |
| 113 sys.executable, |
| 114 chrome_run_benchmark_script, |
| 115 '--browser', options.browser_type, |
| 116 ] |
| 117 # Automatically set the arguments to run this script on a local build. |
| 118 if options.browser_type == 'exact': |
| 119 benchmark_command += [ |
| 120 '--browser-executable', os.path.join(options.build_dir, 'chrome.exe') |
| 121 ] |
| 122 benchmark_command += [ |
| 123 '--profiler', 'win_pgo_profiler', |
| 124 benchmark |
| 125 ] |
| 126 subprocess.check_call(benchmark_command, env=env) |
| 127 except: |
| 128 print ('Error while trying to run the %s benchmark, continuing.' % |
| 129 benchmark) |
| 130 continue |
| 131 |
| 132 return 0 |
| 133 |
| 134 |
| 135 def main(): |
| 136 parser = optparse.OptionParser(usage='%prog [options]') |
| 137 parser.add_option( |
| 138 '--browser-type', help='The browser type (to be passed to Telemetry\'s ' |
| 139 'benchmark runner).') |
| 140 # TODO(sebmarchand): Parse the args.gn file to automatically set this value. |
| 141 parser.add_option('--target-cpu', help='The target\'s bitness.') |
| 142 parser.add_option('--build-dir', help='Chrome build directory.') |
| 143 options, _ = parser.parse_args() |
| 144 |
| 145 if not options.target_cpu: |
| 146 parser.error('--target-cpu is required') |
| 147 if not options.build_dir: |
| 148 parser.error('--build-dir is required') |
| 149 if not options.browser_type: |
| 150 options.browser_type = 'exact' |
| 151 |
| 152 return RunBenchmarks(options) |
| 153 |
| 154 |
| 155 if __name__ == '__main__': |
| 156 sys.exit(main()) |
OLD | NEW |