21 import multiprocessing
30 os.path.join(os.path.dirname(sys.argv[0]),
'..',
'..',
'run_tests',
34 argp = argparse.ArgumentParser(description=
'Perform diff on memory benchmarks')
36 argp.add_argument(
'-d',
39 help=
'Commit or branch to compare the current one to')
41 argp.add_argument(
'-j',
'--jobs', type=int, default=multiprocessing.cpu_count())
43 args = argp.parse_args()
47 (rb
'client call memory usage: ([0-9\.]+) bytes per call', float),
49 (rb
'server call memory usage: ([0-9\.]+) bytes per call', float),
54 'minstack': [
'--minstack'],
59 """Build with Bazel, then run, and extract interesting lines from the output."""
60 subprocess.check_call([
61 'tools/bazel',
'build',
'-c',
'opt',
62 'test/core/memory_usage/memory_usage_test'
65 for scenario, extra_args
in _SCENARIOS.items():
67 output = subprocess.check_output([
68 'bazel-bin/test/core/memory_usage/memory_usage_test',
72 except subprocess.CalledProcessError
as e:
73 print(
'Error running benchmark:', e)
75 for line
in output.splitlines():
76 for key, (pattern, conversion)
in _INTERESTING.items():
77 m = re.match(pattern, line)
79 ret[scenario +
': ' + key] = conversion(m.group(1))
87 where_am_i = subprocess.check_output(
88 [
'git',
'rev-parse',
'--abbrev-ref',
'HEAD']).
decode().strip()
90 subprocess.check_call([
'git',
'checkout', args.diff_base])
95 subprocess.check_call([
'git',
'checkout', where_am_i])
100 for key, value
in sorted(cur.items()):
101 text +=
'{}: {}\n'.
format(key, value)
105 for scenario
in _SCENARIOS.keys():
106 for key, value
in sorted(_INTERESTING.items()):
107 key = scenario +
': ' + key
110 text +=
'{}: {}\n'.
format(key, cur[key])
112 diff_size += cur[key] - old[key]
113 text +=
'{}: {} -> {}\n'.
format(key, old[key], cur[key])
115 print(
"DIFF_SIZE: %f" % diff_size)
116 check_on_pr.label_increase_decrease_on_pr(
'per-call-memory', diff_size, 64)
119 check_on_pr.check_on_pr(
'Memory Difference',
'```\n%s\n```' % text)