blob: 76d342cae506b3fd10fd601014f706ac6dd1c82e [file] [log] [blame]
Rob Landleyf8a80842006-05-07 19:26:53 +00001#!/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
Bernhard Reutner-Fischer45aebfd2007-04-05 12:27:12 +000016for f in sys.argv[1], sys.argv[2]:
17 if not os.path.exists(f):
18 sys.stderr.write("Error: file '%s' does not exist\n" % f)
19 sys.exit(-1)
20
Rob Landleyf8a80842006-05-07 19:26:53 +000021def getsizes(file):
22 sym = {}
23 for l in os.popen("nm --size-sort " + file).readlines():
Bernhard Reutner-Fischer49bdf282008-05-21 10:32:39 +000024 # Skip empty lines
Bernhard Reutner-Fischer7bd8d8f2008-05-21 21:15:37 +000025 if not len(l.strip()): continue
Bernhard Reutner-Fischer49bdf282008-05-21 10:32:39 +000026 # Skip archive members
27 if len(l.split()) == 1 and l.endswith(':'):
28 continue
Rob Landleyf8a80842006-05-07 19:26:53 +000029 size, type, name = l[:-1].split()
Denis Vlasenko2425bdc2006-11-29 14:32:01 +000030 if type in "tTdDbBrR":
Rob Landley712ba852006-05-08 18:30:33 +000031 if "." in name: name = "static." + name.split(".")[0]
32 sym[name] = sym.get(name, 0) + int(size, 16)
Rob Landleyf14f7fc2006-05-29 20:56:27 +000033 for l in os.popen("readelf -S " + file).readlines():
34 x = l.split()
35 if len(x)<6 or x[1] != ".rodata": continue
36 sym[".rodata"] = int(x[5], 16)
Rob Landleyf8a80842006-05-07 19:26:53 +000037 return sym
38
39old = getsizes(sys.argv[1])
40new = getsizes(sys.argv[2])
41grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
42delta, common = [], {}
43
44for a in old:
45 if a in new:
46 common[a] = 1
47
48for name in old:
49 if name not in common:
50 remove += 1
51 down += old[name]
52 delta.append((-old[name], name))
53
54for name in new:
55 if name not in common:
56 add += 1
57 up += new[name]
58 delta.append((new[name], name))
59
60for name in common:
61 d = new.get(name, 0) - old.get(name, 0)
62 if d>0: grow, up = grow+1, up+d
63 if d<0: shrink, down = shrink+1, down-d
64 delta.append((d, name))
65
66delta.sort()
67delta.reverse()
68
Rob Landleyf14f7fc2006-05-29 20:56:27 +000069print "%-48s %7s %7s %+7s" % ("function", "old", "new", "delta")
Rob Landleyf8a80842006-05-07 19:26:53 +000070for d, n in delta:
Rob Landleyf14f7fc2006-05-29 20:56:27 +000071 if d: print "%-48s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)
72print "-"*78
73total="(add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s)%%sTotal: %s bytes"\
74 % (add, remove, grow, shrink, up, -down, up-down)
75print total % (" "*(80-len(total)))