1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-22 11:43:51 +01:00
This commit is contained in:
J. Nick Koston
2025-10-17 13:44:30 -10:00
parent 6d2c700c43
commit 256d3b119b

View File

@@ -1,6 +1,7 @@
"""Memory usage analyzer for ESPHome compiled binaries.""" """Memory usage analyzer for ESPHome compiled binaries."""
from collections import defaultdict from collections import defaultdict
from dataclasses import dataclass, field
from functools import cache from functools import cache
import json import json
import logging import logging
@@ -36,32 +37,36 @@ def get_esphome_components():
return components return components
@dataclass
class MemorySection: class MemorySection:
"""Represents a memory section with its symbols.""" """Represents a memory section with its symbols."""
def __init__(self, name: str): name: str
self.name = name symbols: list[tuple[str, int, str]] = field(
self.symbols: list[tuple[str, int, str]] = [] # (symbol_name, size, component) default_factory=list
self.total_size = 0 ) # (symbol_name, size, component)
total_size: int = 0
@dataclass
class ComponentMemory: class ComponentMemory:
"""Tracks memory usage for a component.""" """Tracks memory usage for a component."""
def __init__(self, name: str): name: str
self.name = name text_size: int = 0 # Code in flash
self.text_size = 0 # Code in flash rodata_size: int = 0 # Read-only data in flash
self.rodata_size = 0 # Read-only data in flash data_size: int = 0 # Initialized data (flash + ram)
self.data_size = 0 # Initialized data (flash + ram) bss_size: int = 0 # Uninitialized data (ram only)
self.bss_size = 0 # Uninitialized data (ram only) symbol_count: int = 0
self.symbol_count = 0
@property @property
def flash_total(self) -> int: def flash_total(self) -> int:
"""Total flash usage (text + rodata + data)."""
return self.text_size + self.rodata_size + self.data_size return self.text_size + self.rodata_size + self.data_size
@property @property
def ram_total(self) -> int: def ram_total(self) -> int:
"""Total RAM usage (data + bss)."""
return self.data_size + self.bss_size return self.data_size + self.bss_size