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() |
Jean Delvare | c50e3f5 | 2011-03-22 16:35:13 -0700 | [diff] [blame] | 20 | if type in "tTdDbBrR": |
| 21 | # strip generated symbols |
Josh Triplett | c2e182f | 2013-11-07 12:03:06 +1100 | [diff] [blame] | 22 | if name.startswith("__mod_"): continue |
Josh Triplett | b25c2ff | 2014-08-17 19:45:46 -0500 | [diff] [blame] | 23 | if name.startswith("SyS_"): continue |
| 24 | if name.startswith("compat_SyS_"): continue |
Josh Triplett | 5a7b2d2 | 2013-11-07 12:03:06 +1100 | [diff] [blame] | 25 | if name == "linux_banner": continue |
Andi Kleen | 21cf6e5 | 2013-10-22 08:46:23 -0700 | [diff] [blame] | 26 | # statics and some other optimizations adds random .NUMBER |
| 27 | name = re.sub(r'\.[0-9]+', '', name) |
Rob Landley | 5184973 | 2006-06-25 05:47:10 -0700 | [diff] [blame] | 28 | sym[name] = sym.get(name, 0) + int(size, 16) |
Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 29 | return sym |
| 30 | |
| 31 | old = getsizes(sys.argv[1]) |
| 32 | new = getsizes(sys.argv[2]) |
| 33 | grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0 |
| 34 | delta, common = [], {} |
Vineet Gupta | b21e91c | 2016-05-19 17:09:17 -0700 | [diff] [blame] | 35 | otot, ntot = 0, 0 |
Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 36 | |
| 37 | for a in old: |
| 38 | if a in new: |
| 39 | common[a] = 1 |
| 40 | |
| 41 | for name in old: |
Vineet Gupta | b21e91c | 2016-05-19 17:09:17 -0700 | [diff] [blame] | 42 | otot += old[name] |
Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 43 | if name not in common: |
| 44 | remove += 1 |
| 45 | down += old[name] |
| 46 | delta.append((-old[name], name)) |
| 47 | |
| 48 | for name in new: |
Vineet Gupta | b21e91c | 2016-05-19 17:09:17 -0700 | [diff] [blame] | 49 | ntot += new[name] |
Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 50 | if name not in common: |
| 51 | add += 1 |
| 52 | up += new[name] |
| 53 | delta.append((new[name], name)) |
| 54 | |
| 55 | for name in common: |
| 56 | d = new.get(name, 0) - old.get(name, 0) |
| 57 | if d>0: grow, up = grow+1, up+d |
| 58 | if d<0: shrink, down = shrink+1, down-d |
| 59 | delta.append((d, name)) |
| 60 | |
| 61 | delta.sort() |
| 62 | delta.reverse() |
| 63 | |
Sergey Senozhatsky | 72214a2 | 2016-01-14 15:16:53 -0800 | [diff] [blame] | 64 | print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \ |
| 65 | (add, remove, grow, shrink, up, -down, up-down)) |
| 66 | print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")) |
Matt Mackall | d960600 | 2006-01-08 01:05:19 -0800 | [diff] [blame] | 67 | for d, n in delta: |
Sergey Senozhatsky | 72214a2 | 2016-01-14 15:16:53 -0800 | [diff] [blame] | 68 | if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)) |
Vineet Gupta | b21e91c | 2016-05-19 17:09:17 -0700 | [diff] [blame] | 69 | |
| 70 | print("Total: Before=%d, After=%d, chg %f%%" % \ |
| 71 | (otot, ntot, (ntot - otot)*100/otot)) |