1313//! `$op::{read(), write(x), update(x)}` on the type calls `mallctl` with the
1414//! string-based API. If the operation will be repeatedly performed, a MIB for
1515//! the operation can be obtained using `$op.mib()`.
16- //!
17- //! # Examples
18- //!
19- //! Repeatedly printing allocation statistics:
20- //!
21- //! ```no_run
22- //! use std::thread;
23- //! use std::time::Duration;
24- //! use tikv_jemalloc_ctl::{stats, epoch};
25- //!
26- //! #[global_allocator]
27- //! static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
28- //!
29- //! fn main() {
30- //! loop {
31- //! // many statistics are cached and only updated when the epoch is advanced.
32- //! epoch::advance().unwrap();
33- //!
34- //! let allocated = stats::allocated::read().unwrap();
35- //! let resident = stats::resident::read().unwrap();
36- //! println!("{} bytes allocated/{} bytes resident", allocated, resident);
37- //! thread::sleep(Duration::from_secs(10));
38- //! }
39- //! }
40- //! ```
41- //!
42- //! Doing the same with the MIB-based API:
43- //!
44- //! ```no_run
45- //! use std::thread;
46- //! use std::time::Duration;
47- //! use tikv_jemalloc_ctl::{stats, epoch};
48- //!
49- //! #[global_allocator]
50- //! static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
51- //!
52- //! fn main() {
53- //! let e = epoch::mib().unwrap();
54- //! let allocated = stats::allocated::mib().unwrap();
55- //! let resident = stats::resident::mib().unwrap();
56- //! loop {
57- //! // many statistics are cached and only updated when the epoch is advanced.
58- //! e.advance().unwrap();
59- //!
60- //! let allocated = allocated.read().unwrap();
61- //! let resident = resident.read().unwrap();
62- //! println!("{} bytes allocated/{} bytes resident", allocated, resident);
63- //! thread::sleep(Duration::from_secs(10));
64- //! }
65- //! }
66- //! ```
16+ #![ cfg_attr(
17+ feature = "stats" ,
18+ doc = r##"
19+
20+ # Examples
21+
22+ Repeatedly printing allocation statistics:
23+
24+ ```no_run
25+ use std::thread;
26+ use std::time::Duration;
27+ use tikv_jemalloc_ctl::{stats, epoch};
28+
29+ #[global_allocator]
30+ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
31+
32+ fn main() {
33+ loop {
34+ // many statistics are cached and only updated when the epoch is advanced.
35+ epoch::advance().unwrap();
36+
37+ let allocated = stats::allocated::read().unwrap();
38+ let resident = stats::resident::read().unwrap();
39+ println!("{} bytes allocated/{} bytes resident", allocated, resident);
40+ thread::sleep(Duration::from_secs(10));
41+ }
42+ }
43+ ```
44+
45+ Doing the same with the MIB-based API:
46+
47+ ```no_run
48+ use std::thread;
49+ use std::time::Duration;
50+ use tikv_jemalloc_ctl::{stats, epoch};
51+
52+ #[global_allocator]
53+ static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
54+
55+ fn main() {
56+ let e = epoch::mib().unwrap();
57+ let allocated = stats::allocated::mib().unwrap();
58+ let resident = stats::resident::mib().unwrap();
59+ loop {
60+ // many statistics are cached and only updated when the epoch is advanced.
61+ e.advance().unwrap();
62+
63+ let allocated = allocated.read().unwrap();
64+ let resident = resident.read().unwrap();
65+ println!("{} bytes allocated/{} bytes resident", allocated, resident);
66+ thread::sleep(Duration::from_secs(10));
67+ }
68+ }
69+ ```
70+ "##
71+ ) ]
6772// TODO: rename the following lint on next minor bump
6873#![ allow( renamed_and_removed_lints) ]
6974#![ deny( missing_docs, broken_intra_doc_links) ]
@@ -90,6 +95,7 @@ pub mod opt;
9095#[ cfg( feature = "profiling" ) ]
9196pub mod profiling;
9297pub mod raw;
98+ #[ cfg( feature = "stats" ) ]
9399pub mod stats;
94100#[ cfg( feature = "use_std" ) ]
95101pub mod stats_print;
0 commit comments