Golang pprof详解

go的pprof包

go中有pprof包来做代码的性能监控,在两个地方有包:

net/http/pprof

runtime/pprof

其实net/http/pprof中只是使用runtime/pprof包来进行封装了一下,并在http端口上暴露出来.

 

本篇只讲如何在web上查看性能。

一、代码部分

1.import 增加net/http/pprof包   

import(
    _ net/http/pprof
)

 

2. 打开http 监听端口

go func() {
        log.Println(http.ListenAndServe("localhost:10000", nil)) 
}()

 

二、网页上查看

*浏览器可以打开 http://127.0.0.1:10000/debug/pprof/ 可以查看各种profile索引

 

1.如果安装过graphviz直接提交过这步骤,否则可以到 http://www.graphviz.org/download/下载,并把bin加入到环境变量

2.查看profile :在命令行输入 

go tool pprof http://localhost:10000/debug/pprof/profile

此后的30秒进入收集profile信息的状态。

30秒后进入pprof的交互模式,然后输入

web

然后浏览器自动弹开到网页展示svg图

 

3.查看已经保存的profile文件

go tool pprof profile C:\Users\user\pprof\pprof.samples.cpu.004.pb.gz

 

然后也是进入pprof的交互模式,然后输入web

 

还可以查看heap和goroutine

go tool pprof http://localhost:10000/debug/pprof/heap
go tool pprof http://127.0.0.1:10000/debug/pprof/goroutine 

  

转载于:https://www.cnblogs.com/mrblue/p/9555118.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值