diff --git a/Cargo.lock b/Cargo.lock index 47233b63..e7092a48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -812,6 +812,22 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "dhat" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot", + "rustc-hash", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "diff" version = "0.1.13" @@ -2321,6 +2337,12 @@ dependencies = [ "simd-adler32", ] +[[package]] +name = "mintex" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c505b3e17ed6b70a7ed2e67fbb2c560ee327353556120d6e72f5232b6880d536" + [[package]] name = "mio" version = "1.1.1" @@ -3138,6 +3160,7 @@ dependencies = [ "bytes", "crossbeam-channel", "cyphernet", + "dhat", "fastrand", "gix-packetline", "indexmap", @@ -3485,6 +3508,12 @@ version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustc_version" version = "0.4.1" @@ -4286,6 +4315,12 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "thousands" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820" + [[package]] name = "thread_local" version = "1.1.9" diff --git a/crates/radicle-node/Cargo.toml b/crates/radicle-node/Cargo.toml index 1f7d271e..80c75719 100644 --- a/crates/radicle-node/Cargo.toml +++ b/crates/radicle-node/Cargo.toml @@ -11,6 +11,7 @@ rust-version.workspace = true [features] default = ["backtrace", "i2p", "systemd", "structured-logger", "socket2", "tor"] +dhat-heap = ["dep:dhat"] i2p = ["cyphernet/i2p", "radicle/i2p", "radicle-protocol/i2p"] systemd = ["dep:radicle-systemd"] test = ["radicle/test", "radicle-crypto/test", "radicle-crypto/cyphernet", "radicle-protocol/test", "qcheck", "snapbox"] @@ -21,6 +22,7 @@ backtrace = { workspace = true, optional = true } bytes = { workspace = true } crossbeam-channel = { workspace = true } cyphernet = { workspace = true, features = ["dns", "ed25519", "p2p-ed25519", "noise-framework", "noise_sha2"] } +dhat = { version = "0.3.3", optional = true } fastrand = { workspace = true } gix-packetline = { workspace = true, features = ["blocking-io"] } indexmap = { workspace = true } diff --git a/crates/radicle-node/src/main.rs b/crates/radicle-node/src/main.rs index fb87335f..61251f7e 100644 --- a/crates/radicle-node/src/main.rs +++ b/crates/radicle-node/src/main.rs @@ -41,6 +41,10 @@ Options --help Print help "#; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + #[derive(Debug, Clone)] enum Logger { Radicle, @@ -449,6 +453,9 @@ fn panic_hook(info: &std::panic::PanicHookInfo) { } fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + let options = parse_options().unwrap_or_else(|err| { // The lexopt errors read nicely with a comma. eprintln!("Failed to parse options, {err:#}");