mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 11:56:10 +08:00
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:
@@ -56,7 +56,7 @@
|
|||||||
* to handle the longest line generated by this logic.
|
* to handle the longest line generated by this logic.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MEMINFO_LINELEN 80
|
#define MEMINFO_LINELEN 256
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
@@ -404,7 +404,6 @@ static ssize_t memdump_read(FAR struct file *filep, FAR char *buffer,
|
|||||||
FAR struct meminfo_file_s *procfile;
|
FAR struct meminfo_file_s *procfile;
|
||||||
size_t linesize;
|
size_t linesize;
|
||||||
size_t copysize;
|
size_t copysize;
|
||||||
size_t totalsize;
|
|
||||||
off_t offset;
|
off_t offset;
|
||||||
|
|
||||||
finfo("buffer=%p buflen=%d\n", buffer, (int)buflen);
|
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
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
|
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
|
||||||
"usage: <pid/used/free/on/off>"
|
"usage: <on/off/pid/used/free/leak>"
|
||||||
"<seqmin> <seqmax> \n"
|
"<seqmin> <seqmax>\n"
|
||||||
"on/off backtrace\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
|
#else
|
||||||
linesize = procfs_snprintf(procfile->line, MEMINFO_LINELEN,
|
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
|
#endif
|
||||||
|
|
||||||
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
|
copysize = procfs_memcpy(procfile->line, linesize, buffer, buflen,
|
||||||
&offset);
|
&offset);
|
||||||
totalsize = copysize;
|
filep->f_pos += copysize;
|
||||||
buffer += copysize;
|
return 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;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -556,6 +540,16 @@ static ssize_t memdump_write(FAR struct file *filep, FAR const char *buffer,
|
|||||||
goto dump;
|
goto dump;
|
||||||
#endif
|
#endif
|
||||||
break;
|
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
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
default:
|
default:
|
||||||
if (!isdigit(buffer[0]))
|
if (!isdigit(buffer[0]))
|
||||||
|
|||||||
@@ -427,7 +427,7 @@ mempool_info_task(FAR struct mempool_s *pool,
|
|||||||
node)
|
node)
|
||||||
{
|
{
|
||||||
if ((task->pid == buf->pid || task->pid == PID_MM_ALLOC ||
|
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)
|
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
|
||||||
{
|
{
|
||||||
info.aordblks++;
|
info.aordblks++;
|
||||||
@@ -490,7 +490,7 @@ void mempool_memdump(FAR struct mempool_s *pool,
|
|||||||
struct mempool_backtrace_s, node)
|
struct mempool_backtrace_s, node)
|
||||||
{
|
{
|
||||||
if ((dump->pid == buf->pid || dump->pid == PID_MM_ALLOC ||
|
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)
|
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
|
||||||
{
|
{
|
||||||
char tmp[CONFIG_MM_BACKTRACE * MM_PTR_FMT_WIDTH + 1] = "";
|
char tmp[CONFIG_MM_BACKTRACE * MM_PTR_FMT_WIDTH + 1] = "";
|
||||||
|
|||||||
@@ -106,7 +106,8 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
|
|||||||
#else
|
#else
|
||||||
if ((task->pid == node->pid ||
|
if ((task->pid == node->pid ||
|
||||||
(task->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
|
(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)
|
node->seqno >= task->seqmin && node->seqno <= task->seqmax)
|
||||||
{
|
{
|
||||||
info->aordblks++;
|
info->aordblks++;
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
|
|||||||
#if CONFIG_MM_BACKTRACE < 0
|
#if CONFIG_MM_BACKTRACE < 0
|
||||||
if (dump->pid == PID_MM_ALLOC)
|
if (dump->pid == PID_MM_ALLOC)
|
||||||
#else
|
#else
|
||||||
if ((dump->pid == node->pid ||
|
if ((dump->pid == node->pid || dump->pid == PID_MM_ALLOC ||
|
||||||
(dump->pid == PID_MM_ALLOC && node->pid != PID_MM_MEMPOOL) ||
|
(dump->pid == PID_MM_LEAK && node->pid >= 0 &&
|
||||||
(dump->pid == PID_MM_LEAK && !!nxsched_get_tcb(node->pid))) &&
|
!nxsched_get_tcb(node->pid))) &&
|
||||||
node->seqno >= dump->seqmin && node->seqno <= dump->seqmax)
|
node->seqno >= dump->seqmin && node->seqno <= dump->seqmax)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-2
@@ -299,7 +299,8 @@ static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
|
|||||||
|
|
||||||
if ((task->pid == buf->pid ||
|
if ((task->pid == buf->pid ||
|
||||||
(task->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
|
(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)
|
buf->seqno >= task->seqmin && buf->seqno <= task->seqmax)
|
||||||
{
|
{
|
||||||
info->aordblks++;
|
info->aordblks++;
|
||||||
@@ -412,7 +413,8 @@ static void memdump_handler(FAR void *ptr, size_t size, int used,
|
|||||||
|
|
||||||
if ((dump->pid == buf->pid ||
|
if ((dump->pid == buf->pid ||
|
||||||
(dump->pid == PID_MM_ALLOC && buf->pid != PID_MM_MEMPOOL) ||
|
(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)
|
buf->seqno >= dump->seqmin && buf->seqno <= dump->seqmax)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user