diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 6 | ||||
-rw-r--r-- | cli/main.rs | 14 |
2 files changed, 19 insertions, 1 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f1a8ca0a2..837f98f5b 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -38,6 +38,11 @@ path = "./bench/lsp_bench_standalone.rs" [features] default = ["upgrade", "__vendored_zlib_ng"] +# A feature that enables heap profiling with dhat on Linux. +# 1. Compile with `cargo build --profile=release-with-debug --features=dhat-heap` +# 2. Run the executable. It will output a dhat-heap.json file. +# 3. Open the json file in https://nnethercote.github.io/dh_view/dh_view.html +dhat-heap = ["dhat"] # A feature that enables the upgrade subcommand and the background check for # available updates (of deno binary). This is typically disabled for (Linux) # distribution packages. @@ -98,6 +103,7 @@ color-print.workspace = true console_static_text.workspace = true dashmap.workspace = true data-encoding.workspace = true +dhat = { version = "0.3.3", optional = true } dissimilar = "=1.0.4" dotenvy = "0.15.7" dprint-plugin-json = "=0.19.3" diff --git a/cli/main.rs b/cli/main.rs index 360307d75..d99a4c402 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -61,6 +61,10 @@ use std::ops::Deref; use std::path::PathBuf; use std::sync::Arc; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + /// Ensures that all subcommands return an i32 exit code and an [`AnyError`] error type. trait SubcommandOutput { fn output(self) -> Result<i32, AnyError>; @@ -387,6 +391,9 @@ pub(crate) fn unstable_exit_cb(feature: &str, api_name: &str) { } pub fn main() { + #[cfg(feature = "dhat-heap")] + let profiler = dhat::Profiler::new_heap(); + setup_panic_hook(); util::unix::raise_fd_limit(); @@ -407,7 +414,12 @@ pub fn main() { run_subcommand(Arc::new(flags)).await }; - match create_and_run_current_thread_with_maybe_metrics(future) { + let result = create_and_run_current_thread_with_maybe_metrics(future); + + #[cfg(feature = "dhat-heap")] + drop(profiler); + + match result { Ok(exit_code) => std::process::exit(exit_code), Err(err) => exit_for_error(err), } |