21 import multiprocessing
29 os.path.join(os.path.dirname(sys.argv[0]),
'..',
'..',
'run_tests',
33 argp = argparse.ArgumentParser(description=
'Perform diff on microbenchmarks')
35 argp.add_argument(
'-d',
38 help=
'Commit or branch to compare the current one to')
40 argp.add_argument(
'-j',
'--jobs', type=int, default=multiprocessing.cpu_count())
42 args = argp.parse_args()
52 """Perform the cmake build under the output_dir."""
53 shutil.rmtree(output_dir, ignore_errors=
True)
54 subprocess.check_call(
'mkdir -p %s' % output_dir, shell=
True, cwd=
'.')
55 subprocess.check_call([
56 'cmake',
'-DgRPC_BUILD_TESTS=OFF',
'-DBUILD_SHARED_LIBS=ON',
57 '-DCMAKE_BUILD_TYPE=RelWithDebInfo',
'-DCMAKE_C_FLAGS="-gsplit-dwarf"',
58 '-DCMAKE_CXX_FLAGS="-gsplit-dwarf"',
'..'
61 subprocess.check_call(
'make -j%d' % args.jobs, shell=
True, cwd=output_dir)
65 """Determine how significant diff_bytes is, and return a simple integer representing that"""
69 diff_bytes = -diff_bytes
70 if diff_bytes < 2 * 1024:
72 if diff_bytes < 16 * 1024:
74 if diff_bytes < 128 * 1024:
82 where_am_i = subprocess.check_output(
83 [
'git',
'rev-parse',
'--abbrev-ref',
'HEAD']).
decode().strip()
85 subprocess.check_call([
'git',
'checkout', args.diff_base])
86 subprocess.check_call([
'git',
'submodule',
'update'])
91 subprocess.check_call([
'git',
'checkout', where_am_i])
92 subprocess.check_call([
'git',
'submodule',
'update'])
94 pathlib.Path(
'bloaty-build').mkdir(exist_ok=
True)
95 subprocess.check_call(
96 [
'cmake',
'-G',
'Unix Makefiles',
'../third_party/bloaty'],
98 subprocess.check_call(
'make -j%d' % args.jobs, shell=
True, cwd=
'bloaty-build')
103 text +=
'****************************************************************\n\n'
105 old_version = glob.glob(
'bloat_diff_old/%s' % lib)
106 new_version = glob.glob(
'bloat_diff_new/%s' % lib)
107 for filename
in [old_version, new_version]:
109 subprocess.check_call(
'strip %s -o %s.stripped' %
110 (filename[0], filename[0]),
112 assert len(new_version) == 1
113 cmd =
'bloaty-build/bloaty -d compileunits,symbols'
115 assert len(old_version) == 1
116 text += subprocess.check_output(
117 '%s -n 0 --debug-file=%s --debug-file=%s %s.stripped -- %s.stripped'
118 % (cmd, new_version[0], old_version[0], new_version[0],
122 x
for x
in csv.reader(
123 subprocess.check_output(
124 'bloaty-build/bloaty -n 0 --csv %s -- %s' %
125 (new_version[0], old_version[0]),
126 shell=
True).
decode().splitlines())
129 for section
in sections[1:]:
131 if section[0].startswith(
".debug"):
134 if section[0].startswith(
".dyn"):
136 diff_size +=
int(section[2])
138 text += subprocess.check_output(
'%s %s.stripped -n 0 --debug-file=%s' %
139 (cmd, new_version[0], new_version[0]),
144 print(
"SEVERITY: %d" % severity)
147 check_on_pr.check_on_pr(
'Bloat Difference',
'```\n%s\n```' % text)
148 check_on_pr.label_significance_on_pr(
'bloat', severity)