下载graphviz
windows下载msi格式,安装成功后,进入命令行查看是否安装成功
指令:dot -version
如下图,说明安装成功

添加代码
在你的程序中加入如下代码:
import "net/http"
import _ "net/http/pprof"
func main() {
// 主函数中添加
http.ListenAndServe("0.0.0.0:9999", nil)
}
运行程序
在命令行执行如下指令:
go tool pprof -http=:1234http://localhost:9999/debug/pprof/profile
等几秒钟就会出现如下界面,选择【Flame Graph】

图片.png

图片.png
如上图,宽度代表耗时
beego查看接口调用耗时
如果你是用beego框架开发,beego提供了查看接口调用的功能,跟火焰图功能类似
在配置文件中添加如下配置
EnableAdmin = true
AdminHttpAddr = 0.0.0.0
AdminHttpPort = 19099
启动程序
访问 localhost:19099,出现如下界面

图片.png
注意:下面的内容,在点击对应的操作后,需要操作接口,才能获取对应的接口使用统计信息
【Requests statistics】:查询接口调用耗时情况,如下图

图片.png
【lookup goroutine】:查找协程信息
【get cpuprof】:查看cpu耗时统计
【get memprof】:查看内存消耗统计
【gc summary】:查看垃圾回收情况,如下图

图片.png
有疑问加站长微信联系(非本文作者)
