docs(evidence): complete M1-008 artifacts and draft owner pass record (#9)

## Summary

Completes the remaining M1-008 evidence gaps and drafts the owner pass
record (requirement **M1-008**; heap/stack instrumentation also closes
the M1-006 soak heap-integrity note "internal_free not evaluable").

### Firmware: `metrics` console command (console_service.{cc,hh})
- Machine-parseable `heap internal|psram free=<u> largest=<u>
min_ever=<u>` (heap_caps 8-bit pools) and `task <name>
stack_hwm_bytes=<u>` per FreeRTOS task via `uxTaskGetSystemState` (all
tasks: frame-sd/board/display/prov-mon/console_repl/IDLE/ipc/Tmr
Svc/esp_timer/wifi/tcpip/sys_evt).
- ESP-IDF Xtensa reports the high-water mark directly in bytes
(`StackType_t` = uint8_t), so the unit is documented in the field name
itself.
- Companion one-line sdkconfig change:
`CONFIG_FREERTOS_USE_TRACE_FACILITY=y` (required for
`uxTaskGetSystemState`; necessary build-config companion to the mandated
API).
- No JSONL/display/snapshot changes; no new files; partitions untouched;
clang-format 18.1.8 clean; build 0 warnings.

### Evidence (poc/evidence/m1-20260831/)
- `build/m1_frame_m1_hardware.map` — linker map of the instrumented
build (binary sha256 a0e937ba… pinned in the manifest note).
- `build/m1_size_components.txt` — `idf.py size` summary + `idf.py
size-components` breakdown.
- `build/m1_metrics_samples.txt` — three on-device samples (t≈14 s
boot-ish / post-selftest / post-60 s-idle) + selftest + status --json.
Highlights: internal heap min_ever 123295 B (largest block 53248 B),
PSRAM min_ever 8362016 B, smallest task stack HWM ipc0 552 B,
console_repl 2652 B free of 6144 B, idle drift ~36 B/min.
- `M1-PASS-RECORD.md` — completeness table for every M1-008 artifact
(path+sha256), M1-001..007 one-line acceptance summary, known
limitations; **ships PENDING owner confirmation, does not record Pass**.
- manifest.json: 3 artifact entries (+notes); .gitignore: re-include
`poc/evidence/**/build/` (map/size/metrics), same mechanism as the
existing `!poc/evidence/**/*.log`.

## Requirement refs
- M1-008 (pass-record artifacts: linker map, size-components, heap/stack
metrics, owner record draft)
- M1-006 (heap-integrity: heap free/largest/min-ever + per-task stack
HWM now instrumented)

## Gates
Build 0 warnings (clean rebuild, evidence-logged); ruff format/check,
pyright (0 errors), pytest 31 passed 1 skipped, frame-evidence validated
(1 manifest, 47 artifacts).

Co-authored-by: ania-lain <[email protected]>
This commit is contained in:
Lain
2026-08-31 18:10:32 +08:00
committed by GitHub
co-authored by lain
parent 61a01671cb
commit e8ac2c1c5d
10 changed files with 139327 additions and 1 deletions
@@ -7,6 +7,9 @@
#include "board_config.hh"
#include "esp_console.h"
#include "esp_heap_caps.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "linenoise/linenoise.h"
namespace frame::m1 {
@@ -97,6 +100,15 @@ esp_err_t console_service::start() {
.func_w_context = nullptr,
.context = nullptr,
};
const esp_console_cmd_t metrics_cmd{
.command = "metrics",
.help = "Heap free/largest/min_ever (internal+PSRAM) and per-task stack high-water marks",
.hint = nullptr,
.func = &console_service::metrics_command,
.argtable = nullptr,
.func_w_context = nullptr,
.context = nullptr,
};
esp_err_t result = esp_console_cmd_register(&status_cmd);
if (result == ESP_OK) {
@@ -114,6 +126,9 @@ esp_err_t console_service::start() {
if (result == ESP_OK) {
result = esp_console_cmd_register(&rtc_cmd);
}
if (result == ESP_OK) {
result = esp_console_cmd_register(&metrics_cmd);
}
if (result != ESP_OK) {
return result;
}
@@ -263,6 +278,48 @@ int console_service::rtc_command(int argc, char** argv) {
return 1;
}
int console_service::metrics_command(int argc, char** argv) {
if (argc != 1) {
std::printf("usage: metrics\n");
return 1;
}
instance_->print_metrics();
return 0;
}
void console_service::print_metrics() const {
constexpr uint32_t kInternalCaps = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT;
std::printf("heap internal free=%u largest=%u min_ever=%u\n",
static_cast<unsigned>(heap_caps_get_free_size(kInternalCaps)),
static_cast<unsigned>(heap_caps_get_largest_free_block(kInternalCaps)),
static_cast<unsigned>(heap_caps_get_minimum_free_size(kInternalCaps)));
constexpr uint32_t kPsramCaps = MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT;
std::printf("heap psram free=%u largest=%u min_ever=%u\n",
static_cast<unsigned>(heap_caps_get_free_size(kPsramCaps)),
static_cast<unsigned>(heap_caps_get_largest_free_block(kPsramCaps)),
static_cast<unsigned>(heap_caps_get_minimum_free_size(kPsramCaps)));
const UBaseType_t task_slots = uxTaskGetNumberOfTasks() + 4U;
TaskStatus_t* tasks = static_cast<TaskStatus_t*>(
heap_caps_malloc(sizeof(TaskStatus_t) * task_slots, kInternalCaps));
if (tasks == nullptr) {
std::printf("task snapshot: allocation failed\n");
return;
}
const UBaseType_t task_count = uxTaskGetSystemState(tasks, task_slots, nullptr);
if (task_count == 0U) {
std::printf("task snapshot: task set changed, retry the command\n");
heap_caps_free(tasks);
return;
}
for (UBaseType_t index = 0; index < task_count; ++index) {
const unsigned hwm_bytes = static_cast<unsigned>(tasks[index].usStackHighWaterMark) *
static_cast<unsigned>(sizeof(StackType_t));
std::printf("task %s stack_hwm_bytes=%u\n", tasks[index].pcTaskName, hwm_bytes);
}
heap_caps_free(tasks);
}
void console_service::print_rtc_status() const {
const status_snapshot value = status_.snapshot();
std::printf("RTC: %s\n", value.rtc_present ? "present (PCF85063 @0x51)" : "missing (0x51)");
@@ -25,8 +25,10 @@ class console_service {
static int selftest_command(int argc, char** argv);
static int prov_command(int argc, char** argv);
static int rtc_command(int argc, char** argv);
static int metrics_command(int argc, char** argv);
void print_status(bool json) const;
void print_rtc_status() const;
void print_metrics() const;
int print_rtc_raw() const;
int run_rtc_set(const char* date_text, const char* time_text);
void run_wifi_config_selftest() const;