Skip to content

Commit

Permalink
fix: rust-jemalloc-pprof is only supported on linux (#321)
Browse files Browse the repository at this point in the history
* fix: rust-jemalloc-pprof is only supported on linux

* fix: remove local only dockerfile change (no arm on ecr)

* fix: CC is rough sometimes
  • Loading branch information
dav1do authored Apr 25, 2024
1 parent cc6c0ec commit a478513
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
29 changes: 19 additions & 10 deletions api/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,19 +447,28 @@ where
&self,
_context: &C,
) -> std::result::Result<DebugHeapGetResponse, ApiError> {
#[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))]
Expand Down

0 comments on commit a478513

Please sign in to comment.