From a4785133f0c3e3c302c149934df48ff7acfcee0d Mon Sep 17 00:00:00 2001 From: David Estes <5317198+dav1do@users.noreply.github.com> Date: Wed, 24 Apr 2024 23:51:08 -0600 Subject: [PATCH] fix: rust-jemalloc-pprof is only supported on linux (#321) * fix: rust-jemalloc-pprof is only supported on linux * fix: remove local only dockerfile change (no arm on ecr) * fix: CC is rough sometimes --- api/Cargo.toml | 2 ++ api/src/server.rs | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/api/Cargo.toml b/api/Cargo.toml index 35e6ae7fd..6b442dd11 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -24,6 +24,8 @@ swagger.workspace = true tokio.workspace = true tracing.workspace = true prometheus-client.workspace = true + +[target.'cfg(target_os = "linux")'.dependencies] jemalloc_pprof = "0.1.0" [target.'cfg(not(target_env = "msvc"))'.dependencies] diff --git a/api/src/server.rs b/api/src/server.rs index bf0d8cf26..2b912c837 100644 --- a/api/src/server.rs +++ b/api/src/server.rs @@ -447,19 +447,28 @@ where &self, _context: &C, ) -> std::result::Result { + #[cfg(not(target_env = "msvc"))] epoch::advance().unwrap(); - let mut prof_ctl = jemalloc_pprof::PROF_CTL.as_ref().unwrap().lock().await; - if !prof_ctl.activated() { - return Ok(DebugHeapGetResponse::BadRequest(BadRequestResponse { - message: "heap profiling not enabled".to_string(), - })); + // might be on BSD and others + #[cfg(target_os = "linux")] + { + let mut prof_ctl = jemalloc_pprof::PROF_CTL.as_ref().unwrap().lock().await; + if !prof_ctl.activated() { + return Ok(DebugHeapGetResponse::BadRequest(BadRequestResponse { + message: "heap profiling not enabled".to_string(), + })); + } + prof_ctl + .dump_pprof() + .map_err(|e| ErrorResponse::new(format!("failed to dump profile: {e}"))) + .map(|pprof| DebugHeapGetResponse::Success(ByteArray(pprof))) + .or_else(|err| Ok(DebugHeapGetResponse::InternalServerError(err))) } - prof_ctl - .dump_pprof() - .map_err(|e| ErrorResponse::new(format!("failed to dump profile: {e}"))) - .map(|pprof| DebugHeapGetResponse::Success(ByteArray(pprof))) - .or_else(|err| Ok(DebugHeapGetResponse::InternalServerError(err))) + #[cfg(not(target_os = "linux"))] + Ok(DebugHeapGetResponse::BadRequest( + models::BadRequestResponse::new("unsupported platform".to_string()), + )) } #[instrument(skip(self, _context), ret(level = Level::DEBUG), err(level = Level::ERROR))]