使用google的pprof工具以及在gin中集成pprof

首先我们得先安装这两个工具:

google的pprof工具链

go get -u github.com/google/pprof

 

gin的pprof工具

go get github.com/DeanThompson/ginpprof

 

在ginpprof可以很容易就实现集成pprof服务。

ginpprof.Wrap(router)

 

启动web服务之后,在浏览器中打开http://localhost:port/debug/pprof/即可看见: 

然后我们打开http://localhost:port/debug/pprof/profile,这个地址会收集30秒内服务的运行情况,这个结果会返回一个profile文件给我们

然后我们就可以使用google的pprof工具链去查看服务的运行情况:

ginpprof.Wrap(router)

注意:

  • 在执行这个命令的时候有时候会报错,
    Could not execute dot; may need to install graphviz.

    说缺少graphviz,那我们就要去下载并安装,graphviz下载地址

  • 安装之后还得把安装目录下的bin添加到path中

成功之后我们可以在浏览器看到: 

 

这样我们就可以很简单的查看到我们服务的运行情况了

posted @ 2018-11-29 14:43  timliudream  阅读(7044)  评论(0编辑  收藏  举报