add is_init check to malloc_info
parent
9fb2791af2
commit
50e0f1334c
67
h_malloc.c
67
h_malloc.c
|
@ -1800,48 +1800,51 @@ EXPORT int h_malloc_info(int options, UNUSED FILE *fp) {
|
||||||
|
|
||||||
#if CONFIG_STATS
|
#if CONFIG_STATS
|
||||||
fputs("<malloc version=\"hardened_malloc-1\">", fp);
|
fputs("<malloc version=\"hardened_malloc-1\">", fp);
|
||||||
for (unsigned arena = 0; arena < N_ARENA; arena++) {
|
|
||||||
fprintf(fp, "<heap nr=\"%u\">", arena);
|
|
||||||
|
|
||||||
for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {
|
if (is_init()) {
|
||||||
struct size_class *c = &ro.size_class_metadata[arena][class];
|
for (unsigned arena = 0; arena < N_ARENA; arena++) {
|
||||||
|
fprintf(fp, "<heap nr=\"%u\">", arena);
|
||||||
|
|
||||||
u64 nmalloc;
|
for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {
|
||||||
u64 ndalloc;
|
struct size_class *c = &ro.size_class_metadata[arena][class];
|
||||||
size_t slab_allocated;
|
|
||||||
size_t allocated;
|
|
||||||
|
|
||||||
mutex_lock(&c->lock);
|
u64 nmalloc;
|
||||||
nmalloc = c->nmalloc;
|
u64 ndalloc;
|
||||||
ndalloc = c->ndalloc;
|
size_t slab_allocated;
|
||||||
slab_allocated = c->slab_allocated;
|
size_t allocated;
|
||||||
allocated = c->allocated;
|
|
||||||
mutex_unlock(&c->lock);
|
|
||||||
|
|
||||||
if (nmalloc || ndalloc || slab_allocated || allocated) {
|
mutex_lock(&c->lock);
|
||||||
fprintf(fp, "<bin nr=\"%u\" size=\"%" PRIu32 "\">", class, size_classes[class]);
|
nmalloc = c->nmalloc;
|
||||||
fprintf(fp, "<nmalloc>%" PRIu64 "</nmalloc>", nmalloc);
|
ndalloc = c->ndalloc;
|
||||||
fprintf(fp, "<ndalloc>%" PRIu64 "</ndalloc>", ndalloc);
|
slab_allocated = c->slab_allocated;
|
||||||
fprintf(fp, "<slab_allocated>%zu</slab_allocated>", slab_allocated);
|
allocated = c->allocated;
|
||||||
fprintf(fp, "<allocated>%zu</allocated>", allocated);
|
mutex_unlock(&c->lock);
|
||||||
fputs("</bin>", fp);
|
|
||||||
|
if (nmalloc || ndalloc || slab_allocated || allocated) {
|
||||||
|
fprintf(fp, "<bin nr=\"%u\" size=\"%" PRIu32 "\">", class, size_classes[class]);
|
||||||
|
fprintf(fp, "<nmalloc>%" PRIu64 "</nmalloc>", nmalloc);
|
||||||
|
fprintf(fp, "<ndalloc>%" PRIu64 "</ndalloc>", ndalloc);
|
||||||
|
fprintf(fp, "<slab_allocated>%zu</slab_allocated>", slab_allocated);
|
||||||
|
fprintf(fp, "<allocated>%zu</allocated>", allocated);
|
||||||
|
fputs("</bin>", fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fputs("</heap>", fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t region_allocated;
|
||||||
|
|
||||||
|
struct region_allocator *ra = ro.region_allocator;
|
||||||
|
mutex_lock(&ra->lock);
|
||||||
|
region_allocated = ra->allocated;
|
||||||
|
mutex_unlock(&ra->lock);
|
||||||
|
|
||||||
|
fprintf(fp, "<heap nr=\"%u\">", N_ARENA);
|
||||||
|
fprintf(fp, "<allocated_large>%zu</allocated_large>", region_allocated);
|
||||||
fputs("</heap>", fp);
|
fputs("</heap>", fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t region_allocated;
|
|
||||||
|
|
||||||
struct region_allocator *ra = ro.region_allocator;
|
|
||||||
mutex_lock(&ra->lock);
|
|
||||||
region_allocated = ra->allocated;
|
|
||||||
mutex_unlock(&ra->lock);
|
|
||||||
|
|
||||||
fprintf(fp, "<heap nr=\"%u\">", N_ARENA);
|
|
||||||
fprintf(fp, "<allocated_large>%zu</allocated_large>", region_allocated);
|
|
||||||
fputs("</heap>", fp);
|
|
||||||
|
|
||||||
fputs("</malloc>", fp);
|
fputs("</malloc>", fp);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue