adjust the contents of memdump and meminfo

memdump:just dump info
meminfo:statistics mem information

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
anjiahao 2022-11-20 15:00:44 +08:00 committed by Xiang Xiao
parent 2e0de13813
commit af3978c1fa
7 changed files with 44 additions and 54 deletions

View File

@ -52,14 +52,12 @@ struct mallinfo
* by free (not in use) chunks. */
};
#if CONFIG_MM_BACKTRACE >= 0
struct mallinfo_task
{
pid_t pid; /* The pid of task */
int aordblks; /* This is the number of allocated (in use) chunks for task */
int uordblks; /* This is the total size of memory occupied for task */
};
#endif
/****************************************************************************
* Public Function Prototypes
@ -72,9 +70,7 @@ extern "C"
struct mallinfo mallinfo(void);
size_t malloc_size(FAR void *ptr);
#if CONFIG_MM_BACKTRACE >= 0
struct mallinfo_task mallinfo_task(pid_t pid);
#endif
#if defined(__cplusplus)
}

View File

@ -310,11 +310,9 @@ void kmm_extend(FAR void *mem, size_t size, int region);
struct mallinfo; /* Forward reference */
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info);
#if CONFIG_MM_BACKTRACE >= 0
struct mallinfo_task; /* Forward reference */
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
FAR struct mallinfo_task *info);
#endif
/* Functions contained in kmm_mallinfo.c ************************************/

View File

@ -59,7 +59,6 @@ struct mallinfo kmm_mallinfo(void)
*
****************************************************************************/
#if CONFIG_MM_BACKTRACE >= 0
struct mallinfo_task kmm_mallinfo_task(pid_t pid)
{
struct mallinfo_task info;
@ -68,5 +67,4 @@ struct mallinfo_task kmm_mallinfo_task(pid_t pid)
mm_mallinfo_task(g_kmmheap, &info);
return info;
}
#endif
#endif /* CONFIG_MM_KERNEL_HEAP */

View File

@ -75,7 +75,6 @@ static void mallinfo_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
}
}
#if CONFIG_MM_BACKTRACE >= 0
static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
FAR void *arg)
{
@ -86,14 +85,22 @@ static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
if ((node->preceding & MM_ALLOC_BIT) != 0)
{
DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
if (node->pid == info->pid)
#if CONFIG_MM_BACKTRACE < 0
if (info->pid == -1)
#else
if (info->pid == -1 || node->pid == info->pid)
#endif
{
info->aordblks++;
info->uordblks += node->size;
}
}
else if (info->pid == -2)
{
info->aordblks++;
info->uordblks += node->size;
}
}
#endif
/****************************************************************************
* Public Functions
@ -137,7 +144,6 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
*
****************************************************************************/
#if CONFIG_MM_BACKTRACE >= 0
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
FAR struct mallinfo_task *info)
{
@ -148,4 +154,3 @@ int mm_mallinfo_task(FAR struct mm_heap_s *heap,
mm_foreach(heap, mallinfo_task_handler, info);
return OK;
}
#endif

View File

@ -47,28 +47,21 @@
* Private Types
****************************************************************************/
struct memdump_info_s
{
pid_t pid;
int blks;
int size;
};
/****************************************************************************
* Private Functions
****************************************************************************/
static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
{
FAR struct memdump_info_s *info = arg;
pid_t pid = *(FAR pid_t *)arg;
if ((node->preceding & MM_ALLOC_BIT) != 0)
{
DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
#if CONFIG_MM_BACKTRACE < 0
if (info->pid == -1)
if (pid == -1)
#else
if (info->pid == -1 || node->pid == info->pid)
if (pid == -1 || node->pid == pid)
#endif
{
#if CONFIG_MM_BACKTRACE < 0
@ -95,8 +88,6 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
(int)node->pid, (size_t)node->size, MM_PTR_FMT_WIDTH,
((FAR char *)node + SIZEOF_MM_ALLOCNODE), buf);
#endif
info->blks++;
info->size += node->size;
}
}
else
@ -112,10 +103,8 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
fnode->flink->size == 0 ||
fnode->flink->size >= fnode->size);
if (info->pid <= -2)
if (pid <= -2)
{
info->blks++;
info->size += node->size;
syslog(LOG_INFO, "%12zu%*p\n",
(size_t)node->size, MM_PTR_FMT_WIDTH,
((FAR char *)node + SIZEOF_MM_ALLOCNODE));
@ -140,7 +129,7 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid)
{
struct memdump_info_s info;
struct mallinfo_task info;
if (pid >= -1)
{
@ -158,11 +147,10 @@ void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid)
syslog(LOG_INFO, "%12s%*s\n", "Size", MM_PTR_FMT_WIDTH, "Address");
}
info.blks = 0;
info.size = 0;
info.pid = pid;
mm_foreach(heap, memdump_handler, &info);
mm_foreach(heap, memdump_handler, &pid);
info.pid = pid;
mm_mallinfo_task(heap, &info);
syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
syslog(LOG_INFO, "%12d%12d\n", info.blks, info.size);
syslog(LOG_INFO, "%12d%12d\n", info.aordblks, info.uordblks);
}

