1.安装组件
- 安装go-torch
go get github.com/uber/go-torch - 安装 FlameGraph
cd $WORK_PATH && git clone https://gitee.com/mirrors/FlameGraph.git
export PATH=$PATH:$WORK_PATH/FlameGraph
- 安装graphviz
yum install graphviz(CentOS, Redhat)
2.代码修改
package main
import (
"net/http"
"net/http/pprof"
)
func main() {
// 主函数中添加
go func() {
http.HandleFunc("/debug/pprof/block", pprof.Index)
http.HandleFunc("/debug/pprof/goroutine", pprof.Index)
http.HandleFunc("/debug/pprof/heap", pprof.Index)
http.HandleFunc("/debug/pprof/threadcreate", pprof.Index)
http.ListenAndServe("0.0.0.0:8888", nil)
}()
var finishWaiter chan int
<-finishWaiter
}
3.查看结果
运行上述程序后,使用如下命令生成CPU火焰图:
go-torch -u http://localhost:8888/debug/pprof/ -p > profile-local.svg
有疑问加站长微信联系(非本文作者)
![](https://static.golangjob.cn/static/img/footer.png?imageView2/2/w/280)
本文来自:简书
感谢作者:更多精彩内容【实践】WINDOWS下GOlang性能测试分析工具PProf&GO torch入门指导笔名辉哥Golang FlameGraph(火焰图)zr_hebogo性能优化初级赛亚人golang 使用pprof和go-torch做性能分析 -- W