13
13
import json
14
14
from argparse import ArgumentParser
15
15
from copy import deepcopy
16
+ from collections import defaultdict
16
17
from prettytable import PrettyTable
17
18
from jinja2 import FileSystemLoader , StrictUndefined
18
19
from jinja2 .environment import Environment
@@ -57,7 +58,8 @@ def module_add(self, object_name, size, section):
57
58
contents [section ] += size
58
59
return
59
60
60
- new_module = {section : size }
61
+ new_module = defaultdict (int )
62
+ new_module [section ] = size
61
63
self .modules [object_name ] = new_module
62
64
63
65
def module_replace (self , old_object , new_object ):
@@ -506,7 +508,7 @@ def reduce_depth(self, depth):
506
508
if split_name [0 ] == '' :
507
509
split_name = split_name [1 :]
508
510
new_name = join (* split_name [:depth ])
509
- self .short_modules .setdefault (new_name , {} )
511
+ self .short_modules .setdefault (new_name , defaultdict ( int ) )
510
512
for section_idx , value in v .items ():
511
513
self .short_modules [new_name ].setdefault (section_idx , 0 )
512
514
self .short_modules [new_name ][section_idx ] += self .modules [module_name ][section_idx ]
@@ -525,7 +527,8 @@ def generate_output(self, export_format, depth, file_output=None):
525
527
526
528
Returns: generated string for the 'table' format, otherwise None
527
529
"""
528
- self .reduce_depth (depth )
530
+ if depth is None or depth > 0 :
531
+ self .reduce_depth (depth )
529
532
self .compute_report ()
530
533
try :
531
534
if file_output :
@@ -706,24 +709,24 @@ def compute_report(self):
706
709
for k in self .sections :
707
710
self .subtotal [k ] = 0
708
711
709
- for i in self .short_modules :
712
+ for mod in self .modules . values () :
710
713
for k in self .sections :
711
- self .short_modules [i ].setdefault (k , 0 )
712
- self .subtotal [k ] += self .short_modules [i ][k ]
714
+ self .subtotal [k ] += mod [k ]
713
715
714
716
self .mem_summary = {
715
717
'static_ram' : (self .subtotal ['.data' ] + self .subtotal ['.bss' ]),
716
718
'total_flash' : (self .subtotal ['.text' ] + self .subtotal ['.data' ]),
717
719
}
718
720
719
721
self .mem_report = []
720
- for i in sorted (self .short_modules ):
721
- self .mem_report .append ({
722
- "module" :i ,
723
- "size" :{
724
- k : self .short_modules [i ][k ] for k in self .print_sections
725
- }
726
- })
722
+ if self .short_modules :
723
+ for name , sizes in sorted (self .short_modules .items ()):
724
+ self .mem_report .append ({
725
+ "module" : name ,
726
+ "size" :{
727
+ k : sizes .get (k , 0 ) for k in self .print_sections
728
+ }
729
+ })
727
730
728
731
self .mem_report .append ({
729
732
'summary' : self .mem_summary
0 commit comments