You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/07/26 15:45:38 UTC

[incubator-nuttx] 01/02: mm/mm_heap: output memory info about each task

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 8a1e985e71bcd637ead1035c4fee9bd54bef924c
Author: Jiuzhu Dong <do...@xiaomi.com>
AuthorDate: Thu Jun 2 13:44:14 2022 +0800

    mm/mm_heap: output memory info about each task
    
    Signed-off-by: Jiuzhu Dong <do...@xiaomi.com>
---
 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 <nuttx/arch.h>
 #include <nuttx/mm/mm.h>
+#include <nuttx/sched.h>
 
 #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();