make jemalloc stats an optional feature

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-08-18 17:36:33 -04:00 committed by Jason Volk
parent 867050df9e
commit 23690fd837
5 changed files with 20 additions and 5 deletions

View file

@ -2,7 +2,6 @@
use std::ffi::{c_char, c_void};
use tikv_jemalloc_ctl as mallctl;
use tikv_jemalloc_sys as ffi;
use tikv_jemallocator as jemalloc;
@ -10,8 +9,10 @@ use tikv_jemallocator as jemalloc;
static JEMALLOC: jemalloc::Jemalloc = jemalloc::Jemalloc;
#[must_use]
#[cfg(feature = "jemalloc_stats")]
pub fn memory_usage() -> Option<String> {
use mallctl::stats;
use tikv_jemalloc_ctl as mallctl;
let mibs = |input: Result<usize, mallctl::Error>| {
let input = input.unwrap_or_default();
@ -33,6 +34,10 @@ pub fn memory_usage() -> Option<String> {
))
}
#[must_use]
#[cfg(not(feature = "jemalloc_stats"))]
pub fn memory_usage() -> Option<String> { None }
#[must_use]
pub fn memory_stats() -> Option<String> {
const MAX_LENGTH: usize = 65536 - 4096;