小编典典

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

go

我的主要内容如下:

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

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

    time.Sleep(2 * time.Second)
}

cmd眼镜蛇子命令在哪里。我执行构建,然后运行二进制文件。我可以看到它生成了一个pprof文件:

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

然后,我尝试使用以下方法对其进行分析:

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

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

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

如果有帮助,我跑go version go1.11 linux/amd64一个Ubuntu 16.04.5 LTS。不确定是否重要,但我正在尝试检查DigitalOcean小滴上的pprof输出。

我做错什么了吗?谢谢!


阅读 256

收藏
2020-07-02

共1个答案

小编典典

在浏览了概要文件pkg的注释后,我设法通过以下操作获得了一些样本:

runtime.SetCPUProfileRate(5000)

拨打电话之前defer profile.Start().Stop()

2020-07-02