From 08e835d487b983c44ce2570d8c396d570d426916 Mon Sep 17 00:00:00 2001 From: dullbananas Date: Tue, 13 Jun 2023 13:42:07 +0000 Subject: [PATCH] Add dhat-heap feature --- .gitignore | 3 +++ Cargo.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 7 +++++++ 4 files changed, 55 insertions(+) diff --git a/.gitignore b/.gitignore index 0461784f0..058baf5fa 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ pictrs/ # The generated typescript bindings bindings + +# Generated with dhat-heap feature enabled +dhat-*.json diff --git a/Cargo.lock b/Cargo.lock index 1c687495e..2bbc25175 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1337,6 +1337,22 @@ dependencies = [ "serde", ] +[[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 = "diesel" version = "2.1.0" @@ -2745,6 +2761,7 @@ dependencies = [ "actix-web", "clokwerk", "console-subscriber", + "dhat", "diesel", "diesel-async", "doku", @@ -3156,6 +3173,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.4" @@ -5059,6 +5086,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20518fe4a4c9acf048008599e464deb21beeae3d3578418951a189c235a7a9a8" +[[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 = "tap" version = "1.0.1" @@ -5137,6 +5174,12 @@ dependencies = [ "syn 1.0.103", ] +[[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" diff --git a/Cargo.toml b/Cargo.toml index f275ddbf8..ebb1f62b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ debug = 0 embed-pictrs = ["pict-rs"] console = ["console-subscriber", "opentelemetry", "opentelemetry-otlp", "tracing-opentelemetry", "reqwest-tracing/opentelemetry_0_16"] default = [] +dhat-heap = ["dep:dhat"] [workspace] members = [ @@ -140,3 +141,4 @@ opentelemetry-otlp = { version = "0.10.0", optional = true } pict-rs = { version = "0.4.0-beta.9", optional = true } tokio.workspace = true actix-cors = "0.6.4" +dhat = { version = "0.3.2", optional = true } diff --git a/src/main.rs b/src/main.rs index 79a813c52..15404efcf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,15 @@ use lemmy_server::{init_logging, start_lemmy_server}; use lemmy_utils::{error::LemmyError, settings::SETTINGS}; +#[cfg(feature = "dhat-heap")] +#[global_allocator] +static ALLOC: dhat::Alloc = dhat::Alloc; + #[actix_web::main] pub async fn main() -> Result<(), LemmyError> { + #[cfg(feature = "dhat-heap")] + let _profiler = dhat::Profiler::builder().trim_backtraces(None).build(); + init_logging(&SETTINGS.opentelemetry_url)?; #[cfg(not(feature = "embed-pictrs"))] start_lemmy_server().await?;