Golang pprof详解

go的pprof包

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

net/http/pprof浏览器

runtime/pprofsvg

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

 

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

1、代码部分

1.import 增长net/http/pprof包   spa

import(
    _ net/http/pprof
)

 

2. 打开http 监听端口命令行

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

 

2、网页上查看

*浏览器能够打开 http://127.0.0.1:10000/debug/pprof/ 能够查看各类profile索引debug

 

1.若是安装过graphviz直接提交过这步骤,不然能够到 http://www.graphviz.org/download/下载,并把bin加入到环境变量code

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

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 
相关文章
相关标签/搜索