Skip to content

Commit 0ba46e7

Browse files
author
Cruz Monrreal
authored
Merge pull request #7377 from theotherjimmy/stats-depth-zero
Tools: Summarize stats when depth is 0
2 parents 1941906 + e53537c commit 0ba46e7

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tools/memap.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import json
1414
from argparse import ArgumentParser
1515
from copy import deepcopy
16+
from collections import defaultdict
1617
from prettytable import PrettyTable
1718
from jinja2 import FileSystemLoader, StrictUndefined
1819
from jinja2.environment import Environment
@@ -57,7 +58,8 @@ def module_add(self, object_name, size, section):
5758
contents[section] += size
5859
return
5960

60-
new_module = {section: size}
61+
new_module = defaultdict(int)
62+
new_module[section] = size
6163
self.modules[object_name] = new_module
6264

6365
def module_replace(self, old_object, new_object):
@@ -506,7 +508,7 @@ def reduce_depth(self, depth):
506508
if split_name[0] == '':
507509
split_name = split_name[1:]
508510
new_name = join(*split_name[:depth])
509-
self.short_modules.setdefault(new_name, {})
511+
self.short_modules.setdefault(new_name, defaultdict(int))
510512
for section_idx, value in v.items():
511513
self.short_modules[new_name].setdefault(section_idx, 0)
512514
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):
525527
526528
Returns: generated string for the 'table' format, otherwise None
527529
"""
528-
self.reduce_depth(depth)
530+
if depth is None or depth > 0:
531+
self.reduce_depth(depth)
529532
self.compute_report()
530533
try:
531534
if file_output:
@@ -706,24 +709,24 @@ def compute_report(self):
706709
for k in self.sections:
707710
self.subtotal[k] = 0
708711

709-
for i in self.short_modules:
712+
for mod in self.modules.values():
710713
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]
713715

714716
self.mem_summary = {
715717
'static_ram': (self.subtotal['.data'] + self.subtotal['.bss']),
716718
'total_flash': (self.subtotal['.text'] + self.subtotal['.data']),
717719
}
718720

719721
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+
})
727730

728731
self.mem_report.append({
729732
'summary': self.mem_summary

0 commit comments

Comments
 (0)