Skip to content

Commit ae6e980

Browse files
committed
ESPBufferManager integration
1 parent 64333e5 commit ae6e980

7 files changed

Lines changed: 392 additions & 79 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
55
## [Unreleased]
66
### Added
77
- More ESPMemoryMonitor examples: manual sampling without the background task and a panic-hook sketch that captures a final snapshot.
8+
- `MemoryMonitorConfig::usePSRAMBuffers` to prefer PSRAM for monitor-owned long-lived containers via `ESPBufferManager` with automatic fallback to normal heap.
9+
- Routed additional hot-path transient monitor scratch containers (threshold/task events, task-status capture, scope/tag threshold staging, and window analytics scratch vectors) through the same `ESPBufferManager` policy.
10+
- Added internal/public model separation for history/scope/tag/task/leak state: monitor internals now use PSRAM-policy-aware storage models and convert to existing public API structs at return/callback boundaries.
811
### Fixed
912
- Mark the failed-allocation hook instance pointer as static so Arduino builds compile the callback correctly.
1013

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ESPMemoryMonitor is a tiny C++17 helper that wraps ESP-IDF heap/stack inspection
1717
- Derived insights: windowed min/avg/max, slope-based bytes/second, and time-to-warn/critical estimates per region.
1818
- Task visibility: stack state transitions (`Safe/Warn/Critical`), optional new/vanished task detection, and per-task thresholds.
1919
- Export/panic helpers: convert snapshots to ArduinoJson for telemetry and install a shutdown/panic hook that captures a final snapshot before abort/restart.
20+
- Optional PSRAM-backed monitor-owned buffers via `usePSRAMBuffers` (through `ESPBufferManager`) with automatic fallback to normal heap on non-PSRAM boards, including long-lived state, hot-path transient scratch containers, and internal storage models that are converted to public API structs at boundaries.
2021
- Thread-safe with FreeRTOS mutexes; destructor tears down the sampler task and unregisters callbacks.
2122

2223
## Examples
@@ -44,6 +45,7 @@ void setup() {
4445
cfg.maxScopesInHistory = 16;
4546
cfg.windowStatsSize = 10;
4647
cfg.enableTaskTracking = true;
48+
cfg.usePSRAMBuffers = true; // optional: prefer PSRAM for monitor-owned containers
4749
monitor.init(cfg);
4850

4951
httpTag = monitor.registerTag("http_server");
@@ -163,6 +165,7 @@ serializeJson(doc, Serial);
163165
| `enableTaskTracking` | `false` | Emit stack-state transitions and task create/destroy events (requires `enablePerTaskStacks`). |
164166
| `defaultTaskStackBytes` / `stackWarnFraction` / `stackCriticalFraction` | `4096` / `0.25` / `0.10` | Default stack headroom thresholds when per-task overrides are absent. |
165167
| `leakNoiseBytes` | `1024` | Ignore free-byte changes smaller than this when flagging leak drift between checkpoints. |
168+
| `usePSRAMBuffers` | `false` | Best-effort PSRAM preference for monitor-owned dynamic containers and internal storage models (history/scope/tag/task/leak internals plus transient threshold, scope/tag, window, and task-tracking scratch buffers); automatically falls back to normal heap when PSRAM is unavailable. |
166169

167170
`MemorySnapshot` holds `timestampUs` plus vectors of `RegionStats` (free bytes, low-water, largest block, fragmentation, slope/time estimates, window stats) and optional `TaskStackUsage` entries (task name, priority, state, free high-water bytes).
168171

@@ -171,6 +174,7 @@ serializeJson(doc, Serial);
171174
- `enableFailedAllocEvents` hooks IDF’s global failed-allocation callback; if you already use it elsewhere, coordinate registration to avoid conflicts.
172175
- Threshold hysteresis is byte-based; bump `thresholdHysteresisBytes` if your allocator churns in small bursts.
173176
- Fragmentation is `0` when free bytes are zero; values closer to `1.0` indicate more fragmentation.
177+
- `usePSRAMBuffers` affects monitor-owned container allocations only; callback captures and other external allocations are not redirected.
174178

175179
## Restrictions
176180
- ESP32 + FreeRTOS (Arduino-ESP32 or ESP-IDF) with C++17 enabled.

library.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
{
2727
"name": "ArduinoJson",
2828
"version": "^7.0.0"
29+
},
30+
{
31+
"name": "ESPBufferManager",
32+
"version": "https://github.com/ESPToolKit/esp-buffer-manager.git"
2933
}
3034
],
3135
"headers": ["ESPMemoryMonitor.h"],

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ category=Data Processing
88
url=https://github.com/ESPToolKit/esp-memoryMonitor
99
repository=https://github.com/ESPToolKit/esp-memoryMonitor.git
1010
architectures=esp32
11-
depends=ArduinoJson@^7
11+
depends=ArduinoJson@^7,ESPBufferManager
1212
license=MIT

0 commit comments

Comments
 (0)