Skip to content

Commit c33963d

Browse files
authored
iOS binary size script cleanup (grpc#29377)
* iOS binary size script cleanup * add job cfg for running iOS binary size on master
1 parent 5e989cf commit c33963d

File tree

3 files changed

+104
-35
lines changed

3 files changed

+104
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2022 The gRPC Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Config file for the internal CI (in protobuf text format)
16+
17+
# Location of the continuous shell script in repository.
18+
build_file: "grpc/tools/internal_ci/macos/grpc_ios_binary_size.sh"
19+
timeout_mins: 90
20+
before_action {
21+
fetch_keystore {
22+
keystore_resource {
23+
keystore_config_id: 73836
24+
keyname: "grpc_checks_private_key"
25+
}
26+
}
27+
}
28+
action {
29+
define_artifacts {
30+
regex: "**/*sponge_log.*"
31+
regex: "github/grpc/reports/**"
32+
}
33+
}

tools/internal_ci/macos/grpc_ios_binary_size.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,14 @@ cd $(dirname $0)/../../..
2727
export PREPARE_BUILD_INSTALL_DEPS_OBJC=true
2828
source tools/internal_ci/helper_scripts/prepare_build_macos_rc
2929

30+
if [ "${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}" != "" ]
31+
then
32+
# running on PR, generate size diff
33+
DIFF_BASE="origin/${KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH}"
34+
else
35+
# running as continous build, only generate numbers for the current revision
36+
DIFF_BASE=""
37+
fi
38+
3039
tools/profiling/ios_bin/binary_size.py \
31-
-d "origin/$KOKORO_GITHUB_PULL_REQUEST_TARGET_BRANCH"
40+
--diff_base="${DIFF_BASE}"

tools/profiling/ios_bin/binary_size.py

+61-34
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import check_on_pr
3131

3232
# Only show diff 1KB or greater
33-
diff_threshold = 1000
33+
_DIFF_THRESHOLD = 1000
3434

35-
size_labels = ('Core', 'ObjC', 'BoringSSL', 'Protobuf', 'Total')
35+
_SIZE_LABELS = ('Core', 'ObjC', 'BoringSSL', 'Protobuf', 'Total')
3636

3737
argp = argparse.ArgumentParser(
3838
description='Binary size diff of gRPC Objective-C sample')
@@ -58,19 +58,22 @@ def get_size(where, frameworks):
5858
build_dir = 'src/objective-c/examples/Sample/Build/Build-%s/' % where
5959
if not frameworks:
6060
link_map_filename = 'Build/Intermediates.noindex/Sample.build/Release-iphoneos/Sample.build/Sample-LinkMap-normal-arm64.txt'
61+
# IMPORTANT: order needs to match labels in _SIZE_LABELS
6162
return parse_link_map(build_dir + link_map_filename)
6263
else:
6364
framework_dir = 'Build/Products/Release-iphoneos/Sample.app/Frameworks/'
64-
boringssl_size = dir_size(build_dir + framework_dir +
65-
'openssl.framework')
6665
core_size = dir_size(build_dir + framework_dir + 'grpc.framework')
6766
objc_size = dir_size(build_dir + framework_dir + 'GRPCClient.framework') + \
6867
dir_size(build_dir + framework_dir + 'RxLibrary.framework') + \
6968
dir_size(build_dir + framework_dir + 'ProtoRPC.framework')
69+
boringssl_size = dir_size(build_dir + framework_dir +
70+
'openssl.framework')
7071
protobuf_size = dir_size(build_dir + framework_dir +
7172
'Protobuf.framework')
73+
# a.k.a. "Total"
7274
app_size = dir_size(build_dir +
7375
'Build/Products/Release-iphoneos/Sample.app')
76+
# IMPORTANT: order needs to match labels in _SIZE_LABELS
7477
return core_size, objc_size, boringssl_size, protobuf_size, app_size
7578

7679

@@ -87,6 +90,34 @@ def build(where, frameworks):
8790
'src/objective-c/examples/Sample/Build/Build-%s' % where)
8891

8992

