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:
parent
2e0de13813
commit
af3978c1fa
@ -52,14 +52,12 @@ struct mallinfo
|
|||||||
* by free (not in use) chunks. */
|
* by free (not in use) chunks. */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
|
||||||
struct mallinfo_task
|
struct mallinfo_task
|
||||||
{
|
{
|
||||||
pid_t pid; /* The pid of task */
|
pid_t pid; /* The pid of task */
|
||||||
int aordblks; /* This is the number of allocated (in use) chunks for 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 */
|
int uordblks; /* This is the total size of memory occupied for task */
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
@ -72,9 +70,7 @@ extern "C"
|
|||||||
|
|
||||||
struct mallinfo mallinfo(void);
|
struct mallinfo mallinfo(void);
|
||||||
size_t malloc_size(FAR void *ptr);
|
size_t malloc_size(FAR void *ptr);
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
|
||||||
struct mallinfo_task mallinfo_task(pid_t pid);
|
struct mallinfo_task mallinfo_task(pid_t pid);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
@ -310,11 +310,9 @@ void kmm_extend(FAR void *mem, size_t size, int region);
|
|||||||
|
|
||||||
struct mallinfo; /* Forward reference */
|
struct mallinfo; /* Forward reference */
|
||||||
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info);
|
int mm_mallinfo(FAR struct mm_heap_s *heap, FAR struct mallinfo *info);
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
|
||||||
struct mallinfo_task; /* Forward reference */
|
struct mallinfo_task; /* Forward reference */
|
||||||
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
||||||
FAR struct mallinfo_task *info);
|
FAR struct mallinfo_task *info);
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Functions contained in kmm_mallinfo.c ************************************/
|
/* Functions contained in kmm_mallinfo.c ************************************/
|
||||||
|
|
||||||
|
@ -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 kmm_mallinfo_task(pid_t pid)
|
||||||
{
|
{
|
||||||
struct mallinfo_task info;
|
struct mallinfo_task info;
|
||||||
@ -68,5 +67,4 @@ struct mallinfo_task kmm_mallinfo_task(pid_t pid)
|
|||||||
mm_mallinfo_task(g_kmmheap, &info);
|
mm_mallinfo_task(g_kmmheap, &info);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#endif /* CONFIG_MM_KERNEL_HEAP */
|
#endif /* CONFIG_MM_KERNEL_HEAP */
|
||||||
|
@ -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,
|
static void mallinfo_task_handler(FAR struct mm_allocnode_s *node,
|
||||||
FAR void *arg)
|
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)
|
if ((node->preceding & MM_ALLOC_BIT) != 0)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
|
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->aordblks++;
|
||||||
info->uordblks += node->size;
|
info->uordblks += node->size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (info->pid == -2)
|
||||||
|
{
|
||||||
|
info->aordblks++;
|
||||||
|
info->uordblks += node->size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* 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,
|
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
||||||
FAR struct mallinfo_task *info)
|
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);
|
mm_foreach(heap, mallinfo_task_handler, info);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
@ -47,28 +47,21 @@
|
|||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
struct memdump_info_s
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
int blks;
|
|
||||||
int size;
|
|
||||||
};
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg)
|
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)
|
if ((node->preceding & MM_ALLOC_BIT) != 0)
|
||||||
{
|
{
|
||||||
DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
|
DEBUGASSERT(node->size >= SIZEOF_MM_ALLOCNODE);
|
||||||
#if CONFIG_MM_BACKTRACE < 0
|
#if CONFIG_MM_BACKTRACE < 0
|
||||||
if (info->pid == -1)
|
if (pid == -1)
|
||||||
#else
|
#else
|
||||||
if (info->pid == -1 || node->pid == info->pid)
|
if (pid == -1 || node->pid == pid)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if CONFIG_MM_BACKTRACE < 0
|
#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,
|
(int)node->pid, (size_t)node->size, MM_PTR_FMT_WIDTH,
|
||||||
((FAR char *)node + SIZEOF_MM_ALLOCNODE), buf);
|
((FAR char *)node + SIZEOF_MM_ALLOCNODE), buf);
|
||||||
#endif
|
#endif
|
||||||
info->blks++;
|
|
||||||
info->size += node->size;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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 == 0 ||
|
||||||
fnode->flink->size >= fnode->size);
|
fnode->flink->size >= fnode->size);
|
||||||
|
|
||||||
if (info->pid <= -2)
|
if (pid <= -2)
|
||||||
{
|
{
|
||||||
info->blks++;
|
|
||||||
info->size += node->size;
|
|
||||||
syslog(LOG_INFO, "%12zu%*p\n",
|
syslog(LOG_INFO, "%12zu%*p\n",
|
||||||
(size_t)node->size, MM_PTR_FMT_WIDTH,
|
(size_t)node->size, MM_PTR_FMT_WIDTH,
|
||||||
((FAR char *)node + SIZEOF_MM_ALLOCNODE));
|
((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)
|
void mm_memdump(FAR struct mm_heap_s *heap, pid_t pid)
|
||||||
{
|
{
|
||||||
struct memdump_info_s info;
|
struct mallinfo_task info;
|
||||||
|
|
||||||
if (pid >= -1)
|
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");
|
syslog(LOG_INFO, "%12s%*s\n", "Size", MM_PTR_FMT_WIDTH, "Address");
|
||||||
}
|
}
|
||||||
|
|
||||||
info.blks = 0;
|
mm_foreach(heap, memdump_handler, &pid);
|
||||||
info.size = 0;
|
|
||||||
info.pid = pid;
|
|
||||||
mm_foreach(heap, memdump_handler, &info);
|
|
||||||
|
|
||||||
|
info.pid = pid;
|
||||||
|
mm_mallinfo_task(heap, &info);
|
||||||
syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
|
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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
* 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,
|
static void mallinfo_task_handler(FAR void *ptr, size_t size, int used,
|
||||||
FAR void *user)
|
FAR void *user)
|
||||||
{
|
{
|
||||||
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
FAR struct memdump_backtrace_s *dump;
|
FAR struct memdump_backtrace_s *dump;
|
||||||
|
#endif
|
||||||
FAR struct mallinfo_task *info = user;
|
FAR struct mallinfo_task *info = user;
|
||||||
|
|
||||||
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
size -= sizeof(struct memdump_backtrace_s);
|
size -= sizeof(struct memdump_backtrace_s);
|
||||||
dump = ptr + size;
|
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->aordblks++;
|
||||||
info->uordblks += size;
|
info->uordblks += size;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mm_lock
|
* 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,
|
static void memdump_handler(FAR void *ptr, size_t size, int used,
|
||||||
FAR void *user)
|
FAR void *user)
|
||||||
{
|
{
|
||||||
FAR struct memdump_info_s *info = user;
|
pid_t pid = *(FAR pid_t *)user;
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
#if CONFIG_MM_BACKTRACE >= 0
|
||||||
FAR struct memdump_backtrace_s *dump;
|
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 (used)
|
||||||
{
|
{
|
||||||
#if CONFIG_MM_BACKTRACE < 0
|
#if CONFIG_MM_BACKTRACE < 0
|
||||||
if (info->pid == -1)
|
if (pid == -1)
|
||||||
#else
|
#else
|
||||||
if (info->pid == -1 || dump->pid == info->pid)
|
if (pid == -1 || dump->pid == pid)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if CONFIG_MM_BACKTRACE < 0
|
#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,
|
(int)dump->pid, size, MM_PTR_FMT_WIDTH,
|
||||||
ptr, buf);
|
ptr, buf);
|
||||||
#endif
|
#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);
|
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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
|
||||||
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
||||||
FAR struct mallinfo_task *info)
|
FAR struct mallinfo_task *info)
|
||||||
{
|
{
|
||||||
@ -867,7 +876,6 @@ int mm_mallinfo_task(FAR struct mm_heap_s *heap,
|
|||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: mm_memdump
|
* 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");
|
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
|
#if CONFIG_MM_REGIONS > 1
|
||||||
for (region = 0; region < heap->mm_nregions; region++)
|
for (region = 0; region < heap->mm_nregions; region++)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
DEBUGVERIFY(mm_lock(heap));
|
DEBUGVERIFY(mm_lock(heap));
|
||||||
tlsf_walk_pool(heap->mm_heapstart[region],
|
tlsf_walk_pool(heap->mm_heapstart[region],
|
||||||
memdump_handler, &info);
|
memdump_handler, &pid);
|
||||||
mm_unlock(heap);
|
mm_unlock(heap);
|
||||||
}
|
}
|
||||||
#undef region
|
#undef region
|
||||||
|
|
||||||
|
info.pid = pid;
|
||||||
|
mm_mallinfo_task(heap, &info);
|
||||||
syslog(LOG_INFO, "%12s%12s\n", "Total Blks", "Total Size");
|
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.blks, info.size);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,6 @@ struct mallinfo mallinfo(void)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_MM_BACKTRACE >= 0
|
|
||||||
struct mallinfo_task mallinfo_task(pid_t pid)
|
struct mallinfo_task mallinfo_task(pid_t pid)
|
||||||
{
|
{
|
||||||
struct mallinfo_task info;
|
struct mallinfo_task info;
|
||||||
@ -68,4 +67,3 @@ struct mallinfo_task mallinfo_task(pid_t pid)
|
|||||||
mm_mallinfo_task(USR_HEAP, &info);
|
mm_mallinfo_task(USR_HEAP, &info);
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user