下载测试代码
go get-d
go get -d github.com/wolfogre/go-pprof-practice
cd $GOPATH/src/github.com/wolfogre/go-pprof-practice
如果 go get 下载不了, 可以 git clone 下载
gir clone https://github.com/wolfogre/go-pprof-practice
对代码进行编译
然后运行
go mod init
go mod tidy
最后再运行
go build
./go-pprof-practice
运行 pprof 命令
go tool pprof http://localhost:6060/debug/pprof/heap
toplist
list
github.com/wolfogre/go-pprof-practice/animal/muridae/mouse.(*Mouse).Steal
func (m *Mouse) Steal() {
log.Println(m.Name(), "steal")
max := constant.Gi
for len(m.buffer) * constant.Mi < max {
m.buffer = append(m.buffer, [constant.Mi]byte{})
}
}
web