93+
def _render_row(new, label, old):
94+
"""Render row in 3-column output format."""
95+
try:
96+
formatted_new = '{:,}'.format(int(new))
97+
except:
98+
formatted_new = new
99+
try:
100+
formatted_old = '{:,}'.format(int(old))
101+
except:
102+
formatted_old = old
103+
return '{:>15}{:>15}{:>15}\n'.format(formatted_new, label, formatted_old)
104+
105+
106+
def _diff_sign(new, old, diff_threshold=None):
107+
"""Generate diff sign based on values"""
108+
diff_sign = ' '
109+
if diff_threshold is not None and abs(new_size[i] -
110+
old_size[i]) >= diff_threshold:
111+
diff_sign += '!'
112+
if new > old:
113+
diff_sign += '(>)'
114+
elif new < old:
115+
diff_sign += '(<)'
116+
else:
117+
diff_sign += '(=)'
118+
return diff_sign
119+
120+
90121
text = 'Objective-C binary sizes\n'
91122
for frameworks in [False, True]:
92123
build('new', frameworks)
@@ -108,42 +139,38 @@ def build(where, frameworks):
108139
subprocess.check_call(['git', 'checkout', where_am_i])
109140
subprocess.check_call(['git', 'submodule', 'update', '--force'])
110141

111-
text += ('***************FRAMEWORKS****************\n'
112-
if frameworks else '*****************STATIC******************\n')
113-
row_format = "{:>10}{:>15}{:>15}" + '\n'
114-
text += row_format.format('New size', '', 'Old size')
142+
text += ('********************FRAMEWORKS****************\n' if frameworks
143+
else '**********************STATIC******************\n')
144+
text += _render_row('New size', '', 'Old size')
115145
if old_size == None:
116-
for i in range(0, len(size_labels)):
117-
text += ('\n' if i == len(size_labels) -
118-
1 else '') + row_format.format('{:,}'.format(new_size[i]),
119-
size_labels[i], '')
146+
for i in range(0, len(_SIZE_LABELS)):
147+
if i == len(_SIZE_LABELS) - 1:
148+
# skip line before rendering "Total"
149+
text += '\n'
150+
text += _render_row(new_size[i], _SIZE_LABELS[i], '')
120151
else:
121152
has_diff = False
122-
for i in range(0, len(size_labels) - 1):
123-
if abs(new_size[i] - old_size[i]) < diff_threshold:
124-
continue
125-
if new_size[i] > old_size[i]:
126-
diff_sign = ' (>)'
127-
else:
128-
diff_sign = ' (<)'
129-
has_diff = True
130-
text += row_format.format('{:,}'.format(new_size[i]),
131-
size_labels[i] + diff_sign,
132-
'{:,}'.format(old_size[i]))
133-
i = len(size_labels) - 1
134-
if new_size[i] > old_size[i]:
135-
diff_sign = ' (>)'
136-
elif new_size[i] < old_size[i]:
137-
diff_sign = ' (<)'
138-
else:
139-
diff_sign = ' (=)'
140-
text += ('\n' if has_diff else '') + row_format.format(
141-
'{:,}'.format(new_size[i]), size_labels[i] + diff_sign,
142-
'{:,}'.format(old_size[i]))
153+
# go through all labels but "Total"
154+
for i in range(0, len(_SIZE_LABELS) - 1):
155+
if abs(new_size[i] - old_size[i]) >= _DIFF_THRESHOLD:
156+
has_diff = True
157+
diff_sign = _diff_sign(new_size[i],
158+
old_size[i],
159+
diff_threshold=_DIFF_THRESHOLD)
160+
text += _render_row(new_size[i], _SIZE_LABELS[i] + diff_sign,
161+
old_size[i])
162+
163+
# render the "Total"
164+
i = len(_SIZE_LABELS) - 1
165+
diff_sign = _diff_sign(new_size[i], old_size[i])
166+
# skip line before rendering "Total"
167+
text += '\n'
168+
text += _render_row(new_size[i], _SIZE_LABELS[i] + diff_sign,
169+
old_size[i])
143170
if not has_diff:
144171
text += '\n No significant differences in binary sizes\n'
145172
text += '\n'
146173

147174
print(text)
148175

149-
check_on_pr.check_on_pr('Binary Size', '```\n%s\n```' % text)
176+
check_on_pr.check_on_pr('ObjC Binary Size', '```\n%s\n```' % text)

0 commit comments

Comments
 (0)