GolangUsing the Go profiler (pprof)
2022 · 03 · 28
1 min read
Paper
Contents
Profile via net/http/pprof
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| import (
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
log.Println(http.ListenAndServe("0.0.0.0:6060", nil))
}()
... do something ...
}
|
CPU profile (collects data for 30 seconds)
1
| go tool pprof http://xxxx:6060/debug/pprof/profile
|
Heap memory (returns current memory info)
1
| go tool pprof http://xxxx:6060/debug/pprof/heap
|