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

@ -400,17 +400,17 @@ version = "0.34.0"
git = "https://github.com/girlbossceo/jemallocator" git = "https://github.com/girlbossceo/jemallocator"
rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294"
default-features = false default-features = false
features = ["stats", "unprefixed_malloc_on_supported_platforms"] features = ["unprefixed_malloc_on_supported_platforms"]
[workspace.dependencies.tikv-jemallocator] [workspace.dependencies.tikv-jemallocator]
git = "https://github.com/girlbossceo/jemallocator" git = "https://github.com/girlbossceo/jemallocator"
rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294"
default-features = false default-features = false
features = ["stats", "unprefixed_malloc_on_supported_platforms"] features = ["unprefixed_malloc_on_supported_platforms"]
[workspace.dependencies.tikv-jemalloc-ctl] [workspace.dependencies.tikv-jemalloc-ctl]
git = "https://github.com/girlbossceo/jemallocator" git = "https://github.com/girlbossceo/jemallocator"
rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294" rev = "c32af15f3b440ae5e46c3404f78b19093bbd5294"
default-features = false default-features = false
features = ["stats", "use_std"] features = ["use_std"]
[workspace.dependencies.console-subscriber] [workspace.dependencies.console-subscriber]
version = "0.4" version = "0.4"

View file

@ -57,7 +57,9 @@ rust-jemalloc-sys' = (rust-jemalloc-sys.override {
# we dont need cxx/C++ integration # we dont need cxx/C++ integration
[ "--disable-cxx" ] ++ [ "--disable-cxx" ] ++
# tikv-jemalloc-sys/profiling feature # tikv-jemalloc-sys/profiling feature
lib.optional (featureEnabled "jemalloc_prof") "--enable-prof"; lib.optional (featureEnabled "jemalloc_prof") "--enable-prof" ++
# tikv-jemalloc-sys/stats feature
(if (featureEnabled "jemalloc_stats") then [ "--enable-stats" ] else [ "--disable-stats" ]);
}); });
buildDepsOnlyEnv = buildDepsOnlyEnv =

View file

@ -32,6 +32,11 @@ jemalloc = [
jemalloc_prof = [ jemalloc_prof = [
"tikv-jemalloc-sys/profiling", "tikv-jemalloc-sys/profiling",
] ]
jemalloc_stats = [
"tikv-jemalloc-sys/stats",
"tikv-jemalloc-ctl/stats",
"tikv-jemallocator/stats",
]
hardened_malloc = [ hardened_malloc = [
"dep:hardened_malloc-rs" "dep:hardened_malloc-rs"
] ]

View file

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

View file

@ -87,6 +87,9 @@ jemalloc = [
jemalloc_prof = [ jemalloc_prof = [
"conduit-core/jemalloc_prof", "conduit-core/jemalloc_prof",
] ]
jemalloc_stats = [
"conduit-core/jemalloc_stats",
]
perf_measurements = [ perf_measurements = [
"dep:opentelemetry", "dep:opentelemetry",
"dep:tracing-flame", "dep:tracing-flame",