• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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
41LIBS = [
42    'libgrpc.so',
43    'libgrpc++.so',
44]
45
46
47def build(where):
48    subprocess.check_call('make -j%d' % args.jobs, shell=True, cwd='.')
49    shutil.rmtree('bloat_diff_%s' % where, ignore_errors=True)
50    os.rename('libs', 'bloat_diff_%s' % where)
51
52
53build('new')
54
55if args.diff_base:
56    old = 'old'
57    where_am_i = subprocess.check_output(
58        ['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
59    subprocess.check_call(['git', 'checkout', args.diff_base])
60    subprocess.check_call(['git', 'submodule', 'update'])
61    try:
62        try:
63            build('old')
64        except subprocess.CalledProcessError, e:
65            subprocess.check_call(['make', 'clean'])
66            build('old')
67    finally:
68        subprocess.check_call(['git', 'checkout', where_am_i])
69        subprocess.check_call(['git', 'submodule', 'update'])
70
71subprocess.check_call('make -j%d' % args.jobs,
72                      shell=True,
73                      cwd='third_party/bloaty')
74
75text = ''
76for lib in LIBS:
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('%s %s -- %s' %
86                                        (cmd, new_version[0], old_version[0]),
87                                        shell=True)
88    else:
89        text += subprocess.check_output('%s %s' % (cmd, new_version[0]),
90                                        shell=True)
91    text += '\n\n'
92
93print text
94check_on_pr.check_on_pr('Bloat Difference', '```\n%s\n```' % text)
95