安装:
1、 安装go-torch
go get github.com/uber/go-torch
2、安装FlameGraph
cd $GOPATH && git clone https://github.com/brendangregg/FlameGraph.git
export PATH=$PATH:$GOPATH/FlameGraph 【这步一定要设置,生成火焰图时会用到】
3、安装graphviz (CentOS, Redhat)
yum install graphviz
在程序的包含mian函数的文件中添加相应代码
使用:
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.ListenAndServe("0.0.0.0:8888", nil) //注意此处,遇到错误
}()