Magellan Linux

Contents of /trunk/mkinitrd-magellan/busybox/scripts/bloat-o-meter

Parent Directory Parent Directory | Revision Log Revision Log


Revision 984 - (show annotations) (download)
Sun May 30 11:32:42 2010 UTC (13 years, 11 months ago) by niro
File size: 2266 byte(s)
-updated to busybox-1.16.1 and enabled blkid/uuid support in default config
1 #!/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
10 import sys, os, re
11
12 def usage():
13 sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
14 sys.exit(-1)
15
16 if len(sys.argv) < 3:
17 usage()
18
19 for f in sys.argv[1:3]:
20 if not os.path.exists(f):
21 sys.stderr.write("Error: file '%s' does not exist\n" % f)
22 usage()
23
24 nm_args = " ".join(sys.argv[3:])
25 def getsizes(file):
26 sym = {}
27 for l in os.popen("nm --size-sort %s %s" % (nm_args, file)).readlines():
28 l = l.strip()
29 # Skip empty lines
30 if not len(l): continue
31 # Skip archive members
32 if len(l.split()) == 1 and l.endswith(':'):
33 continue
34 size, type, name = l.split()
35 if type in "tTdDbBrR":
36 if "." in name: name = "static." + name.split(".")[0]
37 sym[name] = sym.get(name, 0) + int(size, 16)
38 for l in os.popen("readelf -S " + file).readlines():
39 x = l.split()
40 if len(x)<6 or x[1] != ".rodata": continue
41 sym[".rodata"] = int(x[5], 16)
42 return sym
43
44 old = getsizes(sys.argv[1])
45 new = getsizes(sys.argv[2])
46 grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
47 delta, common = [], {}
48
49 for a in old:
50 if a in new:
51 common[a] = 1
52
53 for name in old:
54 if name not in common:
55 remove += 1
56 down += old[name]
57 delta.append((-old[name], name))
58
59 for name in new:
60 if name not in common:
61 add += 1
62 up += new[name]
63 delta.append((new[name], name))
64
65 for name in common:
66 d = new.get(name, 0) - old.get(name, 0)
67 if d>0: grow, up = grow+1, up+d
68 if d<0: shrink, down = shrink+1, down-d
69 delta.append((d, name))
70
71 delta.sort()
72 delta.reverse()
73
74 print "%-48s %7s %7s %+7s" % ("function", "old", "new", "delta")
75 for d, n in delta:
76 if d: print "%-48s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)
77 print "-"*78
78 total="(add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s)%%sTotal: %s bytes"\
79 % (add, remove, grow, shrink, up, -down, up-down)
80 print total % (" "*(80-len(total)))

Properties

Name Value
svn:executable *