普通网友 2018-09-13 19:32
浏览 24
已采纳

在启用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!

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!