普通网友 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.

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

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?