diff options
author | Dave Barach <dave@barachs.net> | 2019-06-15 12:46:13 -0400 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2019-06-16 10:24:43 -0400 |
commit | d67a428b3b2183cd78d7fca82e8afe2f26387810 (patch) | |
tree | f5209028aa2cfb222f35bb0c970685b8d2d777d8 /src/vppinfra | |
parent | c898a4f5bae84148ddec462a9510dee99e3da67d (diff) |
vlib: add "memory-trace stats-segment"
Type: feature
Change-Id: Ie020fd7e2618284a63efbeb9895068f27c0fb9ab
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src/vppinfra')
-rw-r--r-- | src/vppinfra/dlmalloc.c | 29 | ||||
-rw-r--r-- | src/vppinfra/dlmalloc.h | 5 | ||||
-rw-r--r-- | src/vppinfra/mem.h | 2 | ||||
-rw-r--r-- | src/vppinfra/mem_dlmalloc.c | 31 | ||||
-rw-r--r-- | src/vppinfra/mem_mheap.c | 6 |
5 files changed, 52 insertions, 21 deletions
diff --git a/src/vppinfra/dlmalloc.c b/src/vppinfra/dlmalloc.c index 60bd8d55646..524c57b210b 100644 --- a/src/vppinfra/dlmalloc.c +++ b/src/vppinfra/dlmalloc.c @@ -4093,7 +4093,7 @@ void mspace_get_address_and_size (mspace msp, char **addrp, size_t *sizep) { mstate ms; msegment *this_seg; - + ms = (mstate)msp; this_seg = &ms->seg; @@ -4155,9 +4155,18 @@ int mspace_enable_disable_trace (mspace msp, int enable) return (was_enabled); } -void* mspace_get_aligned (mspace msp, +int mspace_is_traced (mspace msp) +{ + mstate ms = (mstate)msp; + + if (use_trace(ms)) + return 1; + return 0; +} + +void* mspace_get_aligned (mspace msp, unsigned long n_user_data_bytes, - unsigned long align, + unsigned long align, unsigned long align_offset) { char *rv; unsigned long searchp; @@ -4165,13 +4174,13 @@ void* mspace_get_aligned (mspace msp, mstate ms = (mstate)msp; /* - * Allocate space for the "Where's Waldo?" pointer + * Allocate space for the "Where's Waldo?" pointer * the base of the dlmalloc object */ n_user_data_bytes += sizeof(unsigned); - /* - * Alignment requests less than the size of an mmx vector are ignored + /* + * Alignment requests less than the size of an mmx vector are ignored */ if (align < sizeof (uword)) { rv = mspace_malloc (msp, n_user_data_bytes); @@ -4181,7 +4190,7 @@ void* mspace_get_aligned (mspace msp, if (use_trace(ms)) { mchunkptr p = mem2chunk(rv); size_t psize = chunksize(p); - + mheap_get_trace ((unsigned long)rv + sizeof (unsigned), psize); } @@ -4196,15 +4205,15 @@ void* mspace_get_aligned (mspace msp, * Alignment requests greater than 4K must be at offset zero, * and must be freed using mspace_free_no_offset - or never freed - * since the "Where's Waldo?" pointer would waste too much space. - * - * Waldo is the address of the chunk of memory returned by mspace_malloc, + * + * Waldo is the address of the chunk of memory returned by mspace_malloc, * which we need later to call mspace_free... */ if (align > 4<<10 || align_offset == ~0UL) { n_user_data_bytes -= sizeof(unsigned); assert(align_offset == 0); rv = internal_memalign(ms, (size_t)align, n_user_data_bytes); - + /* Trace the allocation */ if (rv && use_trace(ms)) { mchunkptr p = mem2chunk(rv); diff --git a/src/vppinfra/dlmalloc.h b/src/vppinfra/dlmalloc.h index 216df4737ca..b8adf74831d 100644 --- a/src/vppinfra/dlmalloc.h +++ b/src/vppinfra/dlmalloc.h @@ -1447,9 +1447,9 @@ DLMALLOC_EXPORT int mspace_trim(mspace msp, size_t pad); */ DLMALLOC_EXPORT int mspace_mallopt(int, int); -DLMALLOC_EXPORT void* mspace_get_aligned (mspace msp, +DLMALLOC_EXPORT void* mspace_get_aligned (mspace msp, unsigned long n_user_data_bytes, - unsigned long align, + unsigned long align, unsigned long align_offset); DLMALLOC_EXPORT int mspace_is_heap_object (mspace msp, void *p); @@ -1463,6 +1463,7 @@ DLMALLOC_EXPORT void *mspace_least_addr (mspace msp); DLMALLOC_EXPORT void mheap_get_trace (uword offset, uword size); DLMALLOC_EXPORT void mheap_put_trace (uword offset, uword size); DLMALLOC_EXPORT int mspace_enable_disable_trace (mspace msp, int enable); +DLMALLOC_EXPORT int mspace_is_traced (mspace msp); #endif /* MSPACES */ diff --git a/src/vppinfra/mem.h b/src/vppinfra/mem.h index 1e14698af98..e31ec82e7c5 100644 --- a/src/vppinfra/mem.h +++ b/src/vppinfra/mem.h @@ -274,6 +274,8 @@ void clib_mem_validate (void); void clib_mem_trace (int enable); +int clib_mem_is_traced (void); + typedef struct { /* Total number of objects allocated. */ diff --git a/src/vppinfra/mem_dlmalloc.c b/src/vppinfra/mem_dlmalloc.c index e83e0e89d21..99f1c04f3eb 100644 --- a/src/vppinfra/mem_dlmalloc.c +++ b/src/vppinfra/mem_dlmalloc.c @@ -56,6 +56,10 @@ typedef struct /* Hash table mapping mheap offset to trace index. */ uword *trace_index_by_offset; + + /* So we can easily shut off current segment trace, if any */ + void *current_traced_mheap; + } mheap_trace_main_t; mheap_trace_main_t mheap_trace_main; @@ -69,7 +73,7 @@ mheap_get_trace (uword offset, uword size) mheap_trace_t trace; uword save_enabled; - if (tm->enabled == 0) + if (tm->enabled == 0 || (clib_mem_get_heap () != tm->current_traced_mheap)) return; /* Spurious Coverity warnings be gone. */ @@ -80,11 +84,6 @@ mheap_get_trace (uword offset, uword size) if (n_callers == 0) return; - /* $$$ This looks like dreck to remove... */ - if (0) - for (i = n_callers; i < ARRAY_LEN (trace.callers); i++) - trace.callers[i] = 0; - clib_spinlock_lock (&tm->lock); /* Turn off tracing to avoid embarrassment... */ @@ -291,7 +290,8 @@ format_mheap_trace (u8 * s, va_list * va) int i; clib_spinlock_lock (&tm->lock); - if (vec_len (tm->traces) > 0) + if (vec_len (tm->traces) > 0 && + clib_mem_get_heap () == tm->current_traced_mheap) { have_traces = 1; @@ -372,7 +372,8 @@ format_mheap (u8 * s, va_list * va) format (s, "\n max total allocated %U", format_msize, mi.usmblks); } - s = format (s, "\n%U", format_mheap_trace, tm, verbose); + if (mspace_is_traced (heap)) + s = format (s, "\n%U", format_mheap_trace, tm, verbose); return s; } @@ -404,9 +405,21 @@ void clib_mem_trace (int enable) { mheap_trace_main_t *tm = &mheap_trace_main; + void *current_heap = clib_mem_get_heap (); tm->enabled = enable; - mheap_trace (clib_mem_get_heap (), enable); + mheap_trace (current_heap, enable); + + if (enable) + tm->current_traced_mheap = current_heap; + else + tm->current_traced_mheap = 0; +} + +int +clib_mem_is_traced (void) +{ + return mspace_is_traced (clib_mem_get_heap ()); } uword diff --git a/src/vppinfra/mem_mheap.c b/src/vppinfra/mem_mheap.c index 4077bf279fd..3046bd22d0a 100644 --- a/src/vppinfra/mem_mheap.c +++ b/src/vppinfra/mem_mheap.c @@ -148,6 +148,12 @@ clib_mem_trace (int enable) mheap_trace (clib_mem_get_heap (), enable); } +int +clib_mem_is_traced (void) +{ + return mheap_is_traced (clib_mem_get_heap ()); +} + /* * fd.io coding-style-patch-verification: ON * |