Flatten mem stats

This commit is contained in:
cpq committed 2026-11-10 11:21:36 +00:00
1 parent de037d6ef9
commit 069024b41c
17 files changed
+347 -260

No files matched your search

+9 -5
View File
@@ -6,13 +6,17 @@
size_t mg_usage(int task, int metric) {
extern void *_sbrk(int incr);
extern unsigned char _end[], _estack[];
if (metric == MG_USAGE_NUM_TASKS) return 1;
if (metric == MG_USAGE_TASK_NAME) return task == 0 ? (size_t) "main" : 0;
// Heap and stack share the free gap, neither has a fixed total
if (metric == MG_USAGE_HEAP_FREE ||
(metric == MG_USAGE_STACK_FREE && task == 0)) {
size_t sp = (size_t) __get_MSP(), heap = (size_t) _sbrk(0);
return sp > heap ? sp - heap : 0;
// Heap and stack share RAM, so neither has a fixed total.
if (metric == MG_USAGE_HEAP_USED) {
size_t heap = (size_t) _sbrk(0), start = (size_t) _end;
return heap >= start && heap <= (size_t) _estack ? heap - start : 0;
}
if (metric == MG_USAGE_STACK_USED && task == 0) {
size_t sp = (size_t) __get_MSP(), top = (size_t) _estack;
return sp <= top ? top - sp : 0;
}
return 0;
}