doucong1887
2018-09-13 19:32
浏览 19
已采纳

在启用pkg / profile的情况下运行时如何获取样本?

I have the following in my main block:

func main() {
    defer profile.Start().Stop()

    fmt.Println("running version", version, "built on", date)
    fmt.Println()
    cmd.Execute()

    time.Sleep(2 * time.Second)
}

where cmd is a cobra subcommand. I do a go build, and then I run the binary. I can see that it generates a pprof file:

2018/09/13 18:43:26 profile: cpu profiling enabled, /tmp/profile705487093/cpu.pprof
... output deleted ...
2018/09/13 18:43:31 profile: cpu profiling disabled, /tmp/profile705487093/cpu.pprof

Then I'm trying to analyze it, using:

go tool pprof /root/code/debug/evented /tmp/profile705487093/cpu.pprof

But when pprof opens, I see this:

File: evented
Type: cpu
Time: Sep 13, 2018 at 6:43pm (UTC)
Duration: 5.49s, Total samples = 0

In case it helps, I'm running go version go1.11 linux/amd64 on a Ubuntu 16.04.5 LTS. Not sure whether it matters, but I'm trying to inspect the pprof output on a DigitalOcean droplet.

Is there something that I'm doing wrong? Thanks!

图片转代码服务由CSDN问答提供 功能建议

我的主要内容如下:

  func  main(){
延迟profile.Start()。Stop()
 
 fmt.Println(“运行版本”,版本,“构建日期”,日期)
 fmt.Println()
 cmd.Execute  ()
 
 time.Sleep(2 * time.Second)
} 
   
 
 

,其中 cmd 是cobra子命令。 我进行构建,然后运行二进制文件。 我可以看到它生成了一个 pprof 文件:

  2018/09/13 18:43:26配置文件:启用了CPU性能分析,/ tmp /  profile705487093 / cpu.pprof 
 ...输出已删除... 
2018 / 09/13 18:43:31 profile:禁用cpu分析,/tmp/profile705487093/cpu.pprof
   
 
 

然后我尝试使用以下工具对其进行分析:

  go工具pprof / root / code / debug / evented / tmp / profile705487093 / cpu。  pprof 
   
 
 

但是当打开pprof时,我看到的是:

 文件:evented 
Type:cpu 
Time  :2018年9月13日下午6:43(UTC)
持续时间:5.49s,总样本= 0 
   
 
 

如果有帮助,我正在运行 Ubuntu 16.04.5 LTS 上>转到go1.11 linux / amd64 版本。 不确定是否重要,但是我正在尝试检查DigitalOcean小滴上的pprof输出。

是否存在我做错了什么? 谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxin2003 2018-09-13 21:18
    已采纳

    After looking a bit through the comments of the profile pkg, I managed to get some samples, by doing this:

    runtime.SetCPUProfileRate(5000)
    

    before calling the defer profile.Start().Stop() line.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题