cpuprofile and memprofile in golang testing

huangapple go评论79阅读模式
英文:

cpuprofile and memprofile in golang testing

问题

我在一个GO测试文件上尝试了命令go test -cpuprofile cpu.out,结果生成了一个名为cpu.out的文件,里面充满了许多64位的数字。对我来说这毫无意义。这个命令做了什么,我可以从cpu.out文件中提取什么信息?

类似地,go test -memprofile mem.out生成了一个名为mem.out的文件,对我来说也没有意义。请帮我解决这个问题。

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

cpu.outmem.out

英文:

I tried the command go test -cpuprofile cpu.out on a GO test file and it resulted in a file cpu.out which is full of many 64 bit numbers. It doesn't make any sense to me. What did the command do and what information can get I extract from cpu.out file?

Similarly go test -memprofile mem.out generated a mem.out file which also seems to make no sense to me. Help me out.

I have attached both the files.

cpu.out and mem.out

答案1

得分: 16

使用go tool与输出配置文件一起协同工作,例如:

go tool pprof testbin.test cpu.out

我建议为您感兴趣的功能编写一些func Benchmark*(b *testing.B)实现,以进行性能分析。

进入工具后,尝试使用top10命令:

欢迎使用pprof!如需帮助,请输入'help'。
(pprof) top10

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

英文:

Use the output profiles in coordination with the go tool e.g.:

go tool pprof testbin.test cpu.out

I'd recommend some func Benchmark*(b *testing.B) implementations for functionality you're interesting in profiling.

Once in the tool try top10:

Welcome to pprof!  For help, type 'help'.
(pprof) top10

More information: https://blog.golang.org/profiling-go-programs

huangapple
  • 本文由 发表于 2016年12月30日 18:00:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/41394227.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定