blob: 91611c2ca4aaced5c4e2e052af30f78e9c931fa3 [file] [log] [blame]
Craig Tillere3dbf762017-10-04 14:01:28 -07001#!/usr/bin/env python2.7
2#
3# Copyright 2017 gRPC authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import argparse
18import glob
19import multiprocessing
20import os
21import shutil
22import subprocess
23import sys
24
25sys.path.append(
ncteisen173c4772017-12-11 16:52:44 -080026 os.path.join(
27 os.path.dirname(sys.argv[0]), '..', '..', 'run_tests', 'python_utils'))
Craig Tillere3dbf762017-10-04 14:01:28 -070028import comment_on_pr
29
ncteisen173c4772017-12-11 16:52:44 -080030argp = argparse.ArgumentParser(description='Perform diff on microbenchmarks')
Craig Tillere3dbf762017-10-04 14:01:28 -070031
32argp.add_argument(
33 '-d',
34 '--diff_base',
35 type=str,
36 help='Commit or branch to compare the current one to')
37
ncteisen173c4772017-12-11 16:52:44 -080038argp.add_argument('-j', '--jobs', type=int, default=multiprocessing.cpu_count())
Craig Tillere3dbf762017-10-04 14:01:28 -070039
40args = argp.parse_args()
41
42LIBS = [
ncteisen173c4772017-12-11 16:52:44 -080043 'libgrpc.so',
44 'libgrpc++.so',
Craig Tillere3dbf762017-10-04 14:01:28 -070045]
46
ncteisen173c4772017-12-11 16:52:44 -080047
Craig Tillere3dbf762017-10-04 14:01:28 -070048def build(where):
ncteisen173c4772017-12-11 16:52:44 -080049 subprocess.check_call('make -j%d' % args.jobs, shell=True, cwd='.')
50 shutil.rmtree('bloat_diff_%s' % where, ignore_errors=True)
51 os.rename('libs', 'bloat_diff_%s' % where)
52
Craig Tillere3dbf762017-10-04 14:01:28 -070053
54build('new')
55
56if args.diff_base:
57 old = 'old'
58 where_am_i = subprocess.check_output(
ncteisen173c4772017-12-11 16:52:44 -080059 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
Craig Tillere3dbf762017-10-04 14:01:28 -070060 subprocess.check_call(['git', 'checkout', args.diff_base])
61 subprocess.check_call(['git', 'submodule', 'update'])
62 try:
ncteisen173c4772017-12-11 16:52:44 -080063 try:
64 build('old')
65 except subprocess.CalledProcessError, e:
66 subprocess.check_call(['make', 'clean'])
67 build('old')
Craig Tillere3dbf762017-10-04 14:01:28 -070068 finally:
ncteisen173c4772017-12-11 16:52:44 -080069 subprocess.check_call(['git', 'checkout', where_am_i])
70 subprocess.check_call(['git', 'submodule', 'update'])
Craig Tillere3dbf762017-10-04 14:01:28 -070071
ncteisen173c4772017-12-11 16:52:44 -080072subprocess.check_call(
73 'make -j%d' % args.jobs, shell=True, cwd='third_party/bloaty')
Craig Tillere3dbf762017-10-04 14:01:28 -070074
75text = ''
76for lib in LIBS:
ncteisen173c4772017-12-11 16:52:44 -080077 text += '****************************************************************\n\n'
78 text += lib + '\n\n'
79 old_version = glob.glob('bloat_diff_old/opt/%s' % lib)
80 new_version = glob.glob('bloat_diff_new/opt/%s' % lib)
81 assert len(new_version) == 1
82 cmd = 'third_party/bloaty/bloaty -d compileunits,symbols'
83 if old_version:
84 assert len(old_version) == 1
85 text += subprocess.check_output(
86 '%s %s -- %s' % (cmd, new_version[0], old_version[0]), shell=True)
87 else:
88 text += subprocess.check_output(
89 '%s %s' % (cmd, new_version[0]), shell=True)
90 text += '\n\n'
Craig Tillere3dbf762017-10-04 14:01:28 -070091
92print text
93comment_on_pr.comment_on_pr('```\n%s\n```' % text)