douzhongjian0752 2016-03-08 15:57
浏览 27
已采纳

Golang配置文件-top10仅显示100%的一行

I try to profiling my go library, to find out what is the cause of being so much slower than same thing in c++.

I have simple benchmark

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 return my custom Writer which encodes data to our binary representation, even compress them, and write to file system.

Running go test -bench . -memprofile mem.out -cpuprofile cpu.out I get

PASS
BenchmarkFile-16    2000000000           0.20 ns/op
ok      .../writer/iowriter 9.074s

Than analysing it

# 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) 

I even try to write example.go app which is using my writer, and add pprof.StartCPUProfile(f) as is shown in http://blog.golang.org/profiling-go-programs but with same result.

What am I doing wrong, and how can I determine what is bottleneck of my lib? Thank you in advance

  • 写回答

2条回答 默认 最新

  • 普通网友 2016-03-08 16:09
    关注

    Ok it's easy, I miss to add binary to go tool pprof, si it has to be

    # 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
        ...
    

    and when using benchmark tests, binary is created there and using it gives same result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题