Skip to content

Commit

Permalink
mm/dump: pretty the log and thin dump call
Browse files Browse the repository at this point in the history
Signed-off-by: buxiasen <[email protected]>
  • Loading branch information
jasonbu authored and GUIDINGLI committed Oct 8, 2024
1 parent fb176c0 commit 8def44b
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 88 deletions.
138 changes: 87 additions & 51 deletions mm/mm_heap/mm_memdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@
* Private Types
****************************************************************************/

#if CONFIG_MM_HEAP_BIGGEST_COUNT > 0
struct mm_memdump_priv_s
{
FAR const struct mm_memdump_s *dump;
struct mallinfo_task info;
#if CONFIG_MM_HEAP_BIGGEST_COUNT > 0
FAR struct mm_allocnode_s *node[CONFIG_MM_HEAP_BIGGEST_COUNT];
size_t filled;
};
#else
struct mm_memdump_priv_s
{
FAR const struct mm_memdump_s *dump;
};
#endif
};

/****************************************************************************
* Private Functions
Expand Down Expand Up @@ -126,10 +122,35 @@ static void memdump_dump_biggestnodes(FAR struct mm_memdump_priv_s *priv)
size_t i;
for (i = 0; i < priv->filled; i++)
{
priv->info.uordblks += MM_SIZEOF_NODE(priv->node[i]);
memdump_allocnode(priv->node[i]);
}

priv->info.aordblks = priv->filled;
}

#endif

#ifdef CONFIG_MM_HEAP_MEMPOOL
static inline_function
void memdump_info_pool(FAR struct mm_memdump_priv_s *priv,
FAR struct mm_heap_s *heap)
{
priv->info = mempool_multiple_info_task(heap->mm_mpool, priv->dump);
}

static inline_function
void memdump_dump_pool(FAR struct mm_memdump_priv_s *priv,
FAR struct mm_heap_s *heap)
{
if (priv->info.aordblks > 0)
{
mempool_multiple_memdump(heap->mm_mpool, priv->dump);
}
}
#else
# define memdump_info_pool(priv,heap)
# define memdump_dump_pool(priv,heap)
#endif

static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
Expand All @@ -144,6 +165,8 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
if ((MM_DUMP_ASSIGN(dump, node) || MM_DUMP_ALLOC(dump, node) ||
MM_DUMP_LEAK(dump, node)) && MM_DUMP_SEQNO(dump, node))
{
priv->info.aordblks++;
priv->info.uordblks += nodesize;
memdump_allocnode(node);
}
else if(dump->pid == PID_MM_ORPHAN && MM_DUMP_SEQNO(dump, node))
Expand All @@ -152,6 +175,8 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
((FAR char *)node + nodesize);
if (MM_PREVNODE_IS_FREE(node) || MM_NODE_IS_FREE(next))
{
priv->info.aordblks++;
priv->info.uordblks += nodesize;
memdump_allocnode(node);
}
}
Expand All @@ -175,6 +200,8 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
MM_SIZEOF_NODE(fnode->flink) == 0 ||
MM_SIZEOF_NODE(fnode->flink) >= nodesize);

priv->info.aordblks++;
priv->info.uordblks += nodesize;
syslog(LOG_INFO, "%12zu%*p\n",
nodesize, BACKTRACE_PTR_FMT_WIDTH,
((FAR char *)node + MM_SIZEOF_ALLOCNODE));
Expand All @@ -200,75 +227,84 @@ void mm_memdump(FAR struct mm_heap_s *heap,
FAR const struct mm_memdump_s *dump)
{
struct mm_memdump_priv_s priv;
struct mallinfo_task info;
pid_t pid = dump->pid;

info = mm_mallinfo_task(heap, dump);
memset(&priv, 0, sizeof(struct mm_memdump_priv_s));
priv.dump = dump;

if (info.aordblks == 0 && dump->pid >= PID_MM_FREE)
if (pid == PID_MM_MEMPOOL)
{
return;
syslog(LOG_INFO, "Memdump mempool\n");
}

if (dump->pid >= PID_MM_ALLOC)
else if (pid == PID_MM_LEAK)
{
syslog(LOG_INFO, "Dump all used memory node info:\n");
#if CONFIG_MM_BACKTRACE < 0
syslog(LOG_INFO, "%12s%*s\n", "Size", BACKTRACE_PTR_FMT_WIDTH,
"Address");
#else
syslog(LOG_INFO, "%6s%12s%12s%*s %s\n", "PID", "Size", "Sequence",
BACKTRACE_PTR_FMT_WIDTH, "Address", "Backtrace");
#endif
syslog(LOG_INFO, "Memdump leak\n");
memdump_info_pool(&priv, heap);
}
else if (dump->pid == PID_MM_FREE)
else if (pid == PID_MM_ALLOC || pid >= 0)
{
FAR struct tcb_s *tcb = NULL;
FAR const char *name;

if (pid == PID_MM_ALLOC)
{
name = "ALL";
}
else
{
name = "Unkown";
tcb = nxsched_get_tcb(pid);
}

if (tcb == NULL)
{
syslog(LOG_INFO, "Memdump task %s\n", name);
}
else
{
name = get_task_name(tcb);
syslog(LOG_INFO, "Memdump task stack_alloc_ptr: %p,"
" adj_stack_size: %zu, name: %s\n",
tcb->stack_alloc_ptr, tcb->adj_stack_size, name);
}

memdump_info_pool(&priv, heap);
}
else if (pid == PID_MM_FREE)
{
syslog(LOG_INFO, "Dump all free memory node info:\n");
syslog(LOG_INFO, "%12s%*s\n", "Size", BACKTRACE_PTR_FMT_WIDTH,
"Address");
syslog(LOG_INFO, "Dump all free memory node info\n");
memdump_info_pool(&priv, heap);
}
#if CONFIG_MM_HEAP_BIGGEST_COUNT > 0
else if (dump->pid == PID_MM_BIGGEST)
else if (pid == PID_MM_BIGGEST)
{
syslog(LOG_INFO, "Memdump biggest allocated top %d\n",
CONFIG_MM_HEAP_BIGGEST_COUNT);
# if CONFIG_MM_BACKTRACE < 0
syslog(LOG_INFO, "%12s%*s\n", "Size", BACKTRACE_PTR_FMT_WIDTH,
"Address");
# else
syslog(LOG_INFO, "%6s%12s%12s%*s %s\n", "PID", "Size", "Sequence",
BACKTRACE_PTR_FMT_WIDTH, "Address", "Backtrace");
# endif
}
#endif
else if (dump->pid == PID_MM_ORPHAN)
else if (pid == PID_MM_ORPHAN)
{
syslog(LOG_INFO, "Dump allocated orphan nodes\n");
# if CONFIG_MM_BACKTRACE < 0
syslog(LOG_INFO, "%12s%*s\n", "Size", BACKTRACE_PTR_FMT_WIDTH,
"Address");
# else
syslog(LOG_INFO, "%6s%12s%12s%*s %s\n", "PID", "Size", "Sequence",
BACKTRACE_PTR_FMT_WIDTH, "Address", "Backtrace");
# endif
}

#ifdef CONFIG_MM_HEAP_MEMPOOL
mempool_multiple_memdump(heap->mm_mpool, dump);
#if CONFIG_MM_BACKTRACE < 0
syslog(LOG_INFO, "%12s%*s\n", "Size", BACKTRACE_PTR_FMT_WIDTH, "Address");
#else
syslog(LOG_INFO, "%6s%12s%12s%*s %s\n", "PID", "Size", "Sequence",
BACKTRACE_PTR_FMT_WIDTH, "Address", "Backtrace");
#endif
memset(&priv, 0, sizeof(struct mm_memdump_priv_s));
priv.dump = dump;

memdump_dump_pool(&priv, heap);

mm_foreach(heap, memdump_handler, &priv);

if (dump->pid == PID_MM_FREE)
{
syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
syslog(LOG_INFO, "%12d%12d\n", info.aordblks, info.uordblks);
}
#if CONFIG_MM_HEAP_BIGGEST_COUNT > 0
else if (dump->pid == PID_MM_BIGGEST)
if (pid == PID_MM_BIGGEST)
{
memdump_dump_biggestnodes(&priv);
}
#endif

syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
syslog(LOG_INFO, "%12d%12d\n", priv.info.aordblks, priv.info.uordblks);
}
Loading

0 comments on commit 8def44b

Please sign in to comment.