16 """ Python utility to build opt and counters benchmarks """
19 import multiprocessing
28 argp = argparse.ArgumentParser(description=
'Builds microbenchmarks')
29 argp.add_argument(
'-b',
32 choices=bm_constants._AVAILABLE_BENCHMARK_TESTS,
33 default=bm_constants._AVAILABLE_BENCHMARK_TESTS,
34 help=
'Which benchmarks to build')
39 default=multiprocessing.cpu_count(),
41 'Deprecated. Bazel chooses number of CPUs to build with automatically.')
47 'Unique name of this build. To be used as a handle to pass to the other bm* scripts'
49 argp.add_argument(
'--counters', dest=
'counters', action=
'store_true')
50 argp.add_argument(
'--no-counters', dest=
'counters', action=
'store_false')
51 argp.set_defaults(counters=
True)
52 args = argp.parse_args()
59 '//test/cpp/microbenchmarks:%s' % benchmark
for benchmark
in benchmarks
63 return [
'tools/bazel',
'build',
64 '--config=%s' % cfg,
'--dynamic_mode=off'] + bazel_targets
68 """Build given config and copy resulting binaries to dest_dir/CONFIG"""
69 subprocess.check_call(
_build_cmd(cfg, benchmarks))
70 cfg_dir = dest_dir +
'/%s' % cfg
72 subprocess.check_call([
'cp'] + [
73 'bazel-bin/test/cpp/microbenchmarks/%s' % benchmark
74 for benchmark
in benchmarks
78 def build(name, benchmarks, jobs, counters):
79 dest_dir =
'bm_diff_%s' % name
80 shutil.rmtree(dest_dir, ignore_errors=
True)
86 if __name__ ==
'__main__':
88 build(args.name, args.benchmarks, args.jobs, args.counters)