1#!/usr/bin/env python3 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( 26 os.path.join(os.path.dirname(sys.argv[0]), '..', '..', 'run_tests', 27 'python_utils')) 28import check_on_pr 29 30argp = argparse.ArgumentParser(description='Perform diff on microbenchmarks') 31 32argp.add_argument('-d', 33 '--diff_base', 34 type=str, 35 help='Commit or branch to compare the current one to') 36 37argp.add_argument('-j', '--jobs', type=int, default=multiprocessing.cpu_count()) 38 39args = argp.parse_args() 40 41# the libraries for which check bloat difference is calculated 42LIBS = [ 43 'libgrpc.so', 44 'libgrpc++.so', 45] 46 47 48def _build(output_dir): 49 """Perform the cmake build under the output_dir.""" 50 shutil.rmtree(output_dir, ignore_errors=True) 51 subprocess.check_call('mkdir -p %s' % output_dir, shell=True, cwd='.') 52 subprocess.check_call( 53 'cmake -DgRPC_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..', 54 shell=True, 55 cwd=output_dir) 56 subprocess.check_call('make -j%d' % args.jobs, shell=True, cwd=output_dir) 57 58 59_build('bloat_diff_new') 60 61if args.diff_base: 62 where_am_i = subprocess.check_output( 63 ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip() 64 # checkout the diff base (="old") 65 subprocess.check_call(['git', 'checkout', args.diff_base]) 66 subprocess.check_call(['git', 'submodule', 'update']) 67 try: 68 _build('bloat_diff_old') 69 finally: 70 # restore the original revision (="new") 71 subprocess.check_call(['git', 'checkout', where_am_i]) 72 subprocess.check_call(['git', 'submodule', 'update']) 73 74subprocess.check_call('make -j%d' % args.jobs, 75 shell=True, 76 cwd='third_party/bloaty') 77 78text = '' 79for lib in LIBS: 80 text += '****************************************************************\n\n' 81 text += lib + '\n\n' 82 old_version = glob.glob('bloat_diff_old/%s' % lib) 83 new_version = glob.glob('bloat_diff_new/%s' % lib) 84 assert len(new_version) == 1 85 cmd = 'third_party/bloaty/bloaty -d compileunits,symbols' 86 if old_version: 87 assert len(old_version) == 1 88 text += subprocess.check_output('%s %s -- %s' % 89 (cmd, new_version[0], old_version[0]), 90 shell=True).decode() 91 else: 92 text += subprocess.check_output('%s %s' % (cmd, new_version[0]), 93 shell=True).decode() 94 text += '\n\n' 95 96print(text) 97check_on_pr.check_on_pr('Bloat Difference', '```\n%s\n```' % text) 98