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