go get github.com/uber/go-torch
cd $WORK_PATH && git clone https://github.com/brendangregg/FlameGraph.git
export PATH=$PATH:$WORK_PATH/FlameGraph
yum install graphviz
package main
import (
"net/http"
_ "net/http/pprof"
)
func main() {
// 服务端启动一个协程,支持pprof的handler
//导入pprof的包,自动包含一些handler
//项目加入如下代码
go func() {
http.ListenAndServe("0.0.0.0:8888", nil)
}()
//other code
}
ab -n 19999 -c 20 http://xxxxxxxxxxxx
-n 总数
-c 同时并发请求数
go tool pprof http://localhost:port/debug/pprof/profile
top
在默认情况下,top命令会输出以本地取样计数为顺序的列表。我们可以把这个列表叫做本地取样计数排名列表。
web
与gv命令类似,web命令也会用图形化的方式来显示概要文件。但不同的是,web命令是在一个Web浏览器中显示它。
//cpu火焰图
go-torch -u http://ip:port/debug/pprof/ -p > profile-cpu.svg
//内存火焰图
go-torch -u http://ip:port/debug/pprof/heap -p > profile-heap.svg
针对测试服务端,进行操作,上述步骤默认监听30s,即30s后可以生成相关图像
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/166803.html原文链接:https://javaforall.cn