Files
led-driver/src/mem_stats.py
T
jimmyandCursor 55a97ac51c feat(patterns): merge pattern styles and add mode support
Consolidate legacy pattern ids into meteor, particles, sparkle, chase,
and colour_cycle with n6/mode style selection; add pattern_modes helper,
self-contained tests/all.py, and preset mode alias on wire.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-16 21:14:54 +12:00

35 lines
985 B
Python

"""GC / heap snapshot helpers for debug logging."""
import gc
def snapshot():
"""Return a dict of memory stats after ``gc.collect()``."""
gc.collect()
out = {
"free": gc.mem_free(),
"alloc": gc.mem_alloc(),
}
try:
import esp32
blocks = esp32.idf_heap_info(esp32.HEAP_DATA)
if blocks:
block = blocks[0]
if isinstance(block, dict):
if "total_free_bytes" in block:
out["idf_free"] = block["total_free_bytes"]
largest = block.get("largest_free_block")
if largest is None:
largest = block.get("largest_free_block_in_bytes")
if largest is not None:
out["idf_largest"] = largest
except Exception:
pass
return out
def print_mem(label):
"""Print one timestamped memory line (via ``print_timestamp`` when installed)."""
print("mem %s:" % label, snapshot())