|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +#[cfg(feature = "mem-prof")] |
| 16 | +use axum::Form; |
15 | 17 | #[cfg(feature = "mem-prof")] |
16 | 18 | use axum::extract::Query; |
17 | 19 | use axum::http::StatusCode; |
@@ -127,3 +129,57 @@ pub async fn heap_prof_status_handler() -> crate::error::Result<impl IntoRespons |
127 | 129 | "The 'mem-prof' feature is disabled", |
128 | 130 | )) |
129 | 131 | } |
| 132 | + |
| 133 | +#[cfg(feature = "mem-prof")] |
| 134 | +#[derive(Deserialize)] |
| 135 | +pub struct GdumpToggleForm { |
| 136 | + activate: bool, |
| 137 | +} |
| 138 | + |
| 139 | +#[cfg(feature = "mem-prof")] |
| 140 | +#[axum_macros::debug_handler] |
| 141 | +pub async fn gdump_toggle_handler( |
| 142 | + Form(form): Form<GdumpToggleForm>, |
| 143 | +) -> crate::error::Result<impl IntoResponse> { |
| 144 | + use snafu::ResultExt; |
| 145 | + |
| 146 | + use crate::error::DumpProfileDataSnafu; |
| 147 | + |
| 148 | + common_mem_prof::set_gdump_active(form.activate).context(DumpProfileDataSnafu)?; |
| 149 | + |
| 150 | + let msg = if form.activate { |
| 151 | + "gdump activated" |
| 152 | + } else { |
| 153 | + "gdump deactivated" |
| 154 | + }; |
| 155 | + Ok((StatusCode::OK, msg)) |
| 156 | +} |
| 157 | + |
| 158 | +#[cfg(not(feature = "mem-prof"))] |
| 159 | +#[axum_macros::debug_handler] |
| 160 | +pub async fn gdump_toggle_handler() -> crate::error::Result<impl IntoResponse> { |
| 161 | + Ok(( |
| 162 | + StatusCode::NOT_IMPLEMENTED, |
| 163 | + "The 'mem-prof' feature is disabled", |
| 164 | + )) |
| 165 | +} |
| 166 | + |
| 167 | +#[cfg(feature = "mem-prof")] |
| 168 | +#[axum_macros::debug_handler] |
| 169 | +pub async fn gdump_status_handler() -> crate::error::Result<impl IntoResponse> { |
| 170 | + use snafu::ResultExt; |
| 171 | + |
| 172 | + use crate::error::DumpProfileDataSnafu; |
| 173 | + |
| 174 | + let is_active = common_mem_prof::is_gdump_active().context(DumpProfileDataSnafu)?; |
| 175 | + Ok((StatusCode::OK, format!("{{\"active\": {}}}", is_active))) |
| 176 | +} |
| 177 | + |
| 178 | +#[cfg(not(feature = "mem-prof"))] |
| 179 | +#[axum_macros::debug_handler] |
| 180 | +pub async fn gdump_status_handler() -> crate::error::Result<impl IntoResponse> { |
| 181 | + Ok(( |
| 182 | + StatusCode::NOT_IMPLEMENTED, |
| 183 | + "The 'mem-prof' feature is disabled", |
| 184 | + )) |
| 185 | +} |
0 commit comments