Skip to content

Commit 89634da

Browse files
authored
[NFC] yapf auto reformatting (#55)
1 parent e2c1320 commit 89634da

10 files changed

+192
-204
lines changed

compiler_opt/benchmark/benchmark_chromium.py

Lines changed: 60 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,16 @@
5959
FLAGS = flags.FLAGS
6060

6161
default_test_descriptions = [
62-
'./compiler_opt/tools/chromium_test_descriptions/base_perftests.json',
63-
'./compiler_opt/tools/chromium_test_descriptions/browser_tests.json',
64-
'./compiler_opt/tools/chromium_test_descriptions/components_perftests.json'
62+
'./compiler_opt/tools/chromium_test_descriptions/base_perftests.json',
63+
'./compiler_opt/tools/chromium_test_descriptions/browser_tests.json',
64+
'./compiler_opt/tools/chromium_test_descriptions/components_perftests.json'
6565
]
6666

67-
flags.DEFINE_multi_string('test_description', default_test_descriptions,
68-
'(Can be defined multiple times) A path to a test'
69-
'description JSON file containing the test executable'
70-
'and the tests to run')
67+
flags.DEFINE_multi_string(
68+
'test_description', default_test_descriptions,
69+
'(Can be defined multiple times) A path to a test'
70+
'description JSON file containing the test executable'
71+
'and the tests to run')
7172
flags.DEFINE_boolean('compile_tests', True,
7273
'Whether or not to compile the tests from scratch')
7374
flags.DEFINE_enum('advisor', None, ['release', 'default'],
@@ -80,34 +81,35 @@
8081
'The path to your llvm build')
8182
flags.DEFINE_boolean('compile_llvm', True,
8283
'whether or not to compile llvm using the new model')
83-
flags.DEFINE_boolean('llvm_use_incremental', True,
84-
'whether or not to use an incremental build while'
85-
'compiling llvm')
84+
flags.DEFINE_boolean(
85+
'llvm_use_incremental', True,
86+
'whether or not to use an incremental build while'
87+
'compiling llvm')
8688
flags.DEFINE_string('llvm_source_path', '/llvm-project',
8789
'The root path of your local llvm-project checkout')
8890
flags.DEFINE_string('model_path', '',
8991
'The path to the model to use when compiling llvm')
90-
flags.DEFINE_string('tensorflow_c_lib_path', '/tmp/tensorflow',
91-
'The path to an extracted copy of the tensorflow c library')
92-
flags.DEFINE_string('chromium_build_path', './out/Release',
93-
'The chromium build path, relative to the chromium source'
94-
'directory')
92+
flags.DEFINE_string(
93+
'tensorflow_c_lib_path', '/tmp/tensorflow',
94+
'The path to an extracted copy of the tensorflow c library')
95+
flags.DEFINE_string(
96+
'chromium_build_path', './out/Release',
97+
'The chromium build path, relative to the chromium source'
98+
'directory')
9599
flags.DEFINE_string('output_file', 'output.json',
96100
'The path to the output file (in JSON format)')
97-
flags.DEFINE_integer('num_threads', 1,
98-
'The number of threads to use when running benchmarks.'
99-
'Should be used with caution')
100-
flags.DEFINE_multi_string('perf_counters',
101-
['mem_uops_retired.all_loads',
102-
'mem_uops_retired.all_stores'],
103-
'The performance counters to use')
104-
105-
def build_chromium_tests(regalloc_advisor: str,
106-
chromium_build_path: str,
107-
chromium_source_path: str,
108-
depot_tools_path: str,
109-
llvm_build_path: str,
110-
tests_to_build: List[str]):
101+
flags.DEFINE_integer(
102+
'num_threads', 1, 'The number of threads to use when running benchmarks.'
103+
'Should be used with caution')
104+
flags.DEFINE_multi_string(
105+
'perf_counters',
106+
['mem_uops_retired.all_loads', 'mem_uops_retired.all_stores'],
107+
'The performance counters to use')
108+
109+
110+
def build_chromium_tests(regalloc_advisor: str, chromium_build_path: str,
111+
chromium_source_path: str, depot_tools_path: str,
112+
llvm_build_path: str, tests_to_build: List[str]):
111113
"""Builds the chromium test suite
112114
113115
This function will build the specified chromium tests using the specified
@@ -139,16 +141,11 @@ def build_chromium_tests(regalloc_advisor: str,
139141
f'-mllvm -regalloc-enable-advisor={regalloc_advisor}'
140142

141143
gn_args = [
142-
'is_official_build=true',
143-
'use_thin_lto=false',
144-
'is_cfi=false',
145-
'use_cfi_icall=false',
146-
'use_cfi_cast=false',
147-
'clang_use_chrome_plugins=false',
148-
'is_debug=false',
149-
'symbol_level=0',
150-
'custom_toolchain=\\\"//build/toolchain/linux/unbundle:default\\\"',
151-
'host_toolchain=\\\"//build/toolchain/linux/unbundle:default\\\"'
144+
'is_official_build=true', 'use_thin_lto=false', 'is_cfi=false',
145+
'use_cfi_icall=false', 'use_cfi_cast=false',
146+
'clang_use_chrome_plugins=false', 'is_debug=false', 'symbol_level=0',
147+
'custom_toolchain=\\\"//build/toolchain/linux/unbundle:default\\\"',
148+
'host_toolchain=\\\"//build/toolchain/linux/unbundle:default\\\"'
152149
]
153150

154151
gn_args_string = '--args="'
@@ -157,22 +154,23 @@ def build_chromium_tests(regalloc_advisor: str,
157154
gn_args_string += '"'
158155

159156
gn_config_command = 'gn gen ' + chromium_build_path + ' ' + gn_args_string
160-
with subprocess.Popen(gn_config_command,
161-
env=new_environment,
162-
cwd=chromium_source_path,
163-
shell=True) as gn_config_process:
157+
with subprocess.Popen(
158+
gn_config_command,
159+
env=new_environment,
160+
cwd=chromium_source_path,
161+
shell=True) as gn_config_process:
164162
gn_config_process.wait()
165163

166164
ninja_compile_command = ['autoninja', '-C', chromium_build_path]
167165
ninja_compile_command.extend(tests_to_build)
168-
with subprocess.Popen(ninja_compile_command,
169-
env=new_environment,
170-
cwd=chromium_source_path) as ninja_compile_process:
166+
with subprocess.Popen(
167+
ninja_compile_command, env=new_environment,
168+
cwd=chromium_source_path) as ninja_compile_process:
171169
ninja_compile_process.wait()
172170

173-
def run_tests(tests_to_run: List[Dict[str,Union[str, List[str]]]],
174-
chromium_absolute_build_path: str,
175-
num_threads: int,
171+
172+
def run_tests(tests_to_run: List[Dict[str, Union[str, List[str]]]],
173+
chromium_absolute_build_path: str, num_threads: int,
176174
perf_counters: List[str]):
177175
"""A utility to run a set of chromium tests
178176
@@ -194,12 +192,12 @@ def run_tests(tests_to_run: List[Dict[str,Union[str, List[str]]]],
194192
for test in tests_to_run:
195193
executable_path = os.path.join(chromium_absolute_build_path,
196194
test['executable'])
197-
test_data.extend(gtest_executable_utils.run_test_suite(test,
198-
executable_path,
199-
perf_counters,
200-
num_threads))
195+
test_data.extend(
196+
gtest_executable_utils.run_test_suite(test, executable_path,
197+
perf_counters, num_threads))
201198
return test_data
202199

200+
203201
def main(_):
204202
test_descriptions = []
205203
for test_description in FLAGS.test_description:
@@ -211,32 +209,24 @@ def main(_):
211209
test_executables.append(test_description['executable'])
212210

213211
if FLAGS.compile_llvm:
214-
benchmarking_utils.build_llvm(FLAGS.model_path,
215-
FLAGS.llvm_use_incremental,
216-
FLAGS.llvm_build_path,
217-
FLAGS.llvm_source_path,
212+
benchmarking_utils.build_llvm(FLAGS.model_path, FLAGS.llvm_use_incremental,
213+
FLAGS.llvm_build_path, FLAGS.llvm_source_path,
218214
FLAGS.tensorflow_c_lib_path)
219215

220216
if FLAGS.compile_tests:
221-
build_chromium_tests(FLAGS.advisor,
222-
FLAGS.chromium_build_path,
223-
FLAGS.chromium_src_path,
224-
FLAGS.depot_tools_path,
225-
FLAGS.llvm_build_path,
226-
test_executables)
217+
build_chromium_tests(FLAGS.advisor, FLAGS.chromium_build_path,
218+
FLAGS.chromium_src_path, FLAGS.depot_tools_path,
219+
FLAGS.llvm_build_path, test_executables)
227220

228221
chromium_absolute_build_path = os.path.join(FLAGS.chromium_src_path,
229222
FLAGS.chromium_build_path)
230-
test_data = run_tests(test_descriptions,
231-
chromium_absolute_build_path,
232-
FLAGS.num_threads,
233-
FLAGS.perf_counters)
223+
test_data = run_tests(test_descriptions, chromium_absolute_build_path,
224+
FLAGS.num_threads, FLAGS.perf_counters)
234225

235226
with open(FLAGS.output_file, 'w', encoding='UTF-8') as output_file:
236-
output_data = {
237-
'benchmarks': test_data
238-
}
227+
output_data = {'benchmarks': test_data}
239228
output_file.write(json.dumps(output_data, indent=4))
240229

230+
241231
if __name__ == '__main__':
242232
app.run(main)

0 commit comments

Comments
 (0)