Golang分析 – top10只显示一行100%
发布时间:2020-12-16 09:26:36 所属栏目:大数据 来源:网络整理
导读:我尝试分析我的go库,找出比c更慢的原因是什么. 我有简单的基准 func BenchmarkFile(t *testing.B) { tmpFile,err := ioutil.TempFile("",TMP_FILE_PREFIX) fw,err := NewFile(tmpFile.Name()) text := []byte("testing") for i := 0; i b.N; i++ { _,err = f
我尝试分析我的go库,找出比c更慢的原因是什么.
我有简单的基准 func BenchmarkFile(t *testing.B) { tmpFile,err := ioutil.TempFile("",TMP_FILE_PREFIX) fw,err := NewFile(tmpFile.Name()) text := []byte("testing") for i := 0; i < b.N; i++ { _,err = fw.Write(text) } fw.Close() } NewFile返回我的自定义Writer,它将数据编码为我们的二进制表示,甚至压缩它们,并写入文件系统. 运行go test -bench. -memprofile mem.out -cpuprofile cpu.out我明白了 PASS BenchmarkFile-16 2000000000 0.20 ns/op ok .../writer/iowriter 9.074s 而不是分析它 # go tool pprof cpu.out Entering interactive mode (type "help" for commands) (pprof) top10 930ms of 930ms total ( 100%) flat flat% sum% cum cum% 930ms 100% 100% 930ms 100% (pprof) 我甚至尝试编写使用我的编写器的example.go app,并添加pprof.StartCPUProfile(f),如http://blog.golang.org/profiling-go-programs所示,但结果相同. 我做错了什么,如何确定我的lib的瓶颈是什么? 解决方法
好吧,这很容易,我想念添加二进制文件去工具pprof,它必须是
# go tool pprof write cpu.out Entering interactive mode (type "help" for commands) (pprof) top10 7.02s of 7.38s total (95.12%) Dropped 14 nodes (cum <= 0.04s) Showing top 10 nodes out of 32 (cum >= 0.19s) flat flat% sum% cum cum% 6.55s 88.75% 88.75% 6.76s 91.60% syscall.Syscall ... 当使用基准测试时,在那里创建二进制并使用它给出相同的结果. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |