简介
pprof为golang自带的性能检测工具
demo
参考:https://blog.wolfogre.com/posts/go-ppof-practice/
Q&A
1. 如果你的程序,本身不是一个http服务,那么需要做如下操作:
import _ "net/http/pprof"
func main() {
//yourself code
//add the next code
go func() {
// 启动一个 http server,注意 pprof 相关的 handler 已经自动注册过了
if err := http.ListenAndServe(":6060", nil); err != nil {
log.Fatal(err)
}
os.Exit(0)
}
}
2. 如果你的程序,本身就是一个http服务,那么就不用做上述操作,仅执行下述动作:
import _ "net/http/pprof"
参考:https://stackoverflow.com/questions/13699297/how-to-use-pprof-in-go-program