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 "path" entry (%s) does not ' | |
scottmg
2016/09/27 18:04:08
You changed the wrong exception here.
Sébastien Marchand
2016/09/27 18:14:10
/facepalm/
| |
67 'refer to a path.' % 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 is invalid.') | |
72 | |
73 pgo_sweep_dir = os.path.join(toolchain_data['path'], 'VC', 'bin') | |
74 if target_cpu == 'x64': | |
75 pgo_sweep_dir = os.path.join(pgo_sweep_dir, 'amd64') | |
76 | |
77 if not os.path.exists(os.path.join(pgo_sweep_dir, 'pgosweep.exe')): | |
78 raise Exception('pgosweep.exe is missing from %s.' % pgo_sweep_dir) | |
79 | |
80 return pgo_sweep_dir | |
81 | |
82 | |
83 def RunBenchmarks(options): | |
84 """Run the benchmarks.""" | |
85 # Starts by finding the directory containing pgosweep.exe | |
86 pgo_sweep_dir = FindPgosweep(options.target_cpu) | |
87 | |
88 # Find the run_benchmark script. | |
89 chrome_run_benchmark_script = os.path.join(_CHROME_SRC_DIR, 'tools', | |
90 'perf', 'run_benchmark') | |
91 if not os.path.exists(chrome_run_benchmark_script): | |
92 raise Exception('Unable to find the run_benchmark script ' | |
93 '(%s doesn\'t exist) ' % chrome_run_benchmark_script) | |
94 | |
95 # Augment the PATH to make sure that the benchmarking script can find | |
96 # pgosweep.exe and its runtime libraries. | |
97 env = os.environ.copy() | |
98 env['PATH'] = str(os.pathsep.join([pgo_sweep_dir, options.build_dir, | |
99 os.environ['PATH']])) | |
100 env['PogoSafeMode'] = '1' | |
101 # Apply a scaling factor of 0.5 to the PGO profiling buffers for the 32-bit | |
102 # builds, without this the buffers will be too large and the process will | |
103 # fail to start. See crbug.com/632864#c22. | |
104 if options.target_cpu == 'x86': | |
105 env['VCPROFILE_ALLOC_SCALE'] = '0.5' | |
106 | |
107 # Run all the benchmarks. | |
108 # TODO(sebmarchand): Make this run in parallel. | |
109 for benchmark in _BENCHMARKS_TO_RUN: | |
110 try: | |
111 benchmark_command = [ | |
112 sys.executable, | |
113 chrome_run_benchmark_script, | |
114 '--browser', options.browser_type, | |
115 ] | |
116 # Automatically set the arguments to run this script on a local build. | |
117 if options.browser_type == 'exact': | |
118 benchmark_command += [ | |
119 '--browser-executable', os.path.join(options.build_dir, 'chrome.exe') | |
120 ] | |
121 benchmark_command += [ | |
122 '--profiler', 'win_pgo_profiler', | |
123 benchmark | |
124 ] | |
125 subprocess.check_call(benchmark_command, env=env) | |
126 except: | |
127 print ('Error while trying to run the %s benchmark, continuing.' % | |
128 benchmark) | |
129 continue | |
130 | |
131 return 0 | |
132 | |
133 | |
134 def main(): | |
135 parser = optparse.OptionParser(usage='%prog [options]') | |
136 parser.add_option( | |
137 '--browser-type', help='The browser type (to be passed to Telemetry\'s ' | |
138 'benchmark runner).') | |
139 # TODO(sebmarchand): Parse the args.gn file to automatically set this value. | |
140 parser.add_option('--target-cpu', help='The target\'s bitness.') | |
141 parser.add_option('--build-dir', help='Chrome build directory.') | |
142 options, _ = parser.parse_args() | |
143 | |
144 if not options.target_cpu: | |
145 parser.error('--target-cpu is required') | |
146 if not options.build_dir: | |
147 parser.error('--build-dir is required') | |
148 if not options.browser_type: | |
149 options.browser_type = 'exact' | |
150 | |
151 return RunBenchmarks(options) | |
152 | |
153 | |
154 if __name__ == '__main__': | |
155 sys.exit(main()) | |
OLD | NEW |