View File

@ -242,8 +242,6 @@ static void mallinfo_handler(FAR void *ptr, size_t size, int used,
}
}
#if CONFIG_MM_BACKTRACE >= 0
/****************************************************************************
* Name: mallinfo_task_handler
****************************************************************************/
@ -251,18 +249,34 @@ static void mallinfo_handler(FAR void *ptr, size_t size, int used,
static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
FAR void *user)
{
#if CONFIG_MM_BACKTRACE >= 0
FAR struct memdump_backtrace_s *dump;
#endif
FAR struct mallinfo_task *info = user;
#if CONFIG_MM_BACKTRACE >= 0
size -= sizeof(struct memdump_backtrace_s);
dump = ptr + size;
if (used && dump->pid == info->pid)
if (used)
{
#if CONFIG_MM_BACKTRACE < 0
if (info->pid = -1)
#else
if (info->pid == -1 || info->pid == dump->pid)
#endif
{
info->aordblks++;
info->uordblks += size;
}
}
else if (info->pid == -2)
{
info->aordblks++;
info->uordblks += size;
}
}
#endif
}
/****************************************************************************
* Name: mm_lock
@ -350,7 +364,7 @@ static void mm_unlock(FAR struct mm_heap_s *heap)
static void memdump_handler(FAR void *ptr, size_t size, int used,
FAR void *user)
{
FAR struct memdump_info_s *info = user;
pid_t pid = *(FAR pid_t *)user;
#if CONFIG_MM_BACKTRACE >= 0
FAR struct memdump_backtrace_s *dump;
@ -361,9 +375,9 @@ static void memdump_handler(FAR void *ptr, size_t size, int used,
if (used)
{
#if CONFIG_MM_BACKTRACE < 0
if (info->pid == -1)
if (pid == -1)
#else
if (info->pid == -1 || dump->pid == info->pid)
if (pid == -1 || dump->pid == pid)
#endif
{
#if CONFIG_MM_BACKTRACE < 0
@ -388,14 +402,10 @@ static void memdump_handler(FAR void *ptr, size_t size, int used,
(int)dump->pid, size, MM_PTR_FMT_WIDTH,
ptr, buf);
#endif
info->blks++;
info->size += size;
}
}
else if (info->pid <= -2)
else if (pid <= -2)
{
info->blks++;
info->size += size;
syslog(LOG_INFO, "%12zu%*p\n", size, MM_PTR_FMT_WIDTH, ptr);
}
}
@ -839,7 +849,6 @@ int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info)
return OK;
}
#if CONFIG_MM_BACKTRACE >= 0
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
FAR struct mallinfo_task *info)
{
@ -867,7 +876,6 @@ int mm_mallinfo_task(FAR struct mm_heap_s *heap,
return OK;
}
#endif
/****************************************************************************
* Name: mm_memdump
@ -905,20 +913,19 @@ void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid)
syslog(LOG_INFO, "%12s%*s\n", "Size", MM_PTR_FMT_WIDTH, "Address");
}
info.blks = 0;
info.size = 0;
info.pid = pid;
#if CONFIG_MM_REGIONS > 1
for (region = 0; region < heap->mm_nregions; region++)
#endif
{
DEBUGVERIFY(mm_lock(heap));
tlsf_walk_pool(heap->mm_heapstart[region],
memdump_handler, &info);
memdump_handler, &pid);
mm_unlock(heap);
}
#undef region
info.pid = pid;
mm_mallinfo_task(heap, &info);
syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
syslog(LOG_INFO, "%12d%12d\n", info.blks, info.size);
}

View File

@ -59,7 +59,6 @@ struct mallinfo mallinfo(void)
*
****************************************************************************/
#if CONFIG_MM_BACKTRACE >= 0
struct mallinfo_task mallinfo_task(pid_t pid)
{
struct mallinfo_task info;
@ -68,4 +67,3 @@ struct mallinfo_task mallinfo_task(pid_t pid)
mm_mallinfo_task(USR_HEAP, &info);
return info;
}
#endif