pprof
web
package main
import (
"encoding/json"
"fmt"
"net/http"
_ "net/http/pprof"
"time"
)
func main() {
go func() {
for {
fmt.Println(1111)
}
}()
fmt.Println("start api server...")
panic(http.ListenAndServe(":8080", nil))
}
使用生成火焰图
go tool pprof -http=:8081 -seconds 10 http://localhost:6060/debug/pprof/profile
http://127.0.0.1:8081/ui/flamegraph?si=cpu 查看cpu时长
参考
https://zhuanlan.zhihu.com/p/71529062
https://eddycjy.com/posts/go/tools/2018-09-15-go-tool-pprof/