67 uword i, n_callers, trace_index, *p;
96 t = tm->
traces + trace_index;
113 if (tm->
traces != old_start)
120 q = uword_to_pointer (p->key, mheap_trace_t *);
121 ASSERT (q >= old_start && q < old_end);
122 p->key = pointer_to_uword (tm->traces + (q - old_start));
126 trace_index = t - tm->
traces;
129 t = tm->
traces + trace_index;
150 uword trace_index, *p;
175 t = tm->
traces + trace_index;
218 flags = CLIB_MEM_HEAP_F_UNMAP_ON_DESTROY;
224 flags |= CLIB_MEM_HEAP_F_LOCKED;
232 strcpy (h->
name, name);
259 if (mheap_trace_main.
lock == 0)
303 int verbose = va_arg (*va,
int);
330 s =
format (s,
"%.2fG", (((
f64) a) / ((
f64) (1ULL << 30))));
331 else if (a >= 1ULL << 20)
332 s =
format (s,
"%.2fM", (((
f64) a) / ((
f64) (1ULL << 20))));
333 else if (a >= 1ULL << 10)
334 s =
format (s,
"%.2fK", (((
f64) a) / ((
f64) (1ULL << 10))));
336 s =
format (s,
"%lld", a);
357 int verbose = va_arg (*va,
int);
369 u32 indent, total_objects_traced;
373 qsort (traces_copy,
vec_len (traces_copy),
sizeof (traces_copy[0]),
376 total_objects_traced = 0;
387 if (!verbose && t->
n_bytes < 1024)
390 if (t == traces_copy)
391 s =
format (s,
"%=9s%=9s %=10s Traceback\n",
"Bytes",
"Count",
399 #if defined(CLIB_UNIX) && !defined(__APPLE__) 410 s =
format (s,
"%d total traced objects\n", total_objects_traced);
415 if (have_traces == 0)
416 s =
format (s,
"no traced allocations\n");
425 int verbose = va_arg (*va,
int);
435 s =
format (s,
"base %p, size %U",
439 if (heap->flags & CLIB_MEM_HEAP_F_##v) s = format (s, ", %s", str); 454 s =
format (s,
"\n%Utotal: %U, used: %U, free: %U, trimmable: %U",
461 s =
format (s,
"\n%Ufree chunks %llu free fastbin blks %llu",
463 s =
format (s,
"\n%Umax total allocated %U",
547 else if (strchr (fmt,
'%'))
574 if (h->
flags & CLIB_MEM_HEAP_F_UNMAP_ON_DESTROY)
__clib_export void clib_mem_destroy(void)
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
#define CLIB_MEM_VM_MAP_FAILED
#define hash_set(h, key, value)
vhost_user_memory_t memory
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
__clib_export int clib_mem_vm_unmap(void *base)
#define hash_unset(h, key)
vl_api_wireguard_peer_flags_t flags
__clib_export void clib_mem_destroy_heap(clib_mem_heap_t *h)
uword bytes_free_reclaimed
void * current_traced_mheap
static void * clib_mem_init_internal(void *base, uword size, clib_mem_page_sz_t log2_page_sz)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static clib_mem_heap_t * clib_mem_set_heap(clib_mem_heap_t *heap)
u8 * format_msize(u8 *s, va_list *va)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define hash_set_mem(h, key, value)
DLMALLOC_EXPORT struct dlmallinfo mspace_mallinfo(mspace msp)
MALLINFO_FIELD_TYPE hblkhd
__clib_export uword clib_mem_get_heap_size(clib_mem_heap_t *heap)
__clib_export uword clib_mem_get_heap_free_space(clib_mem_heap_t *h)
clib_mem_heap_flag_t flags
DLMALLOC_EXPORT mspace create_mspace_with_base(void *base, size_t capacity, int locked)
__clib_export void clib_mem_trace(int enable)
MALLINFO_FIELD_TYPE uordblks
__clib_export uword clib_backtrace(uword *callers, uword max_callers, uword n_frames_to_skip)
void * clib_mem_vm_map_internal(void *base, clib_mem_page_sz_t log2_page_sz, uword size, int fd, uword offset, char *name)
static_always_inline clib_mem_page_sz_t clib_mem_log2_page_size_validate(clib_mem_page_sz_t log2_page_size)
MALLINFO_FIELD_TYPE arena
clib_mem_page_sz_t log2_page_sz
description fragment has unexpected format
#define vec_end(v)
End (last data address) of vector.
MALLINFO_FIELD_TYPE ordblks
__clib_export uword clib_mem_trace_enable_disable(uword enable)
static void clib_spinlock_init(clib_spinlock_t *p)
#define hash_unset_mem(h, key)
vl_api_ikev2_sa_stats_t stats
__clib_export u8 * format_clib_mem_usage(u8 *s, va_list *va)
u8 * format_clib_mem_page_stats(u8 *s, va_list *va)
mheap_trace_main_t mheap_trace_main
MALLINFO_FIELD_TYPE usmblks
DLMALLOC_EXPORT void mspace_disable_expand(mspace msp)
#define vec_dup(V)
Return copy of vector (no header, no alignment)
static int mheap_trace_sort(const void *_t1, const void *_t2)
DLMALLOC_EXPORT int mspace_is_traced(mspace msp)
__clib_export void * clib_mem_get_heap_base(clib_mem_heap_t *h)
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
MALLINFO_FIELD_TYPE keepcost
static_always_inline clib_mem_page_sz_t clib_mem_get_log2_page_size(void)
DLMALLOC_EXPORT int mspace_enable_disable_trace(mspace msp, int enable)
static uword round_pow2(uword x, uword pow2)
u8 * format_mheap_trace(u8 *s, va_list *va)
static void mheap_trace_main_free(mheap_trace_main_t *tm)
static clib_mem_heap_t * clib_mem_get_heap(void)
int clib_mem_is_traced(void)
MALLINFO_FIELD_TYPE smblks
static clib_mem_heap_t * clib_mem_create_heap_internal(void *base, uword size, clib_mem_page_sz_t log2_page_sz, int is_locked, char *name)
#define hash_create_shmem(elts, key_bytes, value_bytes)
__clib_export void clib_mem_get_heap_usage(clib_mem_heap_t *heap, clib_mem_usage_t *usage)
void mheap_get_trace(uword offset, uword size)
__clib_export void * clib_mem_init_with_page_size(uword memory_size, clib_mem_page_sz_t log2_page_sz)
__clib_export void * clib_mem_init(void *memory, uword memory_size)
__clib_export void clib_mem_get_page_stats(void *start, clib_mem_page_sz_t log2_page_size, uword n_pages, clib_mem_page_stats_t *stats)
uword clib_mem_validate_serial
__clib_export void mheap_trace(clib_mem_heap_t *h, int enable)
template key/value backing page structure
__clib_export clib_mem_heap_t * clib_mem_create_heap(void *base, uword size, int is_locked, char *fmt,...)
void qsort(void *base, uword n, uword size, int(*compar)(const void *, const void *))
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
__clib_export void * clib_mem_init_thread_safe(void *memory, uword memory_size)
void mheap_put_trace(uword offset, uword size)
format_function_t format_clib_elf_symbol_with_address
#define hash_get_mem(h, key)
struct clib_bihash_value offset
template key/value backing page structure
DLMALLOC_EXPORT size_t destroy_mspace(mspace msp)
DLMALLOC_EXPORT size_t mspace_footprint(mspace msp)
#define vec_foreach(var, vec)
Vector iterator.
MALLINFO_FIELD_TYPE fordblks
void clib_mem_main_init()
uword * trace_index_by_offset
DLMALLOC_EXPORT void * mspace_least_addr(mspace msp)
__clib_export u8 * format_clib_mem_heap(u8 *s, va_list *va)
static_always_inline uword clib_mem_page_bytes(clib_mem_page_sz_t log2_page_size)
#define CLIB_MEM_POISON(a, s)