From 2dedaa449bee27e6795ef50c8d286d099343f5e4 Mon Sep 17 00:00:00 2001 From: wangbowen6 Date: Wed, 10 May 2023 22:13:20 +0800 Subject: [PATCH] mm: use shced_backtrace and skip the first numbers in mm backatrace beacause the first numbers backtrace in mm node is same, skip them to show more useful backtrace. Signed-off-by: wangbowen6 --- mm/Kconfig | 12 ++++++++++++ mm/mempool/mempool.c | 5 +++-- mm/mm_heap/mm.h | 4 ++-- mm/tlsf/mm_tlsf.c | 5 +++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/mm/Kconfig b/mm/Kconfig index 625983b92b..a2af336f7d 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -228,6 +228,13 @@ config MM_HEAP_MEMPOOL_CHUNK_SIZE ---help--- This size describes the multiple mempool chunk size. +config MM_HEAP_MEMPOOL_BACKTRACE_SKIP + int "The skip depth of backtrace for mempool" + default 6 + depends on MM_HEAP_MEMPOOL_THRESHOLD != 0 && MM_BACKTRACE > 0 + ---help--- + This number is the skipped backtrace depth for mempool. + config FS_PROCFS_EXCLUDE_MEMPOOL bool "Exclude mempool" default DEFAULT_SMALL @@ -304,6 +311,11 @@ config MM_BACKTRACE config: disable backtrace by -1, only record pid info by zero and enable record backtrace info by 8(fixed depth). +config MM_BACKTRACE_SKIP + int "The skip depth of backtrace" + depends on MM_BACKTRACE > 0 + default 3 + config MM_BACKTRACE_DEFAULT bool "Enable the backtrace record by default" default n diff --git a/mm/mempool/mempool.c b/mm/mempool/mempool.c index 55fdcc7f67..47d851349c 100644 --- a/mm/mempool/mempool.c +++ b/mm/mempool/mempool.c @@ -23,7 +23,6 @@ ****************************************************************************/ #include -#include #include #include #include @@ -94,7 +93,9 @@ static inline void mempool_add_backtrace(FAR struct mempool_s *pool, # if CONFIG_MM_BACKTRACE > 0 if (pool->procfs.backtrace) { - int result = backtrace(buf->backtrace, CONFIG_MM_BACKTRACE); + int result = sched_backtrace(buf->pid, buf->backtrace, + CONFIG_MM_BACKTRACE, + CONFIG_MM_HEAP_MEMPOOL_BACKTRACE_SKIP); if (result < CONFIG_MM_BACKTRACE) { buf->backtrace[result] = NULL; diff --git a/mm/mm_heap/mm.h b/mm/mm_heap/mm.h index b3a438bc75..30e3c55ec0 100644 --- a/mm/mm_heap/mm.h +++ b/mm/mm_heap/mm.h @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -89,7 +88,8 @@ tcb = nxsched_get_tcb(tmp->pid); \ if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) \ { \ - int n = backtrace(tmp->backtrace, CONFIG_MM_BACKTRACE); \ + int n = sched_backtrace(tmp->pid, tmp->backtrace, CONFIG_MM_BACKTRACE, \ + CONFIG_MM_BACKTRACE_SKIP); \ if (n < CONFIG_MM_BACKTRACE) \ { \ tmp->backtrace[n] = NULL; \ diff --git a/mm/tlsf/mm_tlsf.c b/mm/tlsf/mm_tlsf.c index fbea79708d..30de861a39 100644 --- a/mm/tlsf/mm_tlsf.c +++ b/mm/tlsf/mm_tlsf.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -150,7 +149,9 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap, if (heap->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) { - int ret = backtrace(buf->backtrace, CONFIG_MM_BACKTRACE); + int ret = sched_backtrace(buf->pid, buf->backtrace, + CONFIG_MM_BACKTRACE, + CONFIG_MM_BACKTRACE_SKIP); if (ret < CONFIG_MM_BACKTRACE) { buf->backtrace[ret] = NULL;