add mi_stats_get_bin_size and chunk counters

This commit is contained in:
Daan 2025-03-13 13:22:58 -07:00
parent 22b879fde1
commit 265af0c90e
7 changed files with 32 additions and 17 deletions

View file

@ -11,7 +11,7 @@ terms of the MIT license. A copy of the license can be found in the file
#include <mimalloc.h>
#include <stdint.h>
#define MI_STAT_VERSION 1 // increased on every backward incompatible change
#define MI_STAT_VERSION 2 // increased on every backward incompatible change
// count allocation over time
typedef struct mi_stat_count_s {
@ -65,6 +65,17 @@ typedef struct mi_stat_counter_s {
MI_STAT_COUNTER(pages_unabandon_busy_wait) \
// Size bins for chunks
typedef enum mi_bbin_e {
MI_BBIN_SMALL, // slice_count == 1
MI_BBIN_OTHER, // slice_count: any other from the other bins, and 1 <= slice_count <= MI_BCHUNK_BITS
MI_BBIN_MEDIUM, // slice_count == 8
MI_BBIN_LARGE, // slice_count == MI_SIZE_BITS (only used if MI_ENABLE_LARGE_PAGES is 1)
MI_BBIN_NONE, // no bin assigned yet (the chunk is completely free)
MI_BBIN_COUNT
} mi_bbin_t;
// Define the statistics structure
#define MI_BIN_HUGE (73U) // see types.h
#define MI_STAT_COUNT(stat) mi_stat_count_t stat;
@ -83,6 +94,7 @@ typedef struct mi_stats_s
// size segregated statistics
mi_stat_count_t malloc_bins[MI_BIN_HUGE+1]; // allocation per size bin
mi_stat_count_t page_bins[MI_BIN_HUGE+1]; // pages allocated per size bin
mi_stat_count_t chunk_bins[MI_BBIN_COUNT]; // chunks per page sizes
} mi_stats_t;
#undef MI_STAT_COUNT
@ -93,8 +105,9 @@ typedef struct mi_stats_s
extern "C" {
#endif
mi_decl_export void mi_stats_get( size_t stats_size, mi_stats_t* stats ) mi_attr_noexcept;
mi_decl_export char* mi_stats_get_json( size_t buf_size, char* buf ) mi_attr_noexcept; // use mi_free to free the result if the input buf == NULL
mi_decl_export void mi_stats_get( size_t stats_size, mi_stats_t* stats ) mi_attr_noexcept;
mi_decl_export char* mi_stats_get_json( size_t buf_size, char* buf ) mi_attr_noexcept; // use mi_free to free the result if the input buf == NULL
mi_decl_export size_t mi_stats_get_bin_size(size_t bin) mi_attr_noexcept;
#ifdef __cplusplus
}

View file

@ -299,7 +299,9 @@ void _mi_assert_fail(const char* assertion, const char* fname, unsigned int line
#define MI_INIT64(x) MI_INIT32(x),MI_INIT32(x)
#define MI_INIT128(x) MI_INIT64(x),MI_INIT64(x)
#define MI_INIT256(x) MI_INIT128(x),MI_INIT128(x)
#define MI_INIT74(x) MI_INIT64(x),MI_INIT8(x),x(),x()
#define MI_INIT5(x) MI_INIT4(x),x()
#include <string.h>
// initialize a local variable to zero; use memset as compilers optimize constant sized memset's