diff --git a/src/servers/src/http/pprof/README.md b/docs/how-to/how-to-profile-cpu.md similarity index 71% rename from src/servers/src/http/pprof/README.md rename to docs/how-to/how-to-profile-cpu.md index b8393ae3f5..b73c85ea2f 100644 --- a/src/servers/src/http/pprof/README.md +++ b/docs/how-to/how-to-profile-cpu.md @@ -9,7 +9,7 @@ cargo build --features=pprof ## HTTP API Sample at 99 Hertz, for 5 seconds, output report in [protobuf format](https://github.com/google/pprof/blob/master/proto/profile.proto). ```bash -curl -s '0:4000/v1/prof/cpu' > /tmp/pprof.out +curl -s '0:4000/debug/prof/cpu' > /tmp/pprof.out ``` Then you can use `pprof` command with the protobuf file. @@ -19,10 +19,10 @@ go tool pprof -top /tmp/pprof.out Sample at 99 Hertz, for 60 seconds, output report in flamegraph format. ```bash -curl -s '0:4000/v1/prof/cpu?seconds=60&output=flamegraph' > /tmp/pprof.svg +curl -s '0:4000/debug/prof/cpu?seconds=60&output=flamegraph' > /tmp/pprof.svg ``` Sample at 49 Hertz, for 10 seconds, output report in text format. ```bash -curl -s '0:4000/v1/prof/cpu?seconds=10&frequency=49&output=text' > /tmp/pprof.txt +curl -s '0:4000/debug/prof/cpu?seconds=10&frequency=49&output=text' > /tmp/pprof.txt ``` diff --git a/src/common/mem-prof/README.md b/docs/how-to/how-to-profile-memory.md similarity index 67% rename from src/common/mem-prof/README.md rename to docs/how-to/how-to-profile-memory.md index da1bbae9f0..7211683190 100644 --- a/src/common/mem-prof/README.md +++ b/docs/how-to/how-to-profile-memory.md @@ -12,10 +12,10 @@ brew install jemalloc sudo apt install libjemalloc-dev ``` -### [flamegraph](https://github.com/brendangregg/FlameGraph) +### [flamegraph](https://github.com/brendangregg/FlameGraph) ```bash -curl https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl > ./flamegraph.pl +curl https://raw.githubusercontent.com/brendangregg/FlameGraph/master/flamegraph.pl > ./flamegraph.pl ``` ### Build GreptimeDB with `mem-prof` feature. @@ -35,7 +35,7 @@ MALLOC_CONF=prof:true,lg_prof_interval:28 ./target/debug/greptime standalone sta Dump memory profiling data through HTTP API: ```bash -curl localhost:4000/v1/prof/mem > greptime.hprof +curl localhost:4000/debug/prof/mem > greptime.hprof ``` You can periodically dump profiling data and compare them to find the delta memory usage. @@ -45,6 +45,9 @@ You can periodically dump profiling data and compare them to find the delta memo To create flamegraph according to dumped profiling data: ```bash -jeprof --svg --base= > output.svg -``` +sudo apt install -y libjemalloc-dev +jeprof --collapse | ./flamegraph.pl > mem-prof.svg + +jeprof --base --collapse | ./flamegraph.pl > output.svg +``` diff --git a/src/servers/src/http.rs b/src/servers/src/http.rs index 953ff9e73a..67309b7244 100644 --- a/src/servers/src/http.rs +++ b/src/servers/src/http.rs @@ -730,6 +730,7 @@ impl HttpServer { authorize::check_http_auth, )), ) + // Handlers for debug, we don't expect a timeout. .nest( "/debug", Router::new() @@ -737,19 +738,19 @@ impl HttpServer { .route( "/log_level", routing::get(dyn_log::dyn_log_handler).post(dyn_log::dyn_log_handler), - ), - ) - // Handlers for debug, we don't expect a timeout. - .nest( - &format!("/{HTTP_API_VERSION}/prof"), - Router::new() - .route( - "/cpu", - routing::get(pprof::pprof_handler).post(pprof::pprof_handler), ) - .route( - "/mem", - routing::get(mem_prof::mem_prof_handler).post(mem_prof::mem_prof_handler), + .nest( + "/prof", + Router::new() + .route( + "/cpu", + routing::get(pprof::pprof_handler).post(pprof::pprof_handler), + ) + .route( + "/mem", + routing::get(mem_prof::mem_prof_handler) + .post(mem_prof::mem_prof_handler), + ), ), ) }