一、前言

业务方反馈引入jaeger后,cpu load飙升,无奈只能分析一波。

二、PPROF环境

go tool pprof -h
#Mac 
brew install graphviz
#centos
yum install graphviz

另外之前gotorch(https://github.com/uber-archive/go-torch
)非常好用,由于go1.11自带svg后,这个项目废弃了。

三、数据来源

1)runtime/pprof
2)net/http/pprof
net http封装了 runtime/pprof,通过http方式暴露数据。
3)github.com/pkg/profile,也是对runtime/pprof的封装。

pprof使用

如果直接使用runtime,则直接返回采样文件;如果使用http接口,可以访问url:
http://localhost:8080/debug/pprof/profile
http://localhost:8080/debug/pprof/heap

常用命令

#文本方式显示文件
go tool pprof --text http://localhost:8080/debug/pprof/heap
#交互模式
# Get a 30 second CPU profile
go tool pprof <local_binary_path> 'http://localhost:<local_port>/debug/pprof/profile'
# Get a 60 second CPU profile
go tool pprof <local_binary_path> 'http://localhost:<local_port>/debug/pprof/profile?seconds=60'
# Get a heap profile
go tool pprof <local_binary_path> 'http://localhost:<local_port>/debug/pprof/heap'