Skip to content

Commit 15db03e

Browse files
Add a script to display the captured code sizes
This script parses the JSON file we generate and pretty-prints a table of sizes along with the totals. Signed-off-by: David Horstmann <david.horstmann@arm.com>
1 parent 6c5e93b commit 15db03e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

scripts/show_code_size.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
"""Parse a JSON code size report and output a pretty-printed table of sizes
3+
for each module along with their totals.
4+
"""
5+
6+
# Copyright The Mbed TLS Contributors
7+
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
8+
9+
import json
10+
import sys
11+
12+
def display_sizes(json_file):
13+
with open(json_file) as f:
14+
json_sizes = f.read()
15+
16+
sizes = json.loads(json_sizes)
17+
18+
padded_line = '{:<40} {:>8} {:>8} {:>8} {:>8}'
19+
20+
print(padded_line.format('file', 'text', 'data', 'bss', 'total'))
21+
22+
text_total = 0
23+
data_total = 0
24+
bss_total = 0
25+
total_total = 0
26+
27+
for file in sizes:
28+
module = file.split('.')[0] # Remove .c.obj extension
29+
text = sizes[file]['text']
30+
data = sizes[file]['data']
31+
bss = sizes[file]['bss']
32+
print(padded_line.format(module, text, data, bss, text + data + bss))
33+
text_total += text
34+
data_total += data
35+
bss_total += bss
36+
total_total += text + data + bss
37+
38+
print(padded_line.format('TOTAL', text_total, data_total, bss_total, total_total))
39+
40+
if __name__ == '__main__':
41+
if len(sys.argv) < 2:
42+
print('Error: No JSON file supplied.', file=sys.stderr)
43+
sys.exit(1)
44+
45+
display_sizes(sys.argv[1])

0 commit comments

Comments
 (0)