Skip to content

Conversation

v0y4g3r
Copy link
Contributor

@v0y4g3r v0y4g3r commented Sep 22, 2025

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

prof.gdump is a convenient features provided by jemalloc that dumps the memory profiling data every time the memory usage exceeds previous maximum value. This PR adds an HTTP endpoint to control the status of prof.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.

PR Checklist

Please convert it to a draft if some of the following conditions are not met.

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.
  • API changes are backward compatible.
  • Schema or data changes are backward compatible.

 ### 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 <[email protected]>
@v0y4g3r v0y4g3r requested a review from a team as a code owner September 22, 2025 07:27
@github-actions github-actions bot added size/S documentation docs-not-required This change does not impact docs. labels Sep 22, 2025
Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others LGTM

use crate::error::DumpProfileDataSnafu;

let is_active = common_mem_prof::is_gdump_active().context(DumpProfileDataSnafu)?;
Ok((StatusCode::OK, format!("{{\"active\": {}}}", is_active)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use serde_json::json! ?

curl -X POST localhost:4000/debug/prof/mem/deactivate

# Activate gdump feature that dumps memory profiling data every time virtual memory usage exceeds previous maximum value.
`curl -X POST localhost:4000/debug/prof/mem/gdump -d 'activate=true'`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`curl -X POST localhost:4000/debug/prof/mem/gdump -d 'activate=true'`
curl -X POST localhost:4000/debug/prof/mem/gdump -d 'activate=true'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. documentation size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants