Skip to content

Commit

Permalink
docs: refactor and enhance profiling and debug routes
Browse files Browse the repository at this point in the history
- Rename admin route group to debug route group
- Update pprof profile URL to include query parameter for duration
- Add instructions for downloading pprof profile data using curl and viewing it with go tool pprof

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Nov 15, 2024
1 parent 6b5f17c commit cb3eda1
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ import (

func main() {
router := gin.Default()
adminGroup := router.Group("/admin", func(c *gin.Context) {
debugGroup := router.Group("/debug", func(c *gin.Context) {
if c.Request.Header.Get("Authorization") != "foobar" {
c.AbortWithStatus(http.StatusForbidden)
return
}
c.Next()
})
pprof.RouteRegister(adminGroup, "pprof")
pprof.RouteRegister(debugGroup, "pprof")
router.Run(":8080")
}

Expand All @@ -91,7 +91,7 @@ go tool pprof http://localhost:8080/debug/pprof/heap
Or to look at a 30-second CPU profile:

```bash
go tool pprof http://localhost:8080/debug/pprof/profile
go tool pprof http://localhost:8080/debug/pprof/profile?seconds=30
```

Or to look at the goroutine blocking profile, after calling runtime.SetBlockProfileRate in your program:
Expand All @@ -105,3 +105,11 @@ Or to collect a 5-second execution trace:
```bash
wget http://localhost:8080/debug/pprof/trace?seconds=5
```

Download the pprof profile data:

```bash
curl -v -H "Authorization: foobar" -o profile.pb.gz \
http://localhost:8080/debug/pprof/profile?seconds=60
go tool pprof -http=:8099 profile.pb.gz
```

0 comments on commit cb3eda1

Please sign in to comment.