tikv_jemalloc_ctl/
profiling.rs

1//! `jemalloc`'s run-time configuration for profiling-specific settings.
2//!
3//! These settings are controlled by the `MALLOC_CONF` environment variable.
4
5option! {
6    lg_prof_interval[ str: b"opt.lg_prof_interval\0", non_str: 2 ] => libc::ssize_t |
7    ops: r |
8    docs:
9    /// Average interval (log base 2) between memory profile dumps, as measured in bytes of
10    /// allocation activity.
11    ///
12    /// The actual interval between dumps may be sporadic because
13    /// decentralized allocation counters are used to avoid synchronization bottlenecks.
14    ///
15    /// Profiles are dumped to files named according to the pattern
16    /// \<prefix\>.\<pid\>.\<seq\>.i\<iseq\>.heap, where \<prefix\> is controlled by the
17    /// opt.prof_prefix and prof.prefix options. By default, interval-triggered profile dumping is
18    /// disabled (encoded as -1).
19    ///
20    /// # Examples
21    ///
22    /// ```
23    /// # #[global_allocator]
24    /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
25    /// #
26    /// # fn main() {
27    /// use tikv_jemalloc_ctl::profiling;
28    /// let lg_prof_interval = profiling::lg_prof_interval::read().unwrap();
29    /// println!("average interval between memory profile dumps: {}", lg_prof_interval);
30    /// # }
31    /// ```
32    mib_docs: /// See [`lg_prof_interval`].
33}
34
35option! {
36    lg_prof_sample[ str: b"opt.lg_prof_sample\0", non_str: 2 ] => libc::size_t |
37    ops: r |
38    docs:
39    /// Average interval (log base 2) between allocation samples, as measured in bytes of
40    /// allocation activity. Increasing the sampling interval decreases profile fidelity, but also
41    /// decreases the computational overhead.
42    ///
43    /// The default sample interval is 512 KiB (2^19 B).
44    ///
45    /// # Examples
46    ///
47    /// ```
48    /// # #[global_allocator]
49    /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
50    /// #
51    /// # fn main() {
52    /// use tikv_jemalloc_ctl::profiling;
53    /// let lg_prof_sample = profiling::lg_prof_sample::read().unwrap();
54    /// println!("average interval between allocation samples: {}", lg_prof_sample);
55    /// # }
56    /// ```
57    mib_docs: /// See [`lg_prof_sample`].
58}
59
60option! {
61    prof_final[ str: b"opt.prof_final\0", non_str: 2 ] => bool |
62    ops: r |
63    docs:
64    /// Use an atexit(3) function to dump final memory usage to a file named according to the
65    /// pattern \<prefix\>.\<pid\>.\<seq\>.f.heap, where \<prefix\> is controlled by the opt.prof_prefix
66    /// and prof.prefix options.
67    ///
68    /// Note that atexit() may allocate memory during application initialization and then deadlock
69    /// internally when jemalloc in turn calls `atexit()`, so this option is not universally usable
70    /// (though the application can register its own `atexit()` function with equivalent
71    /// functionality).
72    ///
73    /// This option is disabled by default.
74    ///
75    /// # Examples
76    ///
77    /// ```
78    /// # #[global_allocator]
79    /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
80    /// #
81    /// # fn main() {
82    /// use tikv_jemalloc_ctl::profiling;
83    /// let prof_final = profiling::prof_final::read().unwrap();
84    /// println!("dump final memory usage to file: {}", prof_final);
85    /// # }
86    /// ```
87    mib_docs: /// See [`prof_final`].
88}
89
90option! {
91    prof[ str: b"opt.prof\0", non_str: 2 ] => bool |
92    ops: r |
93    docs:
94    /// Memory profiling enabled/disabled.
95    ///
96    /// If enabled, profile memory allocation activity.
97    ///
98    /// See the `opt.prof_active` option for on-the-fly activation/deactivation.
99    ///
100    /// See the `opt.lg_prof_sample` option for probabilistic sampling control.
101    ///
102    /// See the `opt.prof_accum` option for control of cumulative sample reporting.
103    ///
104    /// See the `opt.lg_prof_interval` option for information on interval-triggered profile
105    /// dumping, the `opt.prof_gdump` option for information on high-water-triggered profile
106    /// dumping, and the `opt.prof_final` option for final profile dumping.
107    ///
108    /// Profile output is compatible with the jeprof command, which is based on the pprof that is
109    /// developed as part of the gperftools package. See `HEAP PROFILE FORMAT` for heap profile
110    /// format documentation.
111    ///
112    /// # Examples
113    ///
114    /// ```
115    /// # #[global_allocator]
116    /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
117    /// #
118    /// # fn main() {
119    /// use tikv_jemalloc_ctl::profiling;
120    /// let prof = profiling::prof::read().unwrap();
121    /// println!("is memory profiling enabled: {}", prof);
122    /// # }
123    /// ```
124    mib_docs: /// See [`prof`].
125}
126
127option! {
128    prof_leak[ str: b"opt.prof_leak\0", non_str: 2 ] => bool |
129    ops: r |
130    docs:
131    /// Leak reporting enabled/disabled.
132    ///
133    /// If enabled, use an `atexit(3)` function to report memory leaks detected by allocation
134    /// sampling.
135    ///
136    /// See the opt.prof option for information on analyzing heap profile output.
137    ///
138    /// Works only when combined with `opt.prof_final`, otherwise does nothing.
139    ///
140    /// This option is disabled by default.
141    ///
142    /// # Examples
143    ///
144    /// ```
145    /// # #[global_allocator]
146    /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
147    /// #
148    /// # fn main() {
149    /// use tikv_jemalloc_ctl::profiling;
150    /// let prof_leak = profiling::prof_leak::read().unwrap();
151    /// println!("is leak reporting enabled: {}", prof_leak);
152    /// # }
153    /// ```
154    mib_docs: /// See [`prof_leak`].
155}