Unify statistic collection:

- For MI_STAT == 0 no allocation stats are collected
  - For MI_STAT == 1 only aggregated values (across normal, large and huge heaps) are collected
  - For MI_STAT == 1 separate per-bin collection for normal heap is done as well
This commit is contained in:
Anton Korobeynikov 2020-11-11 11:34:40 +03:00
parent 00fb89f771
commit 765fc9c0ca
5 changed files with 36 additions and 14 deletions

View file

@ -39,11 +39,15 @@ extern inline void* _mi_page_malloc(mi_heap_t* heap, mi_page_t* page, size_t siz
block->next = 0; // don't leak internal data
#endif
#if (MI_STAT>1)
#if (MI_STAT>0)
const size_t bsize = mi_page_usable_block_size(page);
if (bsize <= MI_LARGE_OBJ_SIZE_MAX) {
mi_heap_stat_increase(heap, normal, bsize);
mi_heap_stat_counter_increase(heap, normal_count, 1);
#if (MI_STAT>1)
const size_t bin = _mi_bin(bsize);
mi_heap_stat_increase(heap, normal_bins[bin], 1);
#endif
}
#endif
@ -287,14 +291,22 @@ static void mi_padding_shrink(const mi_page_t* page, const mi_block_t* block, co
#endif
// only maintain stats for smaller objects if requested
#if (MI_STAT>1)
#if (MI_STAT>0)
static void mi_stat_free(const mi_page_t* page, const mi_block_t* block) {
#if (MI_STAT < 2)
UNUSED(block);
#endif
mi_heap_t* const heap = mi_heap_get_default();
const size_t bsize = mi_page_usable_block_size(page);
#if (MI_STAT>1)
const size_t usize = mi_page_usable_size_of(page, block);
const size_t bsize = mi_page_usable_block_size(page);
mi_heap_stat_decrease(heap, malloc, usize);
#endif
if (bsize <= MI_LARGE_OBJ_SIZE_MAX) {
mi_heap_stat_decrease(heap, normal, bsize);
#if (MI_STAT > 1)
mi_heap_stat_decrease(heap, normal_bins[_mi_bin(bsize)], 1);
#endif
}
}
#else