golang测试中的cpuprofile和memprofile

Jsm*_*ith 4 testing go memprof

我在GO测试文件上尝试了命令go test -cpuprofile cpu.out,它产生了一个文件cpu.out,其中包含许多64位数字.这对我没有任何意义.该命令做了什么以及从cpu.out文件中提取了哪些信息?

同样go test -memprofile mem.out生成了一个mem.out文件,这对我来说似乎没什么意义.帮帮我.

我已经附上了这两个文件.

cpu.outmem.out

Mar*_*her 9

使用输出配置文件与go tool例如:

go tool pprof testbin.test cpu.out
Run Code Online (Sandbox Code Playgroud)

我建议func Benchmark*(b *testing.B)您在分析中感兴趣的功能实现一些.

进入工具后尝试top10:

Welcome to pprof!  For help, type 'help'.
(pprof) top10
Run Code Online (Sandbox Code Playgroud)

更多信息:https://blog.golang.org/profiling-go-programs