我的主塊中有以下內容:func main() { defer profile.Start().Stop() fmt.Println("running version", version, "built on", date) fmt.Println() cmd.Execute() time.Sleep(2 * time.Second)}cmdcobra 子命令在哪里。我執行 go build,然后運行二進制文件。我可以看到它生成了一個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: eventedType: cpuTime: 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 輸出。我做錯了什么嗎?謝謝!
1 回答

慕容森
TA貢獻1853條經驗 獲得超18個贊
通過配置文件 pkg 的評論看了一點之后,我設法獲得了一些樣本,方法是:
runtime.SetCPUProfileRate(5000)
在呼叫defer profile.Start().Stop()
線路之前。
- 1 回答
- 0 關注
- 113 瀏覽
添加回答
舉報
0/150
提交
取消