-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pprof heap endpoints to node api
- Loading branch information
1 parent
f88d42b
commit 9d701b6
Showing
7 changed files
with
171 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
mod handler; | ||
mod metrics; | ||
mod multiplex; | ||
mod pprof; | ||
mod prometheus_helpers; | ||
mod service; | ||
mod state; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#[cfg(target_os = "linux")] | ||
mod pprof { | ||
use http::StatusCode; | ||
|
||
pub async fn heap() -> Result<impl axum::response::IntoResponse, (StatusCode, String)> { | ||
match jemalloc_pprof::PROF_CTL.as_ref() { | ||
Some(prof_ctl) => { | ||
let mut prof_ctl = prof_ctl.lock().await; | ||
if prof_ctl.activated() { | ||
let pprof = prof_ctl | ||
.dump_pprof() | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?; | ||
Ok(pprof) | ||
} else { | ||
Err(( | ||
axum::http::StatusCode::PRECONDITION_FAILED, | ||
"Heap profiling not activated: first call /debug/pprof/heap/activate\n" | ||
.into(), | ||
)) | ||
} | ||
} | ||
None => Err(( | ||
axum::http::StatusCode::PRECONDITION_FAILED, | ||
"Heap profiling not enabled: run with MALLOC_CONF=\"prof:true\"\n".into(), | ||
)), | ||
} | ||
} | ||
|
||
pub async fn activate_heap() -> Result<(), (StatusCode, String)> { | ||
match jemalloc_pprof::PROF_CTL.as_ref() { | ||
Some(prof_ctl) => { | ||
let mut prof_ctl = prof_ctl.lock().await; | ||
prof_ctl | ||
.activate() | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?; | ||
Ok(()) | ||
} | ||
None => Err(( | ||
axum::http::StatusCode::PRECONDITION_FAILED, | ||
"Heap profiling not enabled: run with MALLOC_CONF=\"prof:true\"\n".into(), | ||
)), | ||
} | ||
} | ||
|
||
pub async fn deactivate_heap() -> Result<(), (StatusCode, String)> { | ||
match jemalloc_pprof::PROF_CTL.as_ref() { | ||
Some(prof_ctl) => { | ||
let mut prof_ctl = prof_ctl.lock().await; | ||
prof_ctl | ||
.deactivate() | ||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?; | ||
Ok(()) | ||
} | ||
None => Err(( | ||
axum::http::StatusCode::PRECONDITION_FAILED, | ||
"Heap profiling not enabled: run with MALLOC_CONF=\"prof:true\"\n".into(), | ||
)), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(not(target_os = "linux"))] | ||
mod pprof { | ||
use http::StatusCode; | ||
|
||
pub async fn heap() -> (StatusCode, String) { | ||
( | ||
axum::http::StatusCode::PRECONDITION_FAILED, | ||
"Heap profiling is only available on Linux\n".into(), | ||
) | ||
} | ||
|
||
pub async fn activate_heap() -> (StatusCode, String) { | ||
heap().await | ||
} | ||
|
||
pub async fn deactivate_heap() -> (StatusCode, String) { | ||
heap().await | ||
} | ||
} | ||
|
||
pub use pprof::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters