Skip to content

Commit

Permalink
Extra pprof endpoints (#1031)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nablaone and pdelewski authored Nov 22, 2024
1 parent 968ed31 commit 32e99dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions quesma/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"quesma/table_resolver"
"quesma/telemetry"
"quesma/tracing"
"runtime"
"syscall"
"time"
)
Expand All @@ -41,7 +42,15 @@ const banner = `
\__> \/ \/ \/ \/
`

const EnableConcurrencyProfiling = false

func main() {

if EnableConcurrencyProfiling {
runtime.SetBlockProfileRate(1)
runtime.SetMutexProfileFraction(1)
}

println(banner)
fmt.Printf("Quesma build info: version=[%s], build hash=[%s], build date=[%s]\n",
buildinfo.Version, buildinfo.BuildHash, buildinfo.BuildDate)
Expand Down
3 changes: 3 additions & 0 deletions quesma/quesma/ui/console_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ func (qmc *QuesmaManagementConsole) initPprof(router *mux.Router) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
router.HandleFunc("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
router.HandleFunc("/debug/pprof/mutex", pprof.Handler("mutex").ServeHTTP)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
Expand Down

0 comments on commit 32e99dc

Please sign in to comment.