Add initial stack/heap reporting for mdash

This commit is contained in:
robert committed 2026-10-23 11:39:12 +03:00
1 parent 38c326644f
commit 2bddebc6f0
8 files changed
+61 -11

No files matched your search

+5 -5
View File
@@ -43,15 +43,15 @@ __attribute__((weak)) int _fstat(int fd, struct stat *st) {
}
extern unsigned char _end[]; // End of data section, start of heap. See link.ld
extern unsigned char _estack[]; // Initial stack pointer. See link.ld
static unsigned char *s_current_heap_end = _end;
size_t hal_ram_used(void) {
return (size_t) (s_current_heap_end - _end);
size_t hal_get_heap(void) {
return (size_t) ((uintptr_t) s_current_heap_end - (uintptr_t) _end);
}
size_t hal_ram_free(void) {
unsigned char endofstack;
return (size_t) (&endofstack - s_current_heap_end);
size_t hal_get_stack(void) {
return (size_t) ((uintptr_t) _estack - (uintptr_t) __get_MSP());
}
void *_sbrk(int incr) {
+2 -2
View File
@@ -15,8 +15,8 @@
extern bool hal_timer_expired(volatile uint64_t *t, uint64_t prd, uint64_t now);
extern uint64_t hal_get_tick(void);
extern size_t hal_ram_free(void);
extern size_t hal_ram_used(void);
extern size_t hal_get_heap(void); // Heap bytes reserved through _sbrk()
extern size_t hal_get_stack(void); // Stack bytes currently used (MSP)
extern uint32_t SystemCoreClock;
#define BIT(x) (1UL << (x))
+4 -4
View File
@@ -78,9 +78,9 @@ static void http_ev_handler(struct mg_connection *c, int ev, void *ev_data) {
mg_http_reply(c, 200, "",
"Hi from Mongoose!\n"
"tick: %llu\n"
"ram used: %zu\n"
"ram free: %zu\n",
hal_get_tick(), hal_ram_used(), hal_ram_free());
"heap used: %zu\n"
"stack used: %zu\n",
hal_get_tick(), hal_get_heap(), hal_get_stack());
}
}
}
@@ -103,7 +103,7 @@ int main(void) {
mg_http_listen(&mgr, "https://0.0.0.0", http_ev_handler, NULL);
MG_INFO(("Initialised. CPU clock: %lu MHz", SystemCoreClock / 1000000));
MG_INFO(("RAM used: %zu, free: %zu", hal_ram_used(), hal_ram_free()));
MG_INFO(("Heap used: %zu, stack used: %zu", hal_get_heap(), hal_get_stack()));
MG_INFO(("Crash record: %M", mg_print_crash_record));
for (;;) {
@@ -28,6 +28,8 @@
// Crash report support. Health record lives in the .mg_health region, see link.ld
#define MG_ENABLE_HEALTH 1
#define MG_HEALTH_HEAP_USED hal_get_heap()
#define MG_HEALTH_STACK_USED hal_get_stack()
// mdash.net device management service support
#define MG_ENABLE_MDASH 0