add is_init check to malloc_info

This commit is contained in:
Daniel Micay 2020-09-17 16:07:10 -04:00
parent 9fb2791af2
commit 50e0f1334c

View File

@ -1800,48 +1800,51 @@ EXPORT int h_malloc_info(int options, UNUSED FILE *fp) {
#if CONFIG_STATS
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++) {
struct size_class *c = &ro.size_class_metadata[arena][class];
if (is_init()) {
for (unsigned arena = 0; arena < N_ARENA; arena++) {
fprintf(fp, "<heap nr=\"%u\">", arena);
u64 nmalloc;
u64 ndalloc;
size_t slab_allocated;
size_t allocated;
for (unsigned class = 0; class < N_SIZE_CLASSES; class++) {
struct size_class *c = &ro.size_class_metadata[arena][class];
mutex_lock(&c->lock);
nmalloc = c->nmalloc;
ndalloc = c->ndalloc;
slab_allocated = c->slab_allocated;
allocated = c->allocated;
mutex_unlock(&c->lock);
u64 nmalloc;
u64 ndalloc;
size_t slab_allocated;
size_t allocated;
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);
mutex_lock(&c->lock);
nmalloc = c->nmalloc;
ndalloc = c->ndalloc;
slab_allocated = c->slab_allocated;
allocated = c->allocated;
mutex_unlock(&c->lock);
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);
}
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);
return 0;