This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2 1/2] malloc: malloc_stats print all heaps except heaps of main_arena
- From: liusirui <liusirui at huawei dot com>
- To: <libc-alpha at sourceware dot org>
- Cc: <hushiyuan at huawei dot com>
- Date: Sat, 26 Oct 2019 15:14:02 +0800
- Subject: [PATCH v2 1/2] malloc: malloc_stats print all heaps except heaps of main_arena
An arena may have several heaps, and only the last heap contains top chunk.
malloc_stats only print the heap which contains top chunk. Now the function
prints all heaps of an arena.
---
malloc/malloc.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 5d3e82a..351e95f 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -4965,6 +4965,7 @@ __malloc_stats (void)
{
int i;
mstate ar_ptr;
+ heap_info *heap_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
if (__malloc_initialized < 0)
@@ -4984,7 +4985,13 @@ __malloc_stats (void)
fprintf (stderr, "in use bytes = %10u\n", (unsigned int) mi.uordblks);
#if MALLOC_DEBUG > 1
if (i > 0)
- dump_heap (heap_for_ptr (top (ar_ptr)));
+ {
+ for (heap_ptr = heap_for_ptr (top (ar_ptr)); heap_ptr->ar_ptr != (mstate) (heap_ptr + 1); heap_ptr = heap_ptr->prev)
+ {
+ dump_heap (heap_ptr);
+ }
+ dump_heap (heap_ptr);
+ }
#endif
system_b += mi.arena;
in_use_b += mi.uordblks;
--
2.7.4