pprof
开启pprof
import (
"net/http"
_ "net/http/pprof"
)
func main(){
http.ListenAndServe(":6060", nil)
}
see 127.0.0.1:6060/debug/pprof
- allocs 过去所有内存分配的样本
- block 导致同步原语阻塞的堆栈痕迹
- cmdline 当前程序的命令行调用
- goroutine 当前所有goroutine的堆栈痕迹
- heap 实时对象的内存分配样本。你可以指定gc GET参数,在进行堆采样之前运行GC。
- mutex 争夺突扰的持有者的堆栈痕迹
概况。CPU配置文件。你可以在seconds GET参数中指定持续时间。在你得到profile文件后,使用go tool pprof命令来调查该profile。 - threadcreate 导致创建新的操作系统线程的堆栈痕迹
- trace: 对当前程序的执行情况进行跟踪。你可以在秒的GET参数中指定持续时间。在你得到跟踪文件后,使用go tool trace命令来调查跟踪。
可视化
go tool pprof -http=:8000 http://10.1.40.70:31644/debug/pprof/{cmd}
堆
go tool pprof -http=:8000 http://10.1.40.70:31644/debug/pprof/heap