Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions scripts/memory_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ def aggregate_by_library(self) -> Dict[str, Dict[str, int]]:

return dict(library_usage)

def get_rom_usage(self) -> Dict[str, int]:
"""Calculate ROM (Flash) usage"""
def get_rom_usage(self, modules_dmp_size: int = 0) -> Dict[str, int]:
"""Calculate ROM (Flash) usage

Args:
modules_dmp_size: Size of modules.dmp file if it exists (0 if not present)
"""
rom_usage = {}

# Get library contributions to text and rodata
Expand All @@ -166,6 +170,10 @@ def get_rom_usage(self) -> Dict[str, int]:
for lib_name, sections in library_usage.items():
rom_usage[lib_name] = sections['text'] + sections['rodata']

# Add modules.dmp size if file exists (size > 0)
if modules_dmp_size > 0:
rom_usage['modules.dmp'] = modules_dmp_size

return rom_usage

def get_ram_usage(self) -> Dict[str, int]:
Expand All @@ -192,8 +200,12 @@ def get_ram_usage(self) -> Dict[str, int]:

return ram_usage

def get_total_rom(self) -> int:
"""Get total ROM usage"""
def get_total_rom(self, modules_dmp_size: int = 0) -> int:
"""Get total ROM usage

Args:
modules_dmp_size: Size of modules.dmp file if it exists (0 if not present)
"""
total = 0
if 'text' in self.sections:
total += self.sections['text']['size']
Expand All @@ -202,6 +214,8 @@ def get_total_rom(self) -> int:
if 'data' in self.sections:
# .data is stored in ROM but copied to RAM
total += self.sections['data']['size']
# Add modules.dmp size if provided (0 is safe to add)
total += modules_dmp_size
return total

def get_total_ram(self) -> int:
Expand Down Expand Up @@ -380,10 +394,20 @@ def main():
parser = MemoryMapParser(map_file, library_config if library_config else None)
parser.parse()

# Check for modules.dmp file in the output directory (build directory)
modules_dmp_path = Path(output_dir) / "modules.dmp"
modules_dmp_size = 0
if modules_dmp_path.exists():
try:
modules_dmp_size = modules_dmp_path.stat().st_size
print(f"Found modules.dmp: {format_size(modules_dmp_size)}")
except (OSError, PermissionError) as e:
print(f"Warning: Could not read modules.dmp size: {e}")

# Get memory usage
rom_usage = parser.get_rom_usage()
rom_usage = parser.get_rom_usage(modules_dmp_size)
ram_usage = parser.get_ram_usage()
total_rom_used = parser.get_total_rom()
total_rom_used = parser.get_total_rom(modules_dmp_size)
total_ram_used = parser.get_total_ram()

# Get memory capacities
Expand Down