memdump: support dump the leak memory (malloced but task exit)

1. command "memdump leak" can dump the leacked memory node;
2. fix the leak memory stat bug in memory manager;

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
This commit is contained in:
wangbowen6 2023-05-26 17:17:19 +08:00 committed by Xiang Xiao
parent 1fb65e18d2
commit b0ab41beee
5 changed files with 35 additions and 38 deletions

View File

@ -56,7 +56,7 @@
* to handle the longest line generated by this logic.
*/
#define MEMINFO_LINELEN 80
#define MEMINFO_LINELEN 256
/****************************************************************************
* Private Types
@ -404,7 +404,6 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer,
FAR struct meminfo_file_s *procfile;
size_t linesize;
size_t copysize;
size_t totalsize;
off_t offset;
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
@ -419,41 +418,26 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer,
#if CONFIG_MM_BACKTRACE >= 0
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
"usage: <pid/used/free/on/off>"
"<seqmin> <seqmax> \n"
"usage: <on/off/pid/used/free/leak>"
"<seqmin> <seqmax>\n"
"on/off backtrace\n"
"pid: dump pid allocated node\n");
"pid: dump pid allocated node\n"
"used: dump all allocated node\n"
"free: dump all free node\n"
"leak: dump all leaked node\n"
"The current sequence number %lu\n",
g_mm_seqno);
#else
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
"usage: <used/free>\n");
"usage: <used/free>\n"
"used: dump all allocated node\n"
"free: dump all free node\n");
#endif
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
&offset);
totalsize = copysize;
buffer += copysize;
buflen -= copysize;
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
"used: dump all allocated node\n"
"free: dump all free node\n");
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
&offset);
totalsize += copysize;
#if CONFIG_MM_BACKTRACE >= 0
buffer += copysize;
buflen -= copysize;
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
"The current sequence number %lu\n",
g_mm_seqno);
totalsize += procfs_memcpy(procfile->line, linesize, buffer, buflen,
&offset);
#endif
filep->f_pos += totalsize;
return totalsize;
filep->f_pos += copysize;
return copysize;
}
#endif
@ -556,6 +540,16 @@ static ssize_t memdump_write(FAR struct file *filep, FAR const char *buffer,
goto dump;
#endif
break;
case 'l':
dump.pid = PID_MM_LEAK;
#if CONFIG_MM_BACKTRACE >= 0
p = (FAR char *)buffer + 4;
goto dump;
#endif
break;
#if CONFIG_MM_BACKTRACE >= 0
default:
if (!isdigit(buffer[0]))

View File

@ -427,7 +427,7 @@ mempool_info_task(FAR struct mempool_s *pool,
node)
{
if ((task->pid == buf->pid || task->pid == PID_MM_ALLOC ||
(task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
(task->pid == PID_MM_LEAK && !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
{
info.aordblks++;
@ -490,7 +490,7 @@ void mempool_memdump(FAR struct mempool_s *pool,
struct mempool_backtrace_s, node)
{
if ((dump->pid == buf->pid || dump->pid == PID_MM_ALLOC ||
(dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
(dump->pid == PID_MM_LEAK && !nxsched_get_tcb(buf->pid))) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
{
char tmp[CONFIG_MM_BACKTRACE * MM_PTR_FMT_WIDTH + 1] = "";

View File

@ -106,7 +106,8 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
#else
if ((task->pid == node->pid ||
(task->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
(task->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
(task->pid == PID_MM_LEAK && node->pid >= 0 &&
!nxsched_get_tcb(node->pid))) &&
node->seqno >= task->seqmin && node->seqno <= task->seqmax)
{
info->aordblks++;

View File

@ -61,9 +61,9 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
#if CONFIG_MM_BACKTRACE < 0
if (dump->pid == PID_MM_ALLOC)
#else
if ((dump->pid == node->pid ||
(dump->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
(dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
if ((dump->pid == node->pid || dump->pid == PID_MM_ALLOC ||
(dump->pid == PID_MM_LEAK && node->pid >= 0 &&
!nxsched_get_tcb(node->pid))) &&
node->seqno >= dump->seqmin && node->seqno <= dump->seqmax)
#endif
{

View File

@ -299,7 +299,8 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
if ((task->pid == buf->pid ||
(task->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
(task->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
(task->pid == PID_MM_LEAK && buf->pid >= 0 &&
!nxsched_get_tcb(buf->pid))) &&
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
{
info->aordblks++;
@ -412,7 +413,8 @@ static void memdump_handler(FAR void *ptr, size_t size, int used,
if ((dump->pid == buf->pid ||
(dump->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
(dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(buf->pid))) &&
(dump->pid == PID_MM_LEAK && buf->pid >= 0 &&
!nxsched_get_tcb(buf->pid))) &&
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
#endif
{