1
// At most one `#[global_allocator]` may exist, so the backends below are
2
// mutually exclusive: `metrics` takes precedence and suppresses `jemalloc`
3
// and `mimalloc`, and enabling both `jemalloc` and `mimalloc` at once will
4
// fail to compile (two `#[global_allocator]` statics).
5
#[cfg(feature = "metrics")]
6
use log::info;
7

            
8
#[cfg(feature = "metrics")]
9
#[global_allocator]
10
static GLOBAL_ALLOCATOR: crate::AllocCounter = crate::AllocCounter::new();
11

            
12
#[cfg(not(target_env = "msvc"))]
13
#[cfg(not(feature = "metrics"))]
14
#[cfg(feature = "jemalloc")]
15
#[global_allocator]
16
static GLOBAL_ALLOCATOR: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
17

            
18
#[cfg(not(feature = "metrics"))]
19
#[cfg(feature = "mimalloc")]
20
#[global_allocator]
21
static GLOBAL_ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc;
22

            
23
/// Prints information from the [AllocCounter].
24
#[cfg(feature = "metrics")]
25
pub fn print_allocator_metrics() {
26
    info!("{}", GLOBAL_ALLOCATOR.get_metrics());
27
}
28

            
29
#[cfg(not(feature = "metrics"))]
30
pub fn print_allocator_metrics() {}