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