From 8a1e985e71bcd637ead1035c4fee9bd54bef924c Mon Sep 17 00:00:00 2001 From: Jiuzhu Dong Date: Thu, 2 Jun 2022 13:44:14 +0800 Subject: [PATCH] mm/mm_heap: output memory info about each task Signed-off-by: Jiuzhu Dong --- mm/mm_heap/mm_malloc.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/mm_heap/mm_malloc.c b/mm/mm_heap/mm_malloc.c index 1d8d6b24bc..d2d8a2647f 100644 --- a/mm/mm_heap/mm_malloc.c +++ b/mm/mm_heap/mm_malloc.c @@ -31,6 +31,7 @@ #include #include +#include #include "mm_heap/mm.h" #include "kasan/kasan.h" @@ -82,6 +83,18 @@ static void mm_free_delaylist(FAR struct mm_heap_s *heap) #endif } +#ifdef CONFIG_MM_BACKTRACE +void mm_dump_handler(FAR struct tcb_s *tcb, FAR void *arg) +{ + struct mallinfo_task info; + + info.pid = tcb->pid; + mm_mallinfo_task(arg, &info); + mwarn("pid:%5d, used:%10d, nused:%10d\n", + tcb->pid, info.uordblks, info.aordblks); +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -254,7 +267,9 @@ FAR void *mm_malloc(FAR struct mm_heap_s *heap, size_t size) mwarn("Total:%d, used:%d, free:%d, largest:%d, nused:%d, nfree:%d\n", minfo.arena, minfo.uordblks, minfo.fordblks, minfo.mxordblk, minfo.aordblks, minfo.ordblks); - mm_memdump(heap, -1); +# ifdef CONFIG_MM_BACKTRACE + nxsched_foreach(mm_dump_handler, heap); +# endif #endif #ifdef CONFIG_MM_PANIC_ON_FAILURE PANIC();