Skip to content

Commit bad0348

Browse files
Merge pull request swiftlang#25660 from apple/analyze_code_size_sorted
analyze_code_size.py sort the categories by size
2 parents 62cb20e + d300684 commit bad0348

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

utils/analyze_code_size.py

Lines changed: 20 additions & 1 deletion
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

@@ -207,15 +217,24 @@ def print_summary(self, section_size):
207217
names.extend([c[0] for c in self.category_mangled_matching])
208218
names.append('Unknown')
209219
total_size = 0
220+
sorted_categories = []
210221
for name in names:
211222
category = self.categories.get(name)
212223
size = 0
213224
if category:
214225
size = category.size
215226
total_size += size
216227
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:
217236
print("%60s: %8d (%6.2f%%)" %
218-
(name, size, (float(size) * 100) / section_size))
237+
(category[0], category[1], category[2]))
219238
print("%60s: %8d (%6.2f%%)" % ('TOTAL', total_size, float(100)))
220239

221240
def uncatorizedSymbols(self):

0 commit comments

Comments
 (0)