Skip to content

Commit d300684

Browse files
committed
anlysize_code_size.py: Add option to print csv
1 parent 9364c47 commit d300684

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

utils/analyze_code_size.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import sys
77

88

9+
useCSV = False
10+
11+
912
def main(arguments):
1013
parser = argparse.ArgumentParser(
1114
description='Analyze the code size in a binary')
@@ -16,13 +19,20 @@ def main(arguments):
1619
default=False)
1720
parser.add_argument('-list-category', type=str,
1821
help='list symbols in category')
22+
parser.add_argument('-csv', dest='use_csv', action='store_true',
23+
help='print results as csv')
1924
parser.add_argument('-uncategorized', action='store_true',
2025
help='show all uncategorized symbols',
2126
dest='show_uncategorized',
2227
default=False)
2328
parser.add_argument('bin', help='the binary')
29+
parser.set_defaults(use_csv=False)
2430

2531
args = parser.parse_args(arguments)
32+
if args.use_csv:
33+
global useCSV
34+
useCSV = True
35+
print("Using csv")
2636

2737
segments = parse_segments(args.bin, args.arch)
2838

@@ -216,11 +226,15 @@ def print_summary(self, section_size):
216226
total_size += size
217227
if size > 0:
218228
sorted_categories.append(
219-
(name, size, (float(size) * 100) / section_size))
220-
sorted_categories.sort(key = lambda entry : entry [1], reverse=True)
229+
(name, size, (float(size) * 100) / section_size))
230+
sorted_categories.sort(key=lambda entry: entry[1], reverse=True)
221231
for category in sorted_categories:
222-
print("%60s: %8d (%6.2f%%)" %
223-
(category[0], category[1], category[2]))
232+
if useCSV:
233+
print("%s;%d;%.2f%%" %
234+
(category[0], category[1], category[2]))
235+
else:
236+
print("%60s: %8d (%6.2f%%)" %
237+
(category[0], category[1], category[2]))
224238
print("%60s: %8d (%6.2f%%)" % ('TOTAL', total_size, float(100)))
225239

226240
def uncatorizedSymbols(self):

0 commit comments

Comments
 (0)