handle the case where 0 or >1 allocs are enabled
In particular this fixes `cargo build --all-features`.
This commit is contained in:
parent
e0c0d51a05
commit
3b05417246
5 changed files with 29 additions and 24 deletions
7
src/alloc/default.rs
Normal file
7
src/alloc/default.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
//! Default allocator with no special features
|
||||
|
||||
/// Always returns the empty string
|
||||
pub(crate) fn memory_stats() -> String { Default::default() }
|
||||
|
||||
/// Always returns the empty string
|
||||
pub(crate) fn memory_usage() -> String { Default::default() }
|
|
@ -1,5 +1,3 @@
|
|||
#![cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
|
||||
|
||||
#[global_allocator]
|
||||
static HMALLOC: hardened_malloc_rs::HardenedMalloc = hardened_malloc_rs::HardenedMalloc;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,20 +1,25 @@
|
|||
pub(crate) mod hardened;
|
||||
pub(crate) mod je;
|
||||
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
|
||||
pub(crate) fn memory_usage() -> String { hardened::memory_usage() }
|
||||
//! Integration with allocators
|
||||
|
||||
// jemalloc
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
|
||||
pub(crate) fn memory_usage() -> String { je::memory_usage() }
|
||||
|
||||
#[cfg(any(target_env = "msvc", all(not(feature = "jemalloc"), not(feature = "hardened_malloc"))))]
|
||||
pub(crate) fn memory_usage() -> String { String::default() }
|
||||
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
|
||||
pub(crate) fn memory_stats() -> String { hardened::memory_stats() }
|
||||
|
||||
mod je;
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))]
|
||||
pub(crate) fn memory_stats() -> String { je::memory_stats() }
|
||||
pub(crate) use je::{memory_stats, memory_usage};
|
||||
|
||||
#[cfg(any(target_env = "msvc", all(not(feature = "jemalloc"), not(feature = "hardened_malloc"))))]
|
||||
pub(crate) fn memory_stats() -> String { String::default() }
|
||||
// hardened_malloc
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
|
||||
mod hardened;
|
||||
#[cfg(all(not(target_env = "msvc"), feature = "hardened_malloc", target_os = "linux", not(feature = "jemalloc")))]
|
||||
pub(crate) use hardened::{memory_stats, memory_usage};
|
||||
|
||||
// default, enabled when none or multiple of the above are enabled
|
||||
#[cfg(any(
|
||||
not(any(feature = "jemalloc", feature = "hardened_malloc")),
|
||||
all(feature = "jemalloc", feature = "hardened_malloc"),
|
||||
))]
|
||||
mod default;
|
||||
#[cfg(any(
|
||||
not(any(feature = "jemalloc", feature = "hardened_malloc")),
|
||||
all(feature = "jemalloc", feature = "hardened_malloc"),
|
||||
))]
|
||||
pub(crate) use default::{memory_stats, memory_usage};
|
||||
|
|
|
@ -49,7 +49,7 @@ use utils::{
|
|||
error::{Error, Result},
|
||||
};
|
||||
|
||||
mod alloc;
|
||||
pub(crate) mod alloc;
|
||||
mod api;
|
||||
mod config;
|
||||
mod database;
|
||||
|
|
Loading…
Add table
Reference in a new issue