pprof in golang
CPU pprof
package main
import (
"fmt"
"net/http"
_ "net/http/pprof"
"time"
)
func main() {
go func() {
ticker := time.NewTicker(time.Second)
for {
select {
case t := <- ticker.C:
fmt.Println("Current time:", t)
default:
}
}
}()
http.ListenAndServe(":8080", nil)
}
#cmdline
go run main.go
go tool pprof http://127.0.0.1:8080/debug/pprof/profile?seconds=10
go tool pprof -http=:8080 pprof.main.samples.cpu.001.pb.gz
Resources
- pprof: https://go.dev/blog/pprof
- 使用pprof排查内存泄漏: https://www.jianshu.com/p/77cc1e350093
- 如何分析golang程序的内存使用情况: https://www.jianshu.com/p/43b0e12043b9