英文:
cpuprofile and memprofile in golang testing
问题
我在一个GO测试文件上尝试了命令go test -cpuprofile cpu.out,结果生成了一个名为cpu.out的文件,里面充满了许多64位的数字。对我来说这毫无意义。这个命令做了什么,我可以从cpu.out文件中提取什么信息?
类似地,go test -memprofile mem.out生成了一个名为mem.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.
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论