19 import multiprocessing
25 from parse_link_map
import parse_link_map
28 os.path.join(os.path.dirname(sys.argv[0]),
'..',
'..',
'run_tests',
33 _DIFF_THRESHOLD = 1000
35 _SIZE_LABELS = (
'Core',
'ObjC',
'BoringSSL',
'Protobuf',
'Total')
37 argp = argparse.ArgumentParser(
38 description=
'Binary size diff of gRPC Objective-C sample')
40 argp.add_argument(
'-d',
43 help=
'Commit or branch to compare the current one to')
45 args = argp.parse_args()
50 for dirpath, dirnames, filenames
in os.walk(dir):
52 fp = os.path.join(dirpath, f)
53 total += os.stat(fp).st_size
58 build_dir =
'src/objective-c/examples/Sample/Build/Build-%s/' % where
60 link_map_filename =
'Build/Intermediates.noindex/Sample.build/Release-iphoneos/Sample.build/Sample-LinkMap-normal-arm64.txt'
64 framework_dir =
'Build/Products/Release-iphoneos/Sample.app/Frameworks/'
65 core_size =
dir_size(build_dir + framework_dir +
'grpc.framework')
66 objc_size =
dir_size(build_dir + framework_dir +
'GRPCClient.framework') + \
67 dir_size(build_dir + framework_dir +
'RxLibrary.framework') + \
68 dir_size(build_dir + framework_dir +
'ProtoRPC.framework')
69 boringssl_size =
dir_size(build_dir + framework_dir +
71 protobuf_size =
dir_size(build_dir + framework_dir +
75 'Build/Products/Release-iphoneos/Sample.app')
77 return core_size, objc_size, boringssl_size, protobuf_size, app_size
81 subprocess.check_call([
'make',
'clean'])
82 shutil.rmtree(
'src/objective-c/examples/Sample/Build/Build-%s' % where,
84 subprocess.check_call(
85 'CONFIG=opt EXAMPLE_PATH=src/objective-c/examples/Sample SCHEME=Sample FRAMEWORKS=%s ./build_one_example.sh'
86 % (
'YES' if frameworks
else 'NO'),
88 cwd=
'src/objective-c/tests')
89 os.rename(
'src/objective-c/examples/Sample/Build/Build',
90 'src/objective-c/examples/Sample/Build/Build-%s' % where)
94 """Render row in 3-column output format."""
103 return '{:>15}{:>15}{:>15}\n'.
format(formatted_new, label, formatted_old)
107 """Generate diff sign based on values"""
109 if diff_threshold
is not None and abs(new_size[i] -
110 old_size[i]) >= diff_threshold:
121 text =
'Objective-C binary sizes\n'
122 for frameworks
in [
False,
True]:
123 build(
'new', frameworks)
129 where_am_i = subprocess.check_output(
130 [
'git',
'rev-parse',
'--abbrev-ref',
'HEAD']).
decode().strip()
131 subprocess.check_call([
'git',
'checkout',
'--',
'.'])
132 subprocess.check_call([
'git',
'checkout', args.diff_base])
133 subprocess.check_call([
'git',
'submodule',
'update',
'--force'])
135 build(
'old', frameworks)
136 old_size =
get_size(
'old', frameworks)
138 subprocess.check_call([
'git',
'checkout',
'--',
'.'])
139 subprocess.check_call([
'git',
'checkout', where_am_i])
140 subprocess.check_call([
'git',
'submodule',
'update',
'--force'])
142 text += (
'********************FRAMEWORKS****************\n' if frameworks
143 else '**********************STATIC******************\n')
146 for i
in range(0,
len(_SIZE_LABELS)):
147 if i ==
len(_SIZE_LABELS) - 1:
150 text +=
_render_row(new_size[i], _SIZE_LABELS[i],
'')
154 for i
in range(0,
len(_SIZE_LABELS) - 1):
155 if abs(new_size[i] - old_size[i]) >= _DIFF_THRESHOLD:
159 diff_threshold=_DIFF_THRESHOLD)
160 text +=
_render_row(new_size[i], _SIZE_LABELS[i] + diff_sign,
165 diff_sign =
_diff_sign(new_size[i], old_size[i])
168 text +=
_render_row(new_size[i], _SIZE_LABELS[i] + diff_sign,
171 text +=
'\n No significant differences in binary sizes\n'
176 check_on_pr.check_on_pr(
'ObjC Binary Size',
'```\n%s\n```' % text)