diff --git a/measure/Cargo.toml b/measure/Cargo.toml index 4bd3763d0..e7b4a1f47 100644 --- a/measure/Cargo.toml +++ b/measure/Cargo.toml @@ -19,5 +19,12 @@ solana-metrics = { path = "../metrics", version = "1.6.0" } jemallocator = "0.3.2" jemalloc-ctl = "0.3.2" +[features] +# mainly for heaptrack, which seems to be incompatible with jemalloc +# opt-out ("no-" prefix) is chosen for convenience for the default case +# (= with jemalloc), considering complexies of proper opt-in (default) +# feature plumbing +no-jemalloc = [] + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] diff --git a/measure/src/lib.rs b/measure/src/lib.rs index d2848c956..b2388e64b 100644 --- a/measure/src/lib.rs +++ b/measure/src/lib.rs @@ -4,6 +4,7 @@ pub mod thread_mem_usage; #[cfg(unix)] extern crate jemallocator; +#[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] #[global_allocator] static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; diff --git a/measure/src/thread_mem_usage.rs b/measure/src/thread_mem_usage.rs index cf8056259..48c63dc83 100644 --- a/measure/src/thread_mem_usage.rs +++ b/measure/src/thread_mem_usage.rs @@ -1,7 +1,9 @@ +#[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] use jemalloc_ctl::thread; pub fn datapoint(_name: &'static str) { + #[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] { let allocated = thread::allocatedp::mib().unwrap(); @@ -12,29 +14,32 @@ pub fn datapoint(_name: &'static str) { } pub struct Allocatedp { + #[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] allocated: thread::ThreadLocal, } impl Allocatedp { pub fn default() -> Self { + #[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] { let allocated = thread::allocatedp::mib().unwrap(); let allocated = allocated.read().unwrap(); Self { allocated } } - #[cfg(not(unix))] + #[cfg(any(feature = "no-jemalloc", not(unix)))] Self {} } /// Return current thread heap usage pub fn get(&self) -> u64 { + #[cfg(not(feature = "no-jemalloc"))] #[cfg(unix)] { self.allocated.get() } - #[cfg(not(unix))] + #[cfg(any(feature = "no-jemalloc", not(unix)))] 0 }