Skip to content

Commit 59ed9d0

Browse files
authored
Reland bloat labelling code. (grpc#27926)
* Revert "Revert "Assign a label for level of bloat diff (grpc#27880)" (grpc#27925)" This reverts commit f2b9600. * fix
1 parent d92baa9 commit 59ed9d0

File tree

4 files changed

+77
-6
lines changed

4 files changed

+77
-6
lines changed

third_party/bloaty

Submodule bloaty updated 230 files

tools/profiling/bloat/bloat_diff.py

+28-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
# limitations under the License.
1616

1717
import argparse
18+
import csv
1819
import glob
20+
import math
1921
import multiprocessing
2022
import os
23+
import pathlib
2124
import shutil
2225
import subprocess
2326
import sys
@@ -71,27 +74,48 @@ def _build(output_dir):
7174
subprocess.check_call(['git', 'checkout', where_am_i])
7275
subprocess.check_call(['git', 'submodule', 'update'])
7376

74-
subprocess.check_call('make -j%d' % args.jobs,
75-
shell=True,
76-
cwd='third_party/bloaty')
77+
pathlib.Path('bloaty-build').mkdir(exist_ok=True)
78+
subprocess.check_call(
79+
['cmake', '-G', 'Unix Makefiles', '../third_party/bloaty'],
80+
cwd='bloaty-build')
81+
subprocess.check_call('make -j%d' % args.jobs, shell=True, cwd='bloaty-build')
7782

7883
text = ''
84+
diff_size = 0
7985
for lib in LIBS:
8086
text += '****************************************************************\n\n'
8187
text += lib + '\n\n'
8288
old_version = glob.glob('bloat_diff_old/%s' % lib)
8389
new_version = glob.glob('bloat_diff_new/%s' % lib)
8490
assert len(new_version) == 1
85-
cmd = 'third_party/bloaty/bloaty -d compileunits,symbols'
91+
cmd = 'bloaty-build/bloaty -d compileunits,symbols'
8692
if old_version:
8793
assert len(old_version) == 1
8894
text += subprocess.check_output('%s %s -- %s' %
8995
(cmd, new_version[0], old_version[0]),
9096
shell=True).decode()
97+
for filename in [old_version, new_version]:
98+
subprocess.check_call('strip %s' % filename[0], shell=True)
99+
sections = [
100+
x for x in csv.reader(
101+
subprocess.check_output('bloaty-build/bloaty --csv %s -- %s' %
102+
(old_version[0], new_version[0]),
103+
shell=True).decode().splitlines())
104+
]
105+
print(sections)
106+
for section in sections[1:]:
107+
diff_size += int(section[2])
91108
else:
92109
text += subprocess.check_output('%s %s' % (cmd, new_version[0]),
93110
shell=True).decode()
94111
text += '\n\n'
95112

113+
severity = int(
114+
math.copysign(max(0, math.log(abs(diff_size) / 1000, 10),
115+
diff_size))) if diff_size != 0 else 0
116+
117+
print("SEVERITY: %d" % severity)
118+
96119
print(text)
97120
check_on_pr.check_on_pr('Bloat Difference', '```\n%s\n```' % text)
121+
check_on_pr.label_significance_on_pr('bloat', severity)

tools/run_tests/python_utils/check_on_pr.py

+47
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@
3333
_ACCESS_TOKEN_FETCH_RETRIES = 6
3434
_ACCESS_TOKEN_FETCH_RETRIES_INTERVAL_S = 15
3535

36+
_CHANGE_LABELS = {
37+
-1: 'improvement',
38+
0: 'none',
39+
1: 'low',
40+
2: 'medium',
41+
3: 'high',
42+
}
43+
3644

3745
def _jwt_token():
3846
github_app_key = open(
@@ -139,3 +147,42 @@ def check_on_pr(name, summary, success=True):
139147
})
140148
print('Result of Creating/Updating Check on PR:',
141149
json.dumps(resp.json(), indent=2))
150+
151+
152+
def label_significance_on_pr(name, change):
153+
"""Add a label to the PR indicating the significance of the check.
154+
155+
Requires environment variable 'KOKORO_GITHUB_PULL_REQUEST_NUMBER' to indicate which pull request
156+
should be updated.
157+
158+
Args:
159+
name: The name of the label.
160+
value: A str in Markdown to be used as the detail information of the label.
161+
"""
162+
if change < min(list(_CHANGE_LABELS.keys())):
163+
change = min(list(_CHANGE_LABELS.keys()))
164+
if change > max(list(_CHANGE_LABELS.keys())):
165+
change = max(list(_CHANGE_LABELS.keys()))
166+
value = _CHANGE_LABELS[change]
167+
if 'KOKORO_GIT_COMMIT' not in os.environ:
168+
print('Missing KOKORO_GIT_COMMIT env var: not checking')
169+
return
170+
if 'KOKORO_KEYSTORE_DIR' not in os.environ:
171+
print('Missing KOKORO_KEYSTORE_DIR env var: not checking')
172+
return
173+
if 'KOKORO_GITHUB_PULL_REQUEST_NUMBER' not in os.environ:
174+
print('Missing KOKORO_GITHUB_PULL_REQUEST_NUMBER env var: not checking')
175+
return
176+
existing = _call(
177+
'/repos/%s/issues/%s/labels' %
178+
(_GITHUB_REPO, os.environ['KOKORO_GITHUB_PULL_REQUEST_NUMBER']),
179+
method='GET').json()
180+
print('Result of Deleting Labels on PR:', existing)
181+
new = [x['name'] for x in existing if not x['name'].startswith(name + '/')]
182+
new.append(name + '/' + value)
183+
resp = _call(
184+
'/repos/%s/issues/%s/labels' %
185+
(_GITHUB_REPO, os.environ['KOKORO_GITHUB_PULL_REQUEST_NUMBER']),
186+
method='POST',
187+
json=new)
188+
print('Result of Adding Label on PR:', resp.text)

tools/run_tests/sanity/check_submodules.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ git submodule | awk '{ print $2 " " $1 }' | sort >"$submodules"
2727
cat <<EOF | sort >"$want_submodules"
2828
third_party/abseil-cpp 278e0a071885a22dcd2fd1b5576cc44757299343
2929
third_party/benchmark 0baacde3618ca617da95375e0af13ce1baadea47
30-
third_party/bloaty 73594cde8c9a52a102c4341c244c833aa61b9c06
30+
third_party/bloaty 60209eb1ccc34d5deefb002d1b7f37545204f7f2
3131
third_party/boringssl-with-bazel 95b3ed1b01f2ef1d72fed290ed79fe1b0e7dafc0
3232
third_party/cares/cares e982924acee7f7313b4baa4ee5ec000c5e373c30
3333
third_party/envoy-api 20b1b5fcee88a20a08b71051a961181839ec7268

0 commit comments

Comments
 (0)