go 自带go tool pprof
这个命令的作用是追踪上面代码60秒内CPU的消耗情况
cpu 采集,默认30s
go tool pprof http://localhost:6006/debug/pprof/profile?seconds=60
内存分析:
go tool pprof -alloc_space http://localhost:6006/debug/pprof/heap
go tool pprof -inuse_space http://localhost:6006/debug/pprof/heap
阻塞分析
go tool pprof http://localhost:6006/debug/pprof/block
互斥锁分析
go tool pprof http://localhost:6006/debug/pprof/mutex
go tool pprof http://localhost:6006/debug/pprof/threadcreate
go tool pprof http://localhost:6006/debug/pprof/goroutine
alloc_objects: 显示自程序启动以来分配的对象总数,包括已经被垃圾回收器回收的对象
alloc_space: 显示所有对象的累计分配空间,包括已经被垃圾回收器回收的对象。
inuse_objects :显示当前存活的对象数量。
inuse_space :显示当前存活对象所占用的内存大小
object 考虑的是对象,space 考虑的是大小。
flat, 函数自身的运行耗时
flat%, 函数自身在cpu运行耗时总比例
sum, 函数自身累计使用cpu总比例
cum, 函数自身及其调用函数的运行总耗时
cum% 函数自身及其调用函数运行耗时总比例
profile: 默认进行 30s 的 CPU Profiling,得到一个分析用的 profile 文件。
allocs:查看过去所有内存分配的样本。
heap:查看活动对象的内存分配情况。
go tool pprof xxxx
top / top 10
list funcname 显示
fucus=funcname
peek 显示调用关系