diff --git a/Cargo.lock b/Cargo.lock index 130eaaeb61..68f3939c7e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1336,9 +1336,13 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +source = "git+https://github.com/discord9/bytes?rev=1572ab22c3cbad0e9b6681d1f68eca4139322a2a#1572ab22c3cbad0e9b6681d1f68eca4139322a2a" dependencies = [ + "backtrace", + "crossbeam-channel", + "inferno 0.12.2", + "papaya", + "quanta", "serde", ] @@ -8862,6 +8866,16 @@ dependencies = [ "unicode-width 0.1.14", ] +[[package]] +name = "papaya" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92dd0b07c53a0a0c764db2ace8c541dc47320dad97c2200c2a637ab9dd2328f" +dependencies = [ + "equivalent", + "seize", +] + [[package]] name = "parking" version = "2.2.1" @@ -10095,6 +10109,21 @@ dependencies = [ "variadics", ] +[[package]] +name = "quanta" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3ab5a9d756f0d97bdc89019bd2e4ea098cf9cde50ee7564dde6b81ccc8f06c7" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi 0.11.1+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "query" version = "0.18.0" @@ -10394,6 +10423,15 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "raw-cpuid" +version = "11.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186" +dependencies = [ + "bitflags 2.9.1", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -11334,6 +11372,16 @@ dependencies = [ "libc", ] +[[package]] +name = "seize" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b55fb86dfd3a2f5f76ea78310a88f96c4ea21a3031f8d212443d56123fd0521" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "semver" version = "1.0.26" diff --git a/Cargo.toml b/Cargo.toml index 3ce3ff48dc..5ff2ceaf3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -333,6 +333,7 @@ datafusion-datasource = { git = "https://github.com/GreptimeTeam/datafusion.git" datafusion-sql = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" } datafusion-substrait = { git = "https://github.com/GreptimeTeam/datafusion.git", rev = "fd4b2abcf3c3e43e94951bda452c9fd35243aab0" } sqlparser = { git = "https://github.com/GreptimeTeam/sqlparser-rs.git", rev = "4b519a5caa95472cc3988f5556813a583dd35af1" } # branch = "v0.58.x" +bytes = { git = "https://github.com/discord9/bytes", rev = "1572ab22c3cbad0e9b6681d1f68eca4139322a2a" } [profile.release] debug = 1 diff --git a/docs/how-to/how-to-profile-memory.md b/docs/how-to/how-to-profile-memory.md index b4bc00093a..b28085bde7 100644 --- a/docs/how-to/how-to-profile-memory.md +++ b/docs/how-to/how-to-profile-memory.md @@ -92,6 +92,9 @@ curl -X POST localhost:4000/debug/prof/mem > greptime.hprof curl -X POST "localhost:4000/debug/prof/mem?output=flamegraph" > greptime.svg # or output pprof format curl -X POST "localhost:4000/debug/prof/mem?output=proto" > greptime.pprof + + +curl -X POST "localhost:4000/debug/prof/bytes" > greptime.svg ``` You can periodically dump profiling data and compare them to find the delta memory usage. diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs index 8fa658b6bb..70ba323cfe 100644 --- a/src/servers/src/http.rs +++ b/src/servers/src/http.rs @@ -913,6 +913,7 @@ impl HttpServer { Router::new() .route("/cpu", routing::post(pprof::pprof_handler)) .route("/mem", routing::post(mem_prof::mem_prof_handler)) + .route("/bytes", routing::post(mem_prof::bytes_prof_handler)) .route( "/mem/activate", routing::post(mem_prof::activate_heap_prof_handler), diff --git a/src/servers/src/http/mem_prof.rs b/src/servers/src/http/mem_prof.rs index e6362aef3f..a3d3e76915 100644 --- a/src/servers/src/http/mem_prof.rs +++ b/src/servers/src/http/mem_prof.rs @@ -39,6 +39,14 @@ pub struct MemPprofQuery { output: Output, } +pub async fn bytes_prof_handler() -> crate::error::Result { + let dump = bytes::GLOBAL_TRACER + .get_or_init(|| bytes::BytesTracer::new().0) + .collector + .render_flamegraph()?; + Ok((StatusCode::OK, dump)) +} + #[cfg(feature = "mem-prof")] #[axum_macros::debug_handler] pub async fn mem_prof_handler(