mirror of
https://github.com/esphome/esphome.git
synced 2025-10-21 19:23:45 +01:00
preen
This commit is contained in:
@@ -48,6 +48,12 @@ _READELF_SECTION_PATTERN = re.compile(
|
|||||||
r"\s*\[\s*\d+\]\s+([\.\w]+)\s+\w+\s+[\da-fA-F]+\s+[\da-fA-F]+\s+([\da-fA-F]+)"
|
r"\s*\[\s*\d+\]\s+([\.\w]+)\s+\w+\s+[\da-fA-F]+\s+[\da-fA-F]+\s+([\da-fA-F]+)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Component category prefixes
|
||||||
|
_COMPONENT_PREFIX_ESPHOME = "[esphome]"
|
||||||
|
_COMPONENT_PREFIX_EXTERNAL = "[external]"
|
||||||
|
_COMPONENT_CORE = f"{_COMPONENT_PREFIX_ESPHOME}core"
|
||||||
|
_COMPONENT_API = f"{_COMPONENT_PREFIX_ESPHOME}api"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MemorySection:
|
class MemorySection:
|
||||||
@@ -222,7 +228,7 @@ class MemoryAnalyzer:
|
|||||||
self._uncategorized_symbols.append((symbol_name, demangled, size))
|
self._uncategorized_symbols.append((symbol_name, demangled, size))
|
||||||
|
|
||||||
# Track ESPHome core symbols for detailed analysis
|
# Track ESPHome core symbols for detailed analysis
|
||||||
if component == "[esphome]core" and size > 0:
|
if component == _COMPONENT_CORE and size > 0:
|
||||||
demangled = self._demangle_symbol(symbol_name)
|
demangled = self._demangle_symbol(symbol_name)
|
||||||
self._esphome_core_symbols.append((symbol_name, demangled, size))
|
self._esphome_core_symbols.append((symbol_name, demangled, size))
|
||||||
|
|
||||||
@@ -246,7 +252,7 @@ class MemoryAnalyzer:
|
|||||||
for component_name in get_esphome_components():
|
for component_name in get_esphome_components():
|
||||||
patterns = get_component_class_patterns(component_name)
|
patterns = get_component_class_patterns(component_name)
|
||||||
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"{_COMPONENT_PREFIX_ESPHOME}{component_name}"
|
||||||
|
|
||||||
# Check for ESPHome component namespaces
|
# Check for ESPHome component namespaces
|
||||||
match = ESPHOME_COMPONENT_PATTERN.search(demangled)
|
match = ESPHOME_COMPONENT_PATTERN.search(demangled)
|
||||||
@@ -257,17 +263,17 @@ class MemoryAnalyzer:
|
|||||||
|
|
||||||
# Check if this is an actual component in the components directory
|
# Check if this is an actual component in the components directory
|
||||||
if component_name in get_esphome_components():
|
if component_name in get_esphome_components():
|
||||||
return f"[esphome]{component_name}"
|
return f"{_COMPONENT_PREFIX_ESPHOME}{component_name}"
|
||||||
# Check if this is a known external component from the config
|
# Check if this is a known external component from the config
|
||||||
if component_name in self.external_components:
|
if component_name in self.external_components:
|
||||||
return f"[external]{component_name}"
|
return f"{_COMPONENT_PREFIX_EXTERNAL}{component_name}"
|
||||||
# Everything else in esphome:: namespace is core
|
# Everything else in esphome:: namespace is core
|
||||||
return "[esphome]core"
|
return _COMPONENT_CORE
|
||||||
|
|
||||||
# Check for esphome core namespace (no component namespace)
|
# Check for esphome core namespace (no component namespace)
|
||||||
if "esphome::" in demangled:
|
if "esphome::" in demangled:
|
||||||
# If no component match found, it's core
|
# If no component match found, it's core
|
||||||
return "[esphome]core"
|
return _COMPONENT_CORE
|
||||||
|
|
||||||
# Check against symbol patterns
|
# Check against symbol patterns
|
||||||
for component, patterns in SYMBOL_PATTERNS.items():
|
for component, patterns in SYMBOL_PATTERNS.items():
|
||||||
@@ -460,8 +466,7 @@ class MemoryAnalyzer:
|
|||||||
Returns:
|
Returns:
|
||||||
Demangled name with suffix annotation
|
Demangled name with suffix annotation
|
||||||
"""
|
"""
|
||||||
suffix_match = _GCC_OPTIMIZATION_SUFFIX_PATTERN.search(original)
|
if suffix_match := _GCC_OPTIMIZATION_SUFFIX_PATTERN.search(original):
|
||||||
if suffix_match:
|
|
||||||
return f"{demangled} [{suffix_match.group(1)}]"
|
return f"{demangled} [{suffix_match.group(1)}]"
|
||||||
return demangled
|
return demangled
|
||||||
|
|
||||||
|
@@ -3,7 +3,13 @@
|
|||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from . import MemoryAnalyzer
|
from . import (
|
||||||
|
_COMPONENT_API,
|
||||||
|
_COMPONENT_CORE,
|
||||||
|
_COMPONENT_PREFIX_ESPHOME,
|
||||||
|
_COMPONENT_PREFIX_EXTERNAL,
|
||||||
|
MemoryAnalyzer,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MemoryAnalyzerCLI(MemoryAnalyzer):
|
class MemoryAnalyzerCLI(MemoryAnalyzer):
|
||||||
@@ -144,7 +150,9 @@ class MemoryAnalyzerCLI(MemoryAnalyzer):
|
|||||||
if self._esphome_core_symbols:
|
if self._esphome_core_symbols:
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append("=" * self.TABLE_WIDTH)
|
lines.append("=" * self.TABLE_WIDTH)
|
||||||
lines.append("[esphome]core Detailed Analysis".center(self.TABLE_WIDTH))
|
lines.append(
|
||||||
|
f"{_COMPONENT_CORE} Detailed Analysis".center(self.TABLE_WIDTH)
|
||||||
|
)
|
||||||
lines.append("=" * self.TABLE_WIDTH)
|
lines.append("=" * self.TABLE_WIDTH)
|
||||||
lines.append("")
|
lines.append("")
|
||||||
|
|
||||||
@@ -185,7 +193,7 @@ class MemoryAnalyzerCLI(MemoryAnalyzer):
|
|||||||
|
|
||||||
# Top 15 largest core symbols
|
# Top 15 largest core symbols
|
||||||
lines.append("")
|
lines.append("")
|
||||||
lines.append("Top 15 Largest [esphome]core Symbols:")
|
lines.append(f"Top 15 Largest {_COMPONENT_CORE} Symbols:")
|
||||||
sorted_core_symbols = sorted(
|
sorted_core_symbols = sorted(
|
||||||
self._esphome_core_symbols, key=lambda x: x[2], reverse=True
|
self._esphome_core_symbols, key=lambda x: x[2], reverse=True
|
||||||
)
|
)
|
||||||
@@ -199,10 +207,12 @@ class MemoryAnalyzerCLI(MemoryAnalyzer):
|
|||||||
esphome_components = [
|
esphome_components = [
|
||||||
(name, mem)
|
(name, mem)
|
||||||
for name, mem in components
|
for name, mem in components
|
||||||
if name.startswith("[esphome]") and name != "[esphome]core"
|
if name.startswith(_COMPONENT_PREFIX_ESPHOME) and name != _COMPONENT_CORE
|
||||||
]
|
]
|
||||||
external_components = [
|
external_components = [
|
||||||
(name, mem) for name, mem in components if name.startswith("[external]")
|
(name, mem)
|
||||||
|
for name, mem in components
|
||||||
|
if name.startswith(_COMPONENT_PREFIX_EXTERNAL)
|
||||||
]
|
]
|
||||||
|
|
||||||
top_esphome_components = sorted(
|
top_esphome_components = sorted(
|
||||||
@@ -217,7 +227,7 @@ class MemoryAnalyzerCLI(MemoryAnalyzer):
|
|||||||
# Check if API component exists and ensure it's included
|
# Check if API component exists and ensure it's included
|
||||||
api_component = None
|
api_component = None
|
||||||
for name, mem in components:
|
for name, mem in components:
|
||||||
if name == "[esphome]api":
|
if name == _COMPONENT_API:
|
||||||
api_component = (name, mem)
|
api_component = (name, mem)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user