node: Heap Profiling with DHAT

This commit is contained in:
Lorenz Leutgeb 2026-05-22 12:35:14 +02:00 committed by Fintan Halpenny
parent d8bf84c173
commit cf108311dc
3 changed files with 44 additions and 0 deletions

35
Cargo.lock generated
View File

@ -812,6 +812,22 @@ dependencies = [
"syn 2.0.117", "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]] [[package]]
name = "diff" name = "diff"
version = "0.1.13" version = "0.1.13"
@ -2321,6 +2337,12 @@ dependencies = [
"simd-adler32", "simd-adler32",
] ]
[[package]]
name = "mintex"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c505b3e17ed6b70a7ed2e67fbb2c560ee327353556120d6e72f5232b6880d536"
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.1.1" version = "1.1.1"
@ -3138,6 +3160,7 @@ dependencies = [
"bytes", "bytes",
"crossbeam-channel", "crossbeam-channel",
"cyphernet", "cyphernet",
"dhat",
"fastrand", "fastrand",
"gix-packetline", "gix-packetline",
"indexmap", "indexmap",
@ -3485,6 +3508,12 @@ version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d" checksum = "b50b8869d9fc858ce7266cce0194bd74df58b9d0e3f6df3a9fc8eb470d95c09d"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]] [[package]]
name = "rustc_version" name = "rustc_version"
version = "0.4.1" version = "0.4.1"
@ -4286,6 +4315,12 @@ dependencies = [
"syn 2.0.117", "syn 2.0.117",
] ]
[[package]]
name = "thousands"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.1.9" version = "1.1.9"

View File

@ -11,6 +11,7 @@ rust-version.workspace = true
[features] [features]
default = ["backtrace", "i2p", "systemd", "structured-logger", "socket2", "tor"] default = ["backtrace", "i2p", "systemd", "structured-logger", "socket2", "tor"]
dhat-heap = ["dep:dhat"]
i2p = ["cyphernet/i2p", "radicle/i2p", "radicle-protocol/i2p"] i2p = ["cyphernet/i2p", "radicle/i2p", "radicle-protocol/i2p"]
systemd = ["dep:radicle-systemd"] systemd = ["dep:radicle-systemd"]
test = ["radicle/test", "radicle-crypto/test", "radicle-crypto/cyphernet", "radicle-protocol/test", "qcheck", "snapbox"] 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 } bytes = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
cyphernet = { workspace = true, features = ["dns", "ed25519", "p2p-ed25519", "noise-framework", "noise_sha2"] } cyphernet = { workspace = true, features = ["dns", "ed25519", "p2p-ed25519", "noise-framework", "noise_sha2"] }
dhat = { version = "0.3.3", optional = true }
fastrand = { workspace = true } fastrand = { workspace = true }
gix-packetline = { workspace = true, features = ["blocking-io"] } gix-packetline = { workspace = true, features = ["blocking-io"] }
indexmap = { workspace = true } indexmap = { workspace = true }

View File

@ -41,6 +41,10 @@ Options
--help Print help --help Print help
"#; "#;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
enum Logger { enum Logger {
Radicle, Radicle,
@ -449,6 +453,9 @@ fn panic_hook(info: &std::panic::PanicHookInfo) {
} }
fn main() { fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let options = parse_options().unwrap_or_else(|err| { let options = parse_options().unwrap_or_else(|err| {
// The lexopt errors read nicely with a comma. // The lexopt errors read nicely with a comma.
eprintln!("Failed to parse options, {err:#}"); eprintln!("Failed to parse options, {err:#}");