| 1 | #!/usr/bin/python |
| 2 | # |
| 3 | # Copyright 2004 Matt Mackall <mpm@selenic.com> |
| 4 | # |
| 5 | # inspired by perl Bloat-O-Meter (c) 1997 by Andi Kleen |
| 6 | # |
| 7 | # This software may be used and distributed according to the terms |
| 8 | # of the GNU General Public License, incorporated herein by reference. |
| 9 | |
| 10 | import sys, os, re |
| 11 | |
| 12 | if len(sys.argv) != 3: |
| 13 | sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0]) |
| 14 | sys.exit(-1) |
| 15 | |
| 16 | def getsizes(file): |
| 17 | sym = {} |
| 18 | for l in os.popen("nm --size-sort " + file).readlines(): |
| 19 | size, type, name = l[:-1].split() |
| 20 | if type in "tTdDbBrR": |
| 21 | # strip generated symbols |
| 22 | if name[:6] == "__mod_": continue |
| 23 | # function names begin with '.' on 64-bit powerpc |
| 24 | if "." in name[1:]: name = "static." + name.split(".")[0] |
| 25 | sym[name] = sym.get(name, 0) + int(size, 16) |
| 26 | return sym |
| 27 | |
| 28 | old = getsizes(sys.argv[1]) |
| 29 | new = getsizes(sys.argv[2]) |
| 30 | grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 |
| 31 | delta, common = [], {} |
| 32 | |
| 33 | for a in old: |
| 34 | if a in new: |
| 35 | common[a] = 1 |
| 36 | |
| 37 | for name in old: |
| 38 | if name not in common: |
| 39 | remove += 1 |
| 40 | down += old[name] |
| 41 | delta.append((-old[name], name)) |
| 42 | |
| 43 | for name in new: |
| 44 | if name not in common: |
| 45 | add += 1 |
| 46 | up += new[name] |
| 47 | delta.append((new[name], name)) |
| 48 | |
| 49 | for name in common: |
| 50 | d = new.get(name, 0) - old.get(name, 0) |
| 51 | if d>0: grow, up = grow+1, up+d |
| 52 | if d<0: shrink, down = shrink+1, down-d |
| 53 | delta.append((d, name)) |
| 54 | |
| 55 | delta.sort() |
| 56 | delta.reverse() |
| 57 | |
| 58 | print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \ |
| 59 | (add, remove, grow, shrink, up, -down, up-down)) |
| 60 | print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")) |
| 61 | for d, n in delta: |
| 62 | if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)) |