blob: 19f5adfd877dcf9b7e9c5b63c796ca72ee06dccf [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 Triplettb25c2ff2014-08-17 19:45:46 -050023 if name.startswith("SyS_"): continue
24 if name.startswith("compat_SyS_"): continue
Josh Triplett5a7b2d22013-11-07 12:03:06 +110025 if name == "linux_banner": continue
Andi Kleen21cf6e52013-10-22 08:46:23 -070026 # statics and some other optimizations adds random .NUMBER
27 name = re.sub(r'\.[0-9]+', '', name)
Rob Landley51849732006-06-25 05:47:10 -070028 sym[name] = sym.get(name, 0) + int(size, 16)
Matt Mackalld9606002006-01-08 01:05:19 -080029 return sym
30
31old = getsizes(sys.argv[1])
32new = getsizes(sys.argv[2])
33grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
34delta, common = [], {}
Vineet Guptab21e91c2016-05-19 17:09:17 -070035otot, ntot = 0, 0
Matt Mackalld9606002006-01-08 01:05:19 -080036
37for a in old:
38 if a in new:
39 common[a] = 1
40
41for name in old:
Vineet Guptab21e91c2016-05-19 17:09:17 -070042 otot += old[name]
Matt Mackalld9606002006-01-08 01:05:19 -080043 if name not in common:
44 remove += 1
45 down += old[name]
46 delta.append((-old[name], name))
47
48for name in new:
Vineet Guptab21e91c2016-05-19 17:09:17 -070049 ntot += new[name]
Matt Mackalld9606002006-01-08 01:05:19 -080050 if name not in common:
51 add += 1
52 up += new[name]
53 delta.append((new[name], name))
54
55for 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
61delta.sort()
62delta.reverse()
63
Sergey Senozhatsky72214a22016-01-14 15:16:53 -080064print("add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
65 (add, remove, grow, shrink, up, -down, up-down))
66print("%-40s %7s %7s %+7s" % ("function", "old", "new", "delta"))
Matt Mackalld9606002006-01-08 01:05:19 -080067for d, n in delta:
Sergey Senozhatsky72214a22016-01-14 15:16:53 -080068 if d: print("%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d))
Vineet Guptab21e91c2016-05-19 17:09:17 -070069
Riku Voipio8cde0da2016-07-26 15:21:20 -070070print("Total: Before=%d, After=%d, chg %+.2f%%" % \
71 (otot, ntot, (ntot - otot)*100.0/otot))