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 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解