Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao-su committed Jul 31, 2023
1 parent abc23a6 commit 9611a81
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi

cargo build --target "${TARGET}"
cargo test --target "${TARGET}"
cargo test --target "${TARGET}" --features profiling
_RJEM_MALLOC_CONF="prof:true" cargo test --target "${TARGET}" --features profiling
cargo test --target "${TARGET}" --features debug
cargo test --target "${TARGET}" --features stats
cargo test --target "${TARGET}" --features 'debug profiling'
Expand Down
26 changes: 22 additions & 4 deletions jemalloc-ctl/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro_rules! types {

/// Read
macro_rules! r {
($id:ident => $ret_ty:ty) => {
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
paste::paste! {
impl $id {
/// Reads value using string API.
Expand Down Expand Up @@ -72,6 +72,12 @@ macro_rules! r {
if cfg!(target_os = "macos") => return,
_ => (),
}
match $byte_string.as_slice() {
b"opt.prof\0" |
b"prof.active\0"
if !cfg!(feature = "profiling") => return,
_ => (),
}

let a = $id::read().unwrap();

Expand All @@ -92,7 +98,7 @@ macro_rules! r {

/// Write
macro_rules! w {
($id:ident => $ret_ty:ty) => {
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
paste::paste! {
impl $id {
/// Writes `value` using string API.
Expand Down Expand Up @@ -140,6 +146,13 @@ macro_rules! w {
if cfg!(target_os = "macos") => return,
_ => (),
}
match $byte_string.as_slice() {
b"prof.dump\0" |
b"prof.active\0" |
b"prof.prefix\0"
if !cfg!(feature = "profiling") => return,
_ => (),
}

let _ = $id::write(<$ret_ty as WriteTestDefault>::default()).unwrap();

Expand All @@ -161,7 +174,7 @@ macro_rules! w {

/// Update
macro_rules! u {
($id:ident => $ret_ty:ty) => {
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
paste::paste! {
impl $id {
/// Updates key to `value` returning its old value using string API.
Expand Down Expand Up @@ -190,6 +203,11 @@ macro_rules! u {
if cfg!(target_os = "macos") => return,
_ => (),
}
match $byte_string.as_slice() {
b"prof.active\0"
if !cfg!(feature = "profiling") => return,
_ => (),
}

let a = $id::update($ret_ty::default()).unwrap();

Expand Down Expand Up @@ -223,7 +241,7 @@ macro_rules! option {
mib_docs: $(#[$doc_mib])*
}
$(
$ops!($id => $ret_ty);
$ops!($id[ str: $byte_string ] => $ret_ty);
)*
};
// Non-string option:
Expand Down
11 changes: 7 additions & 4 deletions jemalloc-ctl/src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,13 @@ option! {
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::opt;
/// let prof = opt::prof::read().unwrap();
/// println!("Jemalloc profiling enabled: {}", prof);
/// #[cfg(feature = "profiling")]
/// {
/// use tikv_jemalloc_ctl::opt;
/// let prof = opt::prof::read().unwrap();
/// println!("Jemalloc profiling enabled: {}", prof);
/// }
/// # }
/// ```
mib_docs: /// See [`prof`].
}
}
35 changes: 22 additions & 13 deletions jemalloc-ctl/src/prof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ option! {
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
/// let dump = prof::dump::mib().unwrap();
/// dump.write(dump_file_name).unwrap();
/// #[cfg(feature = "profiling")]
/// {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
/// let dump = prof::dump::mib().unwrap();
/// dump.write(dump_file_name).unwrap();
/// }
/// # }
/// ```
mib_docs: /// See [`dump`].
Expand All @@ -42,11 +45,14 @@ option! {
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
/// let prefix = prof::prefix::mib().unwrap();
/// prefix.write(dump_file_name).unwrap();
/// #[cfg(feature = "profiling")]
/// {
/// use tikv_jemalloc_ctl::prof;
/// use std::ffi::CStr;
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
/// let prefix = prof::prefix::mib().unwrap();
/// prefix.write(dump_file_name).unwrap();
/// }
/// # }
/// ```
mib_docs: /// See [`prefix`].
Expand All @@ -68,9 +74,12 @@ option! {
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
/// #
/// # fn main() {
/// use tikv_jemalloc_ctl::prof;
/// let active = prof::active::mib().unwrap();
/// active.write(true).unwrap();
/// #[cfg(feature = "profiling")]
/// {
/// use tikv_jemalloc_ctl::prof;
/// let active = prof::active::mib().unwrap();
/// active.write(true).unwrap();
/// }
/// # }
/// ```
mib_docs: /// See [`active`].
Expand Down

0 comments on commit 9611a81

Please sign in to comment.