Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 32e99dc

Browse files
nablaonepdelewski
andauthored
Extra pprof endpoints (#1031)
This PR adds extra `pprof` endpoints that we can handle. So we can profile: ``` # CPU usage go tool pprof -http=: http://localhost:9999/debug/pprof/profile # Heap usage go tool pprof -http=: http://localhost:9999/debug/pprof/heap # Concurrency profiling # It requires changing the constant `main.EnableConcurrencyProfiling` go tool pprof -http=: http://localhost:9999/debug/pprof/mutex go tool pprof -http=: http://localhost:9999/debug/pprof/block ``` --------- Signed-off-by: Rafał Strzaliński <[email protected]> Co-authored-by: Przemyslaw Delewski <[email protected]>
1 parent 968ed31 commit 32e99dc

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

quesma/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"quesma/table_resolver"
2929
"quesma/telemetry"
3030
"quesma/tracing"
31+
"runtime"
3132
"syscall"
3233
"time"
3334
)
@@ -41,7 +42,15 @@ const banner = `
4142
\__> \/ \/ \/ \/
4243
`
4344

45+
const EnableConcurrencyProfiling = false
46+
4447
func main() {
48+
49+
if EnableConcurrencyProfiling {
50+
runtime.SetBlockProfileRate(1)
51+
runtime.SetMutexProfileFraction(1)
52+
}
53+
4554
println(banner)
4655
fmt.Printf("Quesma build info: version=[%s], build hash=[%s], build date=[%s]\n",
4756
buildinfo.Version, buildinfo.BuildHash, buildinfo.BuildDate)

quesma/quesma/ui/console_routes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ func (qmc *QuesmaManagementConsole) initPprof(router *mux.Router) {
306306
router.HandleFunc("/debug/pprof/", pprof.Index)
307307
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
308308
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
309+
router.HandleFunc("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
310+
router.HandleFunc("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
311+
router.HandleFunc("/debug/pprof/mutex", pprof.Handler("mutex").ServeHTTP)
309312
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
310313
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
311314
}

0 commit comments

Comments
 (0)