Golang profiling-前10名仅显示一行100% 我试图剖析我的GO库,找出什么原因导致了比C++中的相同的东西慢得多。
我有一个简单的基准Golang profiling-前10名仅显示一行100% 我试图剖析我的GO库,找出什么原因导致了比C++中的相同的东西慢得多。,go,profiling,Go,Profiling,我有一个简单的基准 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
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()
}
而不是分析它
# 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)
我甚至尝试编写正在使用我的writer的example.go应用程序,并添加pprof.StartCPUProfile(f)
,如中所示,但结果相同
我做错了什么,如何确定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
...
#写入cpu.out的go工具
进入交互模式(键入“帮助”以获取命令)
(pprof)前十名
7.02秒,共7.38秒(95.12%)
丢弃14个节点(cum=0.19s)
单位百分比总和百分比总和百分比
6.55S88.75%88.75%6.76S91.60%syscall.syscall
...
当使用基准测试时,会在那里创建二进制文件,并使用它得到相同的结果 要扩展sejvolnd的答案:
pprof
需要实际生成的cpu.out
文件的二进制文件作为第一个参数
因此,您需要以go-tool pprof
e、 g.
go工具pprof\u二进制cpu.pprof
为什么要使用“i<1000”?基准测试必须使用b.N字段,否则不会给出正确的结果,因为每个基准测试函数可能会使用不同的b.N值调用多次。请澄清此答案?现在还不清楚你的解决方案是什么,或者它是否有效。我认为这很清楚。“我错过了添加二进制到go工具pprof”所以它必须是:“go工具pprof write cpu.out”,在这个命令之后,您可以看到输出,所以它工作了。。
# 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
...