6
6
import sys
7
7
8
8
9
+ useCSV = False
10
+
11
+
9
12
def main (arguments ):
10
13
parser = argparse .ArgumentParser (
11
14
description = 'Analyze the code size in a binary' )
@@ -16,13 +19,20 @@ def main(arguments):
16
19
default = False )
17
20
parser .add_argument ('-list-category' , type = str ,
18
21
help = 'list symbols in category' )
22
+ parser .add_argument ('-csv' , dest = 'use_csv' , action = 'store_true' ,
23
+ help = 'print results as csv' )
19
24
parser .add_argument ('-uncategorized' , action = 'store_true' ,
20
25
help = 'show all uncategorized symbols' ,
21
26
dest = 'show_uncategorized' ,
22
27
default = False )
23
28
parser .add_argument ('bin' , help = 'the binary' )
29
+ parser .set_defaults (use_csv = False )
24
30
25
31
args = parser .parse_args (arguments )
32
+ if args .use_csv :
33
+ global useCSV
34
+ useCSV = True
35
+ print ("Using csv" )
26
36
27
37
segments = parse_segments (args .bin , args .arch )
28
38
@@ -207,15 +217,24 @@ def print_summary(self, section_size):
207
217
names .extend ([c [0 ] for c in self .category_mangled_matching ])
208
218
names .append ('Unknown' )
209
219
total_size = 0
220
+ sorted_categories = []
210
221
for name in names :
211
222
category = self .categories .get (name )
212
223
size = 0
213
224
if category :
214
225
size = category .size
215
226
total_size += size
216
227
if size > 0 :
228
+ sorted_categories .append (
229
+ (name , size , (float (size ) * 100 ) / section_size ))
230
+ sorted_categories .sort (key = lambda entry : entry [1 ], reverse = True )
231
+ for category in sorted_categories :
232
+ if useCSV :
233
+ print ("%s;%d;%.2f%%" %
234
+ (category [0 ], category [1 ], category [2 ]))
235
+ else :
217
236
print ("%60s: %8d (%6.2f%%)" %
218
- (name , size , ( float ( size ) * 100 ) / section_size ))
237
+ (category [ 0 ], category [ 1 ], category [ 2 ] ))
219
238
print ("%60s: %8d (%6.2f%%)" % ('TOTAL' , total_size , float (100 )))
220
239
221
240
def uncatorizedSymbols (self ):
0 commit comments