Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 1 | #!/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 | |
| 17 | import argparse |
| 18 | import glob |
| 19 | import multiprocessing |
| 20 | import os |
| 21 | import shutil |
| 22 | import subprocess |
| 23 | import sys |
| 24 | |
| 25 | sys.path.append( |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 26 | os.path.join( |
| 27 | os.path.dirname(sys.argv[0]), '..', '..', 'run_tests', 'python_utils')) |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 28 | import comment_on_pr |
| 29 | |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 30 | argp = argparse.ArgumentParser(description='Perform diff on microbenchmarks') |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 31 | |
| 32 | argp.add_argument( |
| 33 | '-d', |
| 34 | '--diff_base', |
| 35 | type=str, |
| 36 | help='Commit or branch to compare the current one to') |
| 37 | |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 38 | argp.add_argument('-j', '--jobs', type=int, default=multiprocessing.cpu_count()) |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 39 | |
| 40 | args = argp.parse_args() |
| 41 | |
| 42 | LIBS = [ |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 43 | 'libgrpc.so', |
| 44 | 'libgrpc++.so', |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 45 | ] |
| 46 | |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 47 | |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 48 | def build(where): |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 49 | 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 Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 53 | |
| 54 | build('new') |
| 55 | |
| 56 | if args.diff_base: |
| 57 | old = 'old' |
| 58 | where_am_i = subprocess.check_output( |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 59 | ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip() |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 60 | subprocess.check_call(['git', 'checkout', args.diff_base]) |
| 61 | subprocess.check_call(['git', 'submodule', 'update']) |
| 62 | try: |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 63 | try: |
| 64 | build('old') |
| 65 | except subprocess.CalledProcessError, e: |
| 66 | subprocess.check_call(['make', 'clean']) |
| 67 | build('old') |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 68 | finally: |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 69 | subprocess.check_call(['git', 'checkout', where_am_i]) |
| 70 | subprocess.check_call(['git', 'submodule', 'update']) |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 71 | |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 72 | subprocess.check_call( |
| 73 | 'make -j%d' % args.jobs, shell=True, cwd='third_party/bloaty') |
Craig Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 74 | |
| 75 | text = '' |
| 76 | for lib in LIBS: |
ncteisen | 173c477 | 2017-12-11 16:52:44 -0800 | [diff] [blame] | 77 | 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 Tiller | e3dbf76 | 2017-10-04 14:01:28 -0700 | [diff] [blame] | 91 | |
| 92 | print text |
| 93 | comment_on_pr.comment_on_pr('```\n%s\n```' % text) |