From 173e27d2e81c9f4a299d1acdc881b832041b241c Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 14 Nov 2022 13:26:02 -0700 Subject: [PATCH] Add support for heap profiling using dhat refs: https://github.com/wez/wezterm/issues/2626 --- .gitignore | 1 + Cargo.lock | 43 +++++++++++++++++++++++++++++++++++++++++ wezterm-gui/Cargo.toml | 3 +++ wezterm-gui/src/main.rs | 7 +++++++ 4 files changed, 54 insertions(+) diff --git a/.gitignore b/.gitignore index 377635872..59509c753 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +dhat-heap.json /docs/_site /PKGBUILD /WezTerm*.zip diff --git a/Cargo.lock b/Cargo.lock index b24f6ce1e..174fa6823 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1081,6 +1081,22 @@ dependencies = [ "syn", ] +[[package]] +name = "dhat" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f2aaf837aaf456f6706cb46386ba8dffd4013a757e36f4ea05c20dd46b209a3" +dependencies = [ + "backtrace", + "lazy_static", + "mintex", + "parking_lot 0.12.1", + "rustc-hash", + "serde", + "serde_json", + "thousands", +] + [[package]] name = "diff" version = "0.1.13" @@ -2639,6 +2655,16 @@ dependencies = [ "adler", ] +[[package]] +name = "mintex" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7c5ba1c3b5a23418d7bbf98c71c3d4946a0125002129231da8d6b723d559cb" +dependencies = [ + "once_cell", + "sys-info", +] + [[package]] name = "mio" version = "0.8.5" @@ -4583,6 +4609,16 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "sys-info" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "tabout" version = "0.3.0" @@ -4778,6 +4814,12 @@ dependencies = [ "syn", ] +[[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.4" @@ -5576,6 +5618,7 @@ dependencies = [ "codec", "colorgrad", "config", + "dhat", "dirs-next", "downcast-rs", "embed-resource", diff --git a/wezterm-gui/Cargo.toml b/wezterm-gui/Cargo.toml index 5d0ceda4b..0b9f6314f 100644 --- a/wezterm-gui/Cargo.toml +++ b/wezterm-gui/Cargo.toml @@ -22,6 +22,8 @@ vendored-fonts = [ "vendor-roboto-font", "vendor-noto-emoji-font" ] +dhat-heap = ["dhat"] # if you are doing heap profiling +dhat-ad-hoc = ["dhat"] # if you are doing ad hoc profiling [build-dependencies] anyhow = "1.0" @@ -39,6 +41,7 @@ codec = { path = "../codec" } colorgrad = "0.6" config = { path = "../config" } downcast-rs = "1.0" +dhat = {version="0.3", optional=true} dirs-next = "2.0" emojis = "0.5" env-bootstrap = { path = "../env-bootstrap" } diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index d00ed8e74..eebb8cf5c 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -51,6 +51,10 @@ mod uniforms; mod update; mod utilsprites; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + pub use selection::SelectionMode; pub use termwindow::{set_window_class, set_window_position, TermWindow, ICON_DATA}; @@ -755,6 +759,9 @@ fn terminate_with_error(err: anyhow::Error) -> ! { } fn main() { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::new_heap(); + config::designate_this_as_the_main_thread(); config::assign_error_callback(mux::connui::show_configuration_error_message); notify_on_panic();