handle the case where 0 or >1 allocs are enabled

In particular this fixes `cargo build --all-features`.
This commit is contained in:
Charles Hall 2024-04-27 16:08:50 -07:00 committed by June
parent e0c0d51a05
commit 3b05417246
5 changed files with 29 additions and 24 deletions

View file

@ -1,6 +1,3 @@
#![cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
#![allow(dead_code)]
use std::ffi::{c_char, c_void};
use tikv_jemalloc_ctl as mallctl;
@ -10,8 +7,6 @@ use tikv_jemallocator as jemalloc;
#[global_allocator]
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
pub(crate) fn version() -> &'static str { mallctl::version::read().expect("version string") }
pub(crate) fn memory_usage() -> String {
use mallctl::stats;
let allocated = stats::allocated::read().unwrap_or_default() as f64 / 1024.0 / 1024.0;