1#[cfg(feature = "mem-prof")]
16use axum::extract::Query;
17use axum::http::StatusCode;
18use axum::response::IntoResponse;
19use serde::{Deserialize, Serialize};
20
21#[derive(Debug, Default, Serialize, Deserialize)]
23#[serde(rename_all = "snake_case")]
24pub enum Output {
25 Proto,
27 #[default]
29 Text,
30 Flamegraph,
32}
33
34#[derive(Default, Serialize, Deserialize, Debug)]
35#[serde(default)]
36pub struct MemPprofQuery {
37 output: Output,
38}
39
40#[cfg(feature = "mem-prof")]
41#[axum_macros::debug_handler]
42pub async fn mem_prof_handler(
43 Query(req): Query<MemPprofQuery>,
44) -> crate::error::Result<impl IntoResponse> {
45 use snafu::ResultExt;
46
47 use crate::error::DumpProfileDataSnafu;
48
49 let dump = match req.output {
50 Output::Proto => common_mem_prof::dump_pprof().await,
51 Output::Text => common_mem_prof::dump_profile().await,
52 Output::Flamegraph => common_mem_prof::dump_flamegraph().await,
53 }
54 .context(DumpProfileDataSnafu)?;
55
56 Ok((StatusCode::OK, dump))
57}
58
59#[cfg(not(feature = "mem-prof"))]
60#[axum_macros::debug_handler]
61pub async fn mem_prof_handler() -> crate::error::Result<impl IntoResponse> {
62 Ok((
63 StatusCode::NOT_IMPLEMENTED,
64 "The 'mem-prof' feature is disabled",
65 ))
66}