目录
1 在main 函数 添加下面代码
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
)
func main() {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
// 定义处理请求的函数
handler := func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World!")
}
// 注册处理函数
http.HandleFunc("/", handler)
// 启动HTTP服务器
http.ListenAndServe(":8888", nil)
}
2 采集数据 (会存到一个目录 看提示框)
2 采集数据 (会存到一个目录 看提示框)
go tool pprof http://localhost:6060/debug/pprof/profile
3 分析采集的数据
3 分析采集的数据
go tool pprof -http localhost:3001 ./pprof.samples.cpu.002.pb.gz
4 常用命令行分析
top 10 列出前10
web 调用 graphviz 生成svg图片,然后打开
list 查看具体的函数分析
pdf 命令可以生成可视化的pdf文件
help 命令可以提供所有pprof支持的命令说明