blob: 549d0ab8c66204ec8db65de3d48ce619f7dee925 [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()
Jean Delvarec50e3f52011-03-22 16:35:13 -070020 if type in "tTdDbBrR":
21 # strip generated symbols
Josh Triplettc2e182f2013-11-07 12:03:06 +110022 if name.startswith("__mod_"): continue
Josh Triplett5a7b2d22013-11-07 12:03:06 +110023 if name == "linux_banner": continue
Andi Kleen21cf6e52013-10-22 08:46:23 -070024 # statics and some other optimizations adds random .NUMBER
25 name = re.sub(r'\.[0-9]+', '', name)
Rob Landley51849732006-06-25 05:47:10 -070026 sym[name] = sym.get(name, 0) + int(size, 16)
Matt Mackalld9606002006-01-08 01:05:19 -080027 return sym
28
29old = getsizes(sys.argv[1])
30new = getsizes(sys.argv[2])
31grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
32delta, common = [], {}
33
34for a in old:
35 if a in new:
36 common[a] = 1
37
38for name in old:
39 if name not in common:
40 remove += 1
41 down += old[name]
42 delta.append((-old[name], name))
43
44for name in new:
45 if name not in common:
46 add += 1
47 up += new[name]
48 delta.append((new[name], name))
49
50for name in common:
51 d = new.get(name, 0) - old.get(name, 0)
52 if d>0: grow, up = grow+1, up+d
53 if d<0: shrink, down = shrink+1, down-d
54 delta.append((d, name))
55
56delta.sort()
57delta.reverse()
58
59print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
60 (add, remove, grow, shrink, up, -down, up-down)
61print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")
62for d, n in delta:
63 if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)