[PATCH v2] scripts: Enhance bloat-o-meter to detect .rodata section size changes

18 views
Skip to first unread message

Iulia Manda

unread,
Jan 26, 2015, 1:00:10 PM1/26/15
to jo...@joshtriplett.org, opw-k...@googlegroups.com
Add functionality to scripts/bloat-o-meter to detect size changes in *.rodata*
sections not associated with a symbol (e.g changes to string constants).

Note that gcc uses string padding, so .rodata section size may not change
after a small addition/removal, if you run the script on executable files.
This is why it is added a new parameter, -object-file. Running the script
using this will output the changes in all *.rodata* sections.

At the moment, it only prints changes in .rodata sections, but as
get_section_size function is generic, it can be modified to show modifications
in any other section, specifically.

Signed-off-by: Iulia Manda <iulia....@gmail.com>
---
Changes since v1:
- add a new parameter to the script, -object-file
scripts/bloat-o-meter | 36 +++++++++++++++++++++++++++++++-----
1 file changed, 31 insertions(+), 5 deletions(-)

diff --git a/scripts/bloat-o-meter b/scripts/bloat-o-meter
index 23e78dc..9a6915a 100755
--- a/scripts/bloat-o-meter
+++ b/scripts/bloat-o-meter
@@ -7,12 +7,37 @@
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

-import sys, os, re
+import sys, os, re, subprocess

-if len(sys.argv) != 3:
- sys.stderr.write("usage: %s file1 file2\n" % sys.argv[0])
+is_run_on_obj = False
+file_1 = None
+file_2 = None
+
+if len(sys.argv) == 4 and sys.argv[1] == "-object-file":
+ is_run_on_obj = True
+ file_1, file_2 = sys.argv[2:]
+elif len(sys.argv) == 3:
+ file_1, file_2 = sys.argv[1:]
+else:
+ sys.stderr.write("usage: %s [-object-file] file1 file2\n"
+ % sys.argv[0])
sys.exit(-1)

+
+def get_section_size(file, section, sym):
+ for l in os.popen("objdump -h " + file).readlines():
+ line_tokens = l.split()
+ # retain Size column index
+ if "Size" in l:
+ idx = line_tokens.index("Size")
+ # cumulate all section's sizes
+ if section in l:
+ r = section if is_run_on_obj == 0 else line_tokens[1]
+ if r not in sym:
+ sym[r] = 0
+ sym[r] += int(line_tokens[idx], 16)
+
+
def getsizes(file):
sym = {}
for l in os.popen("nm --size-sort " + file).readlines():
@@ -26,10 +51,11 @@ 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)
+ get_section_size(file, ".rodata", sym)
return sym

-old = getsizes(sys.argv[1])
-new = getsizes(sys.argv[2])
+old = getsizes(file_1)
+new = getsizes(file_2)
grow, shrink, add, remove, up, down = 0, 0, 0, 0, 0, 0
delta, common = [], {}

--
1.7.10.4

Reply all
Reply to author
Forward
0 new messages