Skip to content

Commit 4eca9c6

Browse files
committed
fix test
Signed-off-by: Yuhao Su <[email protected]>
1 parent bb3bf17 commit 4eca9c6

File tree

4 files changed

+52
-22
lines changed

4 files changed

+52
-22
lines changed

ci/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fi
2626

2727
cargo build --target "${TARGET}"
2828
cargo test --target "${TARGET}"
29-
cargo test --target "${TARGET}" --features profiling
29+
_RJEM_MALLOC_CONF="prof:true" cargo test --target "${TARGET}" --features profiling
3030
cargo test --target "${TARGET}" --features debug
3131
cargo test --target "${TARGET}" --features stats
3232
cargo test --target "${TARGET}" --features 'debug profiling'

jemalloc-ctl/src/macros.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ macro_rules! types {
4343

4444
/// Read
4545
macro_rules! r {
46-
($id:ident => $ret_ty:ty) => {
46+
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
4747
paste::paste! {
4848
impl $id {
4949
/// Reads value using string API.
@@ -72,6 +72,12 @@ macro_rules! r {
7272
if cfg!(target_os = "macos") => return,
7373
_ => (),
7474
}
75+
match $byte_string.as_slice() {
76+
b"opt.prof\0" |
77+
b"prof.active\0"
78+
if !cfg!(feature = "profiling") => return,
79+
_ => (),
80+
}
7581

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

@@ -92,7 +98,7 @@ macro_rules! r {
9298

9399
/// Write
94100
macro_rules! w {
95-
($id:ident => $ret_ty:ty) => {
101+
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
96102
paste::paste! {
97103
impl $id {
98104
/// Writes `value` using string API.
@@ -140,6 +146,13 @@ macro_rules! w {
140146
if cfg!(target_os = "macos") => return,
141147
_ => (),
142148
}
149+
match $byte_string.as_slice() {
150+
b"prof.dump\0" |
151+
b"prof.active\0" |
152+
b"prof.prefix\0"
153+
if !cfg!(feature = "profiling") => return,
154+
_ => (),
155+
}
143156

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

@@ -161,7 +174,7 @@ macro_rules! w {
161174

162175
/// Update
163176
macro_rules! u {
164-
($id:ident => $ret_ty:ty) => {
177+
($id:ident[ str: $byte_string:expr ] => $ret_ty:ty) => {
165178
paste::paste! {
166179
impl $id {
167180
/// Updates key to `value` returning its old value using string API.
@@ -190,6 +203,11 @@ macro_rules! u {
190203
if cfg!(target_os = "macos") => return,
191204
_ => (),
192205
}
206+
match $byte_string.as_slice() {
207+
b"prof.active\0"
208+
if !cfg!(feature = "profiling") => return,
209+
_ => (),
210+
}
193211

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

@@ -223,7 +241,7 @@ macro_rules! option {
223241
mib_docs: $(#[$doc_mib])*
224242
}
225243
$(
226-
$ops!($id => $ret_ty);
244+
$ops!($id[ str: $byte_string ] => $ret_ty);
227245
)*
228246
};
229247
// Non-string option:

jemalloc-ctl/src/opt.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,13 @@ option! {
229229
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
230230
/// #
231231
/// # fn main() {
232-
/// use tikv_jemalloc_ctl::opt;
233-
/// let prof = opt::prof::read().unwrap();
234-
/// println!("Jemalloc profiling enabled: {}", prof);
232+
/// #[cfg(feature = "profiling")]
233+
/// {
234+
/// use tikv_jemalloc_ctl::opt;
235+
/// let prof = opt::prof::read().unwrap();
236+
/// println!("Jemalloc profiling enabled: {}", prof);
237+
/// }
235238
/// # }
236239
/// ```
237240
mib_docs: /// See [`prof`].
238-
}
241+
}

jemalloc-ctl/src/prof.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ option! {
1717
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
1818
/// #
1919
/// # fn main() {
20-
/// use tikv_jemalloc_ctl::prof;
21-
/// use std::ffi::CStr;
22-
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
23-
/// let dump = prof::dump::mib().unwrap();
24-
/// dump.write(dump_file_name).unwrap();
20+
/// #[cfg(feature = "profiling")]
21+
/// {
22+
/// use tikv_jemalloc_ctl::prof;
23+
/// use std::ffi::CStr;
24+
/// let dump_file_name = CStr::from_bytes_with_nul(b"dump\0").unwrap();
25+
/// let dump = prof::dump::mib().unwrap();
26+
/// dump.write(dump_file_name).unwrap();
27+
/// }
2528
/// # }
2629
/// ```
2730
mib_docs: /// See [`dump`].
@@ -42,11 +45,14 @@ option! {
4245
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
4346
/// #
4447
/// # fn main() {
45-
/// use tikv_jemalloc_ctl::prof;
46-
/// use std::ffi::CStr;
47-
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
48-
/// let prefix = prof::prefix::mib().unwrap();
49-
/// prefix.write(dump_file_name).unwrap();
48+
/// #[cfg(feature = "profiling")]
49+
/// {
50+
/// use tikv_jemalloc_ctl::prof;
51+
/// use std::ffi::CStr;
52+
/// let dump_file_name = CStr::from_bytes_with_nul(b"my_prefix\0").unwrap();
53+
/// let prefix = prof::prefix::mib().unwrap();
54+
/// prefix.write(dump_file_name).unwrap();
55+
/// }
5056
/// # }
5157
/// ```
5258
mib_docs: /// See [`prefix`].
@@ -68,9 +74,12 @@ option! {
6874
/// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
6975
/// #
7076
/// # fn main() {
71-
/// use tikv_jemalloc_ctl::prof;
72-
/// let active = prof::active::mib().unwrap();
73-
/// active.write(true).unwrap();
77+
/// #[cfg(feature = "profiling")]
78+
/// {
79+
/// use tikv_jemalloc_ctl::prof;
80+
/// let active = prof::active::mib().unwrap();
81+
/// active.write(true).unwrap();
82+
/// }
7483
/// # }
7584
/// ```
7685
mib_docs: /// See [`active`].

0 commit comments

Comments
 (0)