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

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/即可看见: 使用google的pprof工具以及在gin中集成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中

成功之后我们可以在浏览器看到: 使用google的pprof工具以及在gin中集成pprof

 

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

相关文章:

  • 2022-12-23
  • 2023-03-13
  • 2021-10-28
  • 2021-12-27
  • 2021-09-18
猜你喜欢
  • 2022-03-05
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
相关资源
相似解决方案