分析器不显示函数调用(/ pgk / profile with pprof)

时间:2016-12-16 10:12:01

标签: go profiler pprof

编辑:当我将可执行文件添加到pprof调用

时工作

我试图使用https://github.com/pkg/profile中的探查器分析一个简单程序:并转到工具pprof。

package main

import "github.com/pkg/profile"

func main() {
    defer profile.Start().Stop()
    t1()
    t2()
}

func t1() {
    for i := 0; i < 9000000000; i++ {
        x := i * 2
        x += x
    }
}

func t2() {
    for i := 0; i < 1000000000; i++ {
        x := i * 2
        x += x
    }
}

这些示例显示了一个很好的表格,其中包含已调用的所有函数以及在每个函数中花费的时间,但我只看到100%的使用时间,几秒钟内没有更多信息

我该怎么做才能输出功能?它与&#34; cpu profiling disabled&#34;有什么关系?代码完成时输出的行?

这是我用来生成输出的内容:

./test 
2016/12/16 11:04:39 profile: cpu profiling enabled, /tmp/profile176930291/cpu.pprof
2016/12/16 11:04:44 profile: cpu profiling disabled, /tmp/profile176930291/cpu.pprof
martin@martin-laptop:~/work/bin$ go tool pprof -text /tmp/profile176930291/cpu.pprof 
4.90s of 4.90s total (  100%)                                                                                                                                                                                                                       
      flat  flat%   sum%        cum   cum%
     4.90s   100%   100%      4.90s   100%  

1 个答案:

答案 0 :(得分:0)

您收到的错误如下:

  

tmp的本地符号化失败:open / tmp / go-build594370835 / command-line-arguments / _obj / exe / tmp:没有这样的文件或目录

如果是这样;在源代码目录中,尝试:

go build tmp.go

重新运行go tool pprof -text ...然后会产生:

go tool pprof -text /tmp/profile668503934/cpu.pprof
5040ms of 5040ms total (  100%)
      flat  flat%   sum%        cum   cum%
    4560ms 90.48% 90.48%     4560ms 90.48%  main.t1
     480ms  9.52%   100%      480ms  9.52%  main.t2
         0     0%   100%     5040ms   100%  main.main
         0     0%   100%     5040ms   100%  runtime.goexit
         0     0%   100%     5040ms   100%  runtime.main

现在使用./tmp二进制文件中包含的符号。

我正在使用go version go1.7.3 linux/amd64

相关问题