Back to home page

LXR

 
 

    


0001 #!/usr/bin/python
0002 #
0003 # Copyright 2004 Matt Mackall <mpm@selenic.com>
0004 #
0005 # inspired by perl Bloat-O-Meter (c) 1997 by Andi Kleen
0006 #
0007 # This software may be used and distributed according to the terms
0008 # of the GNU General Public License, incorporated herein by reference.
0009 
0010 import sys, os, re
0011 from signal import signal, SIGPIPE, SIG_DFL
0012 
0013 signal(SIGPIPE, SIG_DFL)
0014 
0015 if len(sys.argv) != 3:
0016     sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
0017     sys.exit(-1)
0018 
0019 re_NUMBER = re.compile(r'\.[0-9]+')
0020 
0021 def getsizes(file):
0022     sym = {}
0023     with os.popen("nm --size-sort " + file) as f:
0024         for line in f:
0025             size, type, name = line.split()
0026             if type in "tTdDbBrR":
0027                 # strip generated symbols
0028                 if name.startswith("__mod_"): continue
0029                 if name.startswith("SyS_"): continue
0030                 if name.startswith("compat_SyS_"): continue
0031                 if name == "linux_banner": continue
0032                 # statics and some other optimizations adds random .NUMBER
0033                 name = re_NUMBER.sub('', name)
0034                 sym[name] = sym.get(name, 0) + int(size, 16)
0035     return sym
0036 
0037 old = getsizes(sys.argv[1])
0038 new = getsizes(sys.argv[2])
0039 grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
0040 delta, common = [], {}
0041 otot, ntot = 0, 0
0042 
0043 for a in old:
0044     if a in new:
0045         common[a] = 1
0046 
0047 for name in old:
0048     otot += old[name]
0049     if name not in common:
0050         remove += 1
0051         down += old[name]
0052         delta.append((-old[name], name))
0053 
0054 for name in new:
0055     ntot += new[name]
0056     if name not in common:
0057         add += 1
0058         up += new[name]
0059         delta.append((new[name], name))
0060 
0061 for name in common:
0062         d = new.get(name, 0) - old.get(name, 0)
0063         if d>0: grow, up = grow+1, up+d
0064         if d<0: shrink, down = shrink+1, down-d
0065         delta.append((d, name))
0066 
0067 delta.sort()
0068 delta.reverse()
0069 
0070 print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
0071       (add, remove, grow, shrink, up, -down, up-down))
0072 print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta"))
0073 for d, n in delta:
0074     if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d))
0075 
0076 print("Total: Before=%d, After=%d, chg %+.2f%%" % \
0077     (otot, ntot, (ntot - otot)*100.0/otot))