Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 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 "tTdDbB": |
| 21 | sym[name] = int(size, 16) |
| 22 | return sym |
| 23 | |
| 24 | old = getsizes(sys.argv[1]) |
| 25 | new = getsizes(sys.argv[2]) |
| 26 | grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 |
| 27 | delta, common = [], {} |
| 28 | |
| 29 | for a in old: |
| 30 | if a in new: |
| 31 | common[a] = 1 |
| 32 | |
| 33 | for name in old: |
| 34 | if name not in common: |
| 35 | remove += 1 |
| 36 | down += old[name] |
| 37 | delta.append((-old[name], name)) |
| 38 | |
| 39 | for name in new: |
| 40 | if name not in common: |
| 41 | add += 1 |
| 42 | up += new[name] |
| 43 | delta.append((new[name], name)) |
| 44 | |
| 45 | for name in common: |
| 46 | d = new.get(name, 0) - old.get(name, 0) |
| 47 | if d>0: grow, up = grow+1, up+d |
| 48 | if d<0: shrink, down = shrink+1, down-d |
| 49 | delta.append((d, name)) |
| 50 | |
| 51 | delta.sort() |
| 52 | delta.reverse() |
| 53 | |
| 54 | print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \ |
| 55 | (add, remove, grow, shrink, up, -down, up-down) |
| 56 | print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta") |
| 57 | for d, n in delta: |
| 58 | if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d) |