blob: 6501a50e17f0e157dab2dab3d64d8807fc3669da [file] [log] [blame]
Matt Mackalld9606002006-01-08 01:05:19 -08001#!/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
10import sys, os, re
11
12if len(sys.argv) != 3:
13 sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
14 sys.exit(-1)
15
16def 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":
Nathan Lynch89989792007-12-17 16:20:09 -080021 # function names begin with '.' on 64-bit powerpc
22 if "." in name[1:]: name = "static." + name.split(".")[0]
Rob Landley51849732006-06-25 05:47:10 -070023 sym[name] = sym.get(name, 0) + int(size, 16)
Matt Mackalld9606002006-01-08 01:05:19 -080024 return sym
25
26old = getsizes(sys.argv[1])
27new = getsizes(sys.argv[2])
28grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
29delta, common = [], {}
30
31for a in old:
32 if a in new:
33 common[a] = 1
34
35for name in old:
36 if name not in common:
37 remove += 1
38 down += old[name]
39 delta.append((-old[name], name))
40
41for name in new:
42 if name not in common:
43 add += 1
44 up += new[name]
45 delta.append((new[name], name))
46
47for name in common:
48 d = new.get(name, 0) - old.get(name, 0)
49 if d>0: grow, up = grow+1, up+d
50 if d<0: shrink, down = shrink+1, down-d
51 delta.append((d, name))
52
53delta.sort()
54delta.reverse()
55
56print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
57 (add, remove, grow, shrink, up, -down, up-down)
58print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")
59for d, n in delta:
60 if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)