golang pprof工具使用

服务代码

pprof性能测试代码中已在ListenAndServe()前添加

mux := http.NewServeMux()
mux.Handle("/", &MyHttpsHandler{})

/** 性能分析接口 */
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
// mux.Handle("/debug", http.DefaultServeMux)

go-torch工具

go get github.com/uber/go-torch

# 火焰图库
cd $GOPATH/src/github.com/uber/go-torch
git clone https://github.com/brendangregg/FlameGraph.git
export PATH=$GOPATH/src/github.com/uber/go-torch/FlameGraph:$PATH

linux x window

yum groupinstall "X Window System"
yum install firefox

export REMOTE_IP=`who am i | awk '{print $5}' | sed 's/(//g' | sed 's/)//g'`
export DISPLAY=$REMOTE_IP:0.0

pc xming

https://sourceforge.net/projects/xming/
并在安装位置下的X0.hosts中添加PC IP地址

go tool pprof -seconds 30 http://localhost:8080/debug/pprof/profile
在这里插入图片描述
在这里插入图片描述

go-torch  /root/pprof/pprof.client_bc.samples.cpu.012.pb.g
# 或者
go-torch && firefox torch.svg

在这里插入图片描述

strace跟踪系统调用

strace -cf -p $(pidof client_bc)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/zhout2009/article/details/84573279