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 <wangbowen6@xiaomi.com>
This commit is contained in:
wangbowen6 2023-05-10 22:13:20 +08:00 committed by Xiang Xiao
parent c9e3a0669f
commit 2dedaa449b
4 changed files with 20 additions and 6 deletions

View File

@ -228,6 +228,13 @@ config MM_HEAP_MEMPOOL_CHUNK_SIZE
---help--- ---help---
This size describes the multiple mempool chunk size. 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 config FS_PROCFS_EXCLUDE_MEMPOOL
bool "Exclude mempool" bool "Exclude mempool"
default DEFAULT_SMALL default DEFAULT_SMALL
@ -304,6 +311,11 @@ config MM_BACKTRACE
config: disable backtrace by -1, only record pid info by zero and config: disable backtrace by -1, only record pid info by zero and
enable record backtrace info by 8(fixed depth). 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 config MM_BACKTRACE_DEFAULT
bool "Enable the backtrace record by default" bool "Enable the backtrace record by default"
default n default n

View File

@ -23,7 +23,6 @@
****************************************************************************/ ****************************************************************************/
#include <assert.h> #include <assert.h>
#include <execinfo.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <syslog.h> #include <syslog.h>
@ -94,7 +93,9 @@ static inline void mempool_add_backtrace(FAR struct mempool_s *pool,
# if CONFIG_MM_BACKTRACE > 0 # if CONFIG_MM_BACKTRACE > 0
if (pool->procfs.backtrace) 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) if (result < CONFIG_MM_BACKTRACE)
{ {
buf->backtrace[result] = NULL; buf->backtrace[result] = NULL;

View File

@ -34,7 +34,6 @@
#include <nuttx/mm/mempool.h> #include <nuttx/mm/mempool.h>
#include <assert.h> #include <assert.h>
#include <execinfo.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
@ -89,7 +88,8 @@
tcb = nxsched_get_tcb(tmp->pid); \ tcb = nxsched_get_tcb(tmp->pid); \
if ((heap)->mm_procfs.backtrace || (tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) \ 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) \ if (n < CONFIG_MM_BACKTRACE) \
{ \ { \
tmp->backtrace[n] = NULL; \ tmp->backtrace[n] = NULL; \

View File

@ -28,7 +28,6 @@
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <debug.h> #include <debug.h>
#include <execinfo.h>
#include <sched.h> #include <sched.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@ -150,7 +149,9 @@ static void memdump_backtrace(FAR struct mm_heap_s *heap,
if (heap->mm_procfs.backtrace || if (heap->mm_procfs.backtrace ||
(tcb && tcb->flags & TCB_FLAG_HEAP_DUMP)) (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) if (ret < CONFIG_MM_BACKTRACE)
{ {
buf->backtrace[ret] = NULL; buf->backtrace[ret] = NULL;