ckb_memory_tracker/
lib.rs

1//! Track the memory usage of CKB.
2
3#[cfg(all(
4    not(target_env = "msvc"),
5    not(target_os = "macos"),
6    feature = "profiling"
7))]
8mod jemalloc;
9#[cfg(not(all(
10    not(target_env = "msvc"),
11    not(target_os = "macos"),
12    feature = "profiling"
13)))]
14mod jemalloc {
15    /// A dummy function which is used when the Jemalloc profiling isn't supported.
16    ///
17    /// Jemalloc profiling is disabled in default, the feature `profiling` is used to enable it.
18    pub fn jemalloc_profiling_dump(_: &str) -> Result<(), String> {
19        Err("jemalloc profiling dump: unsupported".to_string())
20    }
21}
22
23#[cfg(all(not(target_env = "msvc"), not(target_os = "macos")))]
24mod process;
25#[cfg(not(all(not(target_env = "msvc"), not(target_os = "macos"))))]
26mod process {
27    use std::sync;
28
29    use crate::rocksdb::TrackRocksDBMemory;
30    use ckb_logger::info;
31
32    /// A dummy function which is used when tracking memory usage isn't supported.
33    pub fn track_current_process<Tracker: 'static + TrackRocksDBMemory + Sync + Send>(
34        _: u64,
35        _: Option<sync::Arc<Tracker>>,
36    ) {
37        info!("track current process: unsupported");
38    }
39}
40mod rocksdb;
41
42pub use jemalloc::jemalloc_profiling_dump;
43pub use process::track_current_process;
44pub use rocksdb::TrackRocksDBMemory;
45
46/// Track the memory usage of the CKB process and Jemalloc.
47pub fn track_current_process_simple(interval: u64) {
48    track_current_process::<rocksdb::DummyRocksDB>(interval, None);
49}