microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.19.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/allocator/mimalloc-sys/mimalloc/include/mimalloc-stats.h

103lines · modeblame

ce21e681Ian Davis11 months ago1/* ----------------------------------------------------------------------------
2Copyright (c) 2018-2025, Microsoft Research, Daan Leijen
3This is free software; you can redistribute it and/or modify it under the
4terms of the MIT license. A copy of the license can be found in the file
5"LICENSE" at the root of this distribution.
6-----------------------------------------------------------------------------*/
7#pragma once
8#ifndef MIMALLOC_STATS_H
9#define MIMALLOC_STATS_H
10
11#include <mimalloc.h>
12#include <stdint.h>
13
14#define MI_STAT_VERSION 1 // increased on every backward incompatible change
15
16// count allocation over time
17typedef struct mi_stat_count_s {
18int64_t total; // total allocated
19int64_t peak; // peak allocation
20int64_t current; // current allocation
21} mi_stat_count_t;
22
23// counters only increase
24typedef struct mi_stat_counter_s {
25int64_t total; // total count
26} mi_stat_counter_t;
27
28#define MI_STAT_FIELDS() \
29MI_STAT_COUNT(pages) /* count of mimalloc pages */ \
30MI_STAT_COUNT(reserved) /* reserved memory bytes */ \
31MI_STAT_COUNT(committed) /* committed bytes */ \
32MI_STAT_COUNT(reset) /* reset bytes */ \
33MI_STAT_COUNT(purged) /* purged bytes */ \
34MI_STAT_COUNT(page_committed) /* committed memory inside pages */ \
35MI_STAT_COUNT(pages_abandoned) /* abandonded pages count */ \
36MI_STAT_COUNT(threads) /* number of threads */ \
37MI_STAT_COUNT(malloc_normal) /* allocated bytes <= MI_LARGE_OBJ_SIZE_MAX */ \
38MI_STAT_COUNT(malloc_huge) /* allocated bytes in huge pages */ \
39MI_STAT_COUNT(malloc_requested) /* malloc requested bytes */ \
40\
41MI_STAT_COUNTER(mmap_calls) \
42MI_STAT_COUNTER(commit_calls) \
43MI_STAT_COUNTER(reset_calls) \
44MI_STAT_COUNTER(purge_calls) \
45MI_STAT_COUNTER(arena_count) /* number of memory arena's */ \
46MI_STAT_COUNTER(malloc_normal_count) /* number of blocks <= MI_LARGE_OBJ_SIZE_MAX */ \
47MI_STAT_COUNTER(malloc_huge_count) /* number of huge bloks */ \
48MI_STAT_COUNTER(malloc_guarded_count) /* number of allocations with guard pages */ \
49\
50/* internal statistics */ \
51MI_STAT_COUNTER(arena_rollback_count) \
52MI_STAT_COUNTER(arena_purges) \
53MI_STAT_COUNTER(pages_extended) /* number of page extensions */ \
54MI_STAT_COUNTER(pages_retire) /* number of pages that are retired */ \
55MI_STAT_COUNTER(page_searches) /* searches for a fresh page */ \
56/* only on v1 and v2 */ \
57MI_STAT_COUNT(segments) \
58MI_STAT_COUNT(segments_abandoned) \
59MI_STAT_COUNT(segments_cache) \
60MI_STAT_COUNT(_segments_reserved) \
61/* only on v3 */ \
62MI_STAT_COUNTER(pages_reclaim_on_alloc) \
63MI_STAT_COUNTER(pages_reclaim_on_free) \
64MI_STAT_COUNTER(pages_reabandon_full) \
65MI_STAT_COUNTER(pages_unabandon_busy_wait) \
66
67
68// Define the statistics structure
69#define MI_BIN_HUGE (73U) // see types.h
70#define MI_STAT_COUNT(stat) mi_stat_count_t stat;
71#define MI_STAT_COUNTER(stat) mi_stat_counter_t stat;
72
73typedef struct mi_stats_s
74{
75int version;
76
77MI_STAT_FIELDS()
78
79// future extension
80mi_stat_count_t _stat_reserved[4];
81mi_stat_counter_t _stat_counter_reserved[4];
82
83// size segregated statistics
84mi_stat_count_t malloc_bins[MI_BIN_HUGE+1]; // allocation per size bin
85mi_stat_count_t page_bins[MI_BIN_HUGE+1]; // pages allocated per size bin
86} mi_stats_t;
87
88#undef MI_STAT_COUNT
89#undef MI_STAT_COUNTER
90
91// Exported definitions
92#ifdef __cplusplus
93extern "C" {
94#endif
95
96mi_decl_export void mi_stats_get( size_t stats_size, mi_stats_t* stats ) mi_attr_noexcept;
97mi_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
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif // MIMALLOC_STATS_H