mirror of
https://github.com/esphome/esphome.git
synced 2025-10-22 19:53:46 +01:00
reduce
This commit is contained in:
@@ -9,7 +9,12 @@ from pathlib import Path
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from .const import DEMANGLED_PATTERNS, ESPHOME_COMPONENT_PATTERN, SYMBOL_PATTERNS
|
from .const import (
|
||||||
|
CORE_SUBCATEGORY_PATTERNS,
|
||||||
|
DEMANGLED_PATTERNS,
|
||||||
|
ESPHOME_COMPONENT_PATTERN,
|
||||||
|
SYMBOL_PATTERNS,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -37,6 +42,26 @@ def get_esphome_components():
|
|||||||
return components
|
return components
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def get_component_class_patterns(component_name: str) -> list[str]:
|
||||||
|
"""Generate component class name patterns for symbol matching.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
component_name: The component name (e.g., "ota", "wifi", "api")
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of pattern strings to match against demangled symbols
|
||||||
|
"""
|
||||||
|
component_upper = component_name.upper()
|
||||||
|
component_camel = component_name.replace("_", "").title()
|
||||||
|
return [
|
||||||
|
f"esphome::{component_upper}Component", # e.g., esphome::OTAComponent
|
||||||
|
f"esphome::ESPHome{component_upper}Component", # e.g., esphome::ESPHomeOTAComponent
|
||||||
|
f"esphome::{component_camel}Component", # e.g., esphome::OtaComponent
|
||||||
|
f"esphome::ESPHome{component_camel}Component", # e.g., esphome::ESPHomeOtaComponent
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MemorySection:
|
class MemorySection:
|
||||||
"""Represents a memory section with its symbols."""
|
"""Represents a memory section with its symbols."""
|
||||||
@@ -289,16 +314,7 @@ class MemoryAnalyzer:
|
|||||||
# Check for special component classes that include component name in the class
|
# Check for special component classes that include component name in the class
|
||||||
# For example: esphome::ESPHomeOTAComponent -> ota component
|
# For example: esphome::ESPHomeOTAComponent -> ota component
|
||||||
for component_name in get_esphome_components():
|
for component_name in get_esphome_components():
|
||||||
# Check various naming patterns
|
patterns = get_component_class_patterns(component_name)
|
||||||
component_upper = component_name.upper()
|
|
||||||
component_camel = component_name.replace("_", "").title()
|
|
||||||
patterns = [
|
|
||||||
f"esphome::{component_upper}Component", # e.g., esphome::OTAComponent
|
|
||||||
f"esphome::ESPHome{component_upper}Component", # e.g., esphome::ESPHomeOTAComponent
|
|
||||||
f"esphome::{component_camel}Component", # e.g., esphome::OtaComponent
|
|
||||||
f"esphome::ESPHome{component_camel}Component", # e.g., esphome::ESPHomeOtaComponent
|
|
||||||
]
|
|
||||||
|
|
||||||
if any(pattern in demangled for pattern in patterns):
|
if any(pattern in demangled for pattern in patterns):
|
||||||
return f"[esphome]{component_name}"
|
return f"[esphome]{component_name}"
|
||||||
|
|
||||||
@@ -394,35 +410,6 @@ class MemoryAnalyzer:
|
|||||||
|
|
||||||
def _categorize_esphome_core_symbol(self, demangled: str) -> str:
|
def _categorize_esphome_core_symbol(self, demangled: str) -> str:
|
||||||
"""Categorize ESPHome core symbols into subcategories."""
|
"""Categorize ESPHome core symbols into subcategories."""
|
||||||
# Dictionary of patterns for core subcategories
|
|
||||||
CORE_SUBCATEGORY_PATTERNS = {
|
|
||||||
"Component Framework": ["Component"],
|
|
||||||
"Application Core": ["Application"],
|
|
||||||
"Scheduler": ["Scheduler"],
|
|
||||||
"Logging": ["Logger", "log_"],
|
|
||||||
"Preferences": ["preferences", "Preferences"],
|
|
||||||
"Synchronization": ["Mutex", "Lock"],
|
|
||||||
"Helpers": ["Helper"],
|
|
||||||
"Network Utilities": ["network", "Network"],
|
|
||||||
"Time Management": ["time", "Time"],
|
|
||||||
"String Utilities": ["str_", "string"],
|
|
||||||
"Parsing/Formatting": ["parse_", "format_"],
|
|
||||||
"Optional Types": ["optional", "Optional"],
|
|
||||||
"Callbacks": ["Callback", "callback"],
|
|
||||||
"Color Utilities": ["Color"],
|
|
||||||
"C++ Operators": ["operator"],
|
|
||||||
"Global Variables": ["global_", "_GLOBAL"],
|
|
||||||
"Setup/Loop": ["setup", "loop"],
|
|
||||||
"System Control": ["reboot", "restart"],
|
|
||||||
"GPIO Management": ["GPIO", "gpio"],
|
|
||||||
"Interrupt Handling": ["ISR", "interrupt"],
|
|
||||||
"Hooks": ["Hook", "hook"],
|
|
||||||
"Entity Base Classes": ["Entity"],
|
|
||||||
"Automation Framework": ["automation", "Automation"],
|
|
||||||
"Automation Components": ["Condition", "Action", "Trigger"],
|
|
||||||
"Lambda Support": ["lambda"],
|
|
||||||
}
|
|
||||||
|
|
||||||
# Special patterns that need to be checked separately
|
# Special patterns that need to be checked separately
|
||||||
if any(pattern in demangled for pattern in ["vtable", "typeinfo", "thunk"]):
|
if any(pattern in demangled for pattern in ["vtable", "typeinfo", "thunk"]):
|
||||||
return "C++ Runtime (vtables/RTTI)"
|
return "C++ Runtime (vtables/RTTI)"
|
||||||
@@ -430,7 +417,7 @@ class MemoryAnalyzer:
|
|||||||
if demangled.startswith("std::"):
|
if demangled.startswith("std::"):
|
||||||
return "C++ STL"
|
return "C++ STL"
|
||||||
|
|
||||||
# Check against patterns
|
# Check against patterns from const.py
|
||||||
for category, patterns in CORE_SUBCATEGORY_PATTERNS.items():
|
for category, patterns in CORE_SUBCATEGORY_PATTERNS.items():
|
||||||
if any(pattern in demangled for pattern in patterns):
|
if any(pattern in demangled for pattern in patterns):
|
||||||
return category
|
return category
|
||||||
|
@@ -855,3 +855,31 @@ DEMANGLED_PATTERNS = {
|
|||||||
"filesystem": ["spiffs", "vfs"],
|
"filesystem": ["spiffs", "vfs"],
|
||||||
"libc": ["newlib"],
|
"libc": ["newlib"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Patterns for categorizing ESPHome core symbols into subcategories
|
||||||
|
CORE_SUBCATEGORY_PATTERNS = {
|
||||||
|
"Component Framework": ["Component"],
|
||||||
|
"Application Core": ["Application"],
|
||||||
|
"Scheduler": ["Scheduler"],
|
||||||
|
"Component Iterator": ["ComponentIterator"],
|
||||||
|
"Helper Functions": ["Helpers", "helpers"],
|
||||||
|
"Preferences/Storage": ["Preferences", "ESPPreferences"],
|
||||||
|
"I/O Utilities": ["HighFrequencyLoopRequester"],
|
||||||
|
"String Utilities": ["str_"],
|
||||||
|
"Bit Utilities": ["reverse_bits"],
|
||||||
|
"Data Conversion": ["convert_"],
|
||||||
|
"Network Utilities": ["network", "IPAddress"],
|
||||||
|
"API Protocol": ["api::"],
|
||||||
|
"WiFi Manager": ["wifi::"],
|
||||||
|
"MQTT Client": ["mqtt::"],
|
||||||
|
"Logger": ["logger::"],
|
||||||
|
"OTA Updates": ["ota::"],
|
||||||
|
"Web Server": ["web_server::"],
|
||||||
|
"Time Management": ["time::"],
|
||||||
|
"Sensor Framework": ["sensor::"],
|
||||||
|
"Binary Sensor": ["binary_sensor::"],
|
||||||
|
"Switch Framework": ["switch_::"],
|
||||||
|
"Light Framework": ["light::"],
|
||||||
|
"Climate Framework": ["climate::"],
|
||||||
|
"Cover Framework": ["cover::"],
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user