[PATCH] scripts/bloat-o-meter: include .rodata section comparison

From: Aristeu Rozanski
Date: Mon Jan 12 2015 - 12:02:59 EST


This patch adds section .rodata comparison in order to detect string
constant changes.

Cc: Josh Triplett <josh@xxxxxxxxxxxxxxxx>
Signed-off-by: Aristeu Rozanski <aris@xxxxxxxxxx>

diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index 23e78dc..cee812a 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -26,40 +26,66 @@ def getsizes(file):
# statics and some other optimizations adds random .NUMBER
name = re.sub(r'\.[0-9]+', '', name)
sym[name] = sym.get(name, 0) + int(size, 16)
- return sym

-old = getsizes(sys.argv[1])
-new = getsizes(sys.argv[2])
-grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
-delta, common = [], {}
+ sections = {}
+ exp = re.compile('[\ ]*[0-9]+[\ ]+([^\ ]+)[\ ]+([0-9a-f]+).*')
+ wanted_sections = ['.rodata']
+ for l in os.popen("objdump -h -w " + file).readlines():
+ match = exp.match(l)
+ if not match:
+ continue
+ name = match.group(1)
+ if name not in wanted_sections:
+ continue
+ size = int(match.group(2), 16)
+ sections[name] = size

-for a in old:
- if a in new:
- common[a] = 1
+ return (sym, sections)

-for name in old:
- if name not in common:
- remove += 1
- down += old[name]
- delta.append((-old[name], name))
+def process_results(old, new):
+ grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
+ delta, common = [], {}
+ for a in old:
+ if a in new:
+ common[a] = 1

-for name in new:
- if name not in common:
- add += 1
- up += new[name]
- delta.append((new[name], name))
+ for name in old:
+ if name not in common:
+ remove += 1
+ down += old[name]
+ delta.append((-old[name], name))

-for name in common:
- d = new.get(name, 0) - old.get(name, 0)
- if d>0: grow, up = grow+1, up+d
- if d<0: shrink, down = shrink+1, down-d
- delta.append((d, name))
+ for name in new:
+ if name not in common:
+ add += 1
+ up += new[name]
+ delta.append((new[name], name))

-delta.sort()
-delta.reverse()
+ for name in common:
+ d = new.get(name, 0) - old.get(name, 0)
+ if d>0: grow, up = grow+1, up+d
+ if d<0: shrink, down = shrink+1, down-d
+ delta.append((d, name))

-print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
- (add, remove, grow, shrink, up, -down, up-down)
-print "%-40s %7s %7s %+7s" % ("function", "old", "new", "delta")
-for d, n in delta:
- if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)
+ delta.sort()
+ delta.reverse()
+
+ return (add, remove, up, down, grow, shrink, delta)
+
+def print_results(title, add, remove, up, down, grow, shrink, delta, old, new):
+ print "add/remove: %s/%s grow/shrink: %s/%s up/down: %s/%s (%s)" % \
+ (add, remove, grow, shrink, up, -down, up-down)
+ print "%-40s %7s %7s %+7s" % (title, "old", "new", "delta")
+ for d, n in delta:
+ if d: print "%-40s %7s %7s %+7d" % (n, old.get(n,"-"), new.get(n,"-"), d)
+
+old, old_sections = getsizes(sys.argv[1])
+new, new_sections = getsizes(sys.argv[2])
+
+(add, remove, up, down, grow, shrink, delta) = process_results(old, new)
+print "Symbols changes"
+print_results("function", add, remove, up, down, grow, shrink, delta, old, new)
+
+(add, remove, up, down, grow, shrink, delta) = process_results(old_sections, new_sections)
+print "\nSection changes"
+print_results("section", add, remove, up, down, grow, shrink, delta, old_sections, new_sections)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/