在启用pkg/profile的情况下运行时如何获取样本? [英] How can I get samples when running go with pkg/profile enabled?

查看:167
本文介绍了在启用pkg/profile的情况下运行时如何获取样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要内容如下:

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文件:

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

但是当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

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

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!

推荐答案

在仔细查看了配置文件pkg的注释后,我设法通过以下操作获得了一些示例:

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

runtime.SetCPUProfileRate(5000)

,在呼叫defer profile.Start().Stop()行之前.

这篇关于在启用pkg/profile的情况下运行时如何获取样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