mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-29 19:30:37 +00:00
feat: add HTTP endpoint to control prof.gdump feature (#6999)
* feat/gdump: ### Add Support for Jemalloc Gdump Flag - **`jemalloc.rs`**: Introduced `PROF_GDUMP` constant and added functions `set_gdump_active` and `is_gdump_active` to manage the gdump flag. - **`error.rs`**: Added error handling for reading and updating the jemalloc gdump flag with `ReadGdump` and `UpdateGdump` errors. - **`lib.rs`**: Exposed `is_gdump_active` and `set_gdump_active` functions for non-Windows platforms. - **`http.rs`**: Added HTTP routes for checking and toggling the jemalloc gdump flag status. - **`mem_prof.rs`**: Implemented handlers `gdump_toggle_handler` and `gdump_status_handler` for managing gdump flag via HTTP requests. Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * Update docs/how-to/how-to-profile-memory.md Co-authored-by: shuiyisong <113876041+shuiyisong@users.noreply.github.com> * fix: typo in docs Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> --------- Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> Co-authored-by: shuiyisong <113876041+shuiyisong@users.noreply.github.com>
This commit is contained in:
@@ -924,6 +924,11 @@ impl HttpServer {
|
||||
.route(
|
||||
"/mem/status",
|
||||
routing::get(mem_prof::heap_prof_status_handler),
|
||||
) // jemalloc gdump flag status and toggle
|
||||
.route(
|
||||
"/mem/gdump",
|
||||
routing::get(mem_prof::gdump_status_handler)
|
||||
.post(mem_prof::gdump_toggle_handler),
|
||||
),
|
||||
),
|
||||
))
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#[cfg(feature = "mem-prof")]
|
||||
use axum::Form;
|
||||
#[cfg(feature = "mem-prof")]
|
||||
use axum::extract::Query;
|
||||
use axum::http::StatusCode;
|
||||
@@ -127,3 +129,57 @@ pub async fn heap_prof_status_handler() -> crate::error::Result<impl IntoRespons
|
||||
"The 'mem-prof' feature is disabled",
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "mem-prof")]
|
||||
#[derive(Deserialize)]
|
||||
pub struct GdumpToggleForm {
|
||||
activate: bool,
|
||||
}
|
||||
|
||||
#[cfg(feature = "mem-prof")]
|
||||
#[axum_macros::debug_handler]
|
||||
pub async fn gdump_toggle_handler(
|
||||
Form(form): Form<GdumpToggleForm>,
|
||||
) -> crate::error::Result<impl IntoResponse> {
|
||||
use snafu::ResultExt;
|
||||
|
||||
use crate::error::DumpProfileDataSnafu;
|
||||
|
||||
common_mem_prof::set_gdump_active(form.activate).context(DumpProfileDataSnafu)?;
|
||||
|
||||
let msg = if form.activate {
|
||||
"gdump activated"
|
||||
} else {
|
||||
"gdump deactivated"
|
||||
};
|
||||
Ok((StatusCode::OK, msg))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mem-prof"))]
|
||||
#[axum_macros::debug_handler]
|
||||
pub async fn gdump_toggle_handler() -> crate::error::Result<impl IntoResponse> {
|
||||
Ok((
|
||||
StatusCode::NOT_IMPLEMENTED,
|
||||
"The 'mem-prof' feature is disabled",
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "mem-prof")]
|
||||
#[axum_macros::debug_handler]
|
||||
pub async fn gdump_status_handler() -> crate::error::Result<impl IntoResponse> {
|
||||
use snafu::ResultExt;
|
||||
|
||||
use crate::error::DumpProfileDataSnafu;
|
||||
|
||||
let is_active = common_mem_prof::is_gdump_active().context(DumpProfileDataSnafu)?;
|
||||
Ok((StatusCode::OK, format!("{{\"active\": {}}}", is_active)))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "mem-prof"))]
|
||||
#[axum_macros::debug_handler]
|
||||
pub async fn gdump_status_handler() -> crate::error::Result<impl IntoResponse> {
|
||||
Ok((
|
||||
StatusCode::NOT_IMPLEMENTED,
|
||||
"The 'mem-prof' feature is disabled",
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user