我的主塊中有以下內(nèi)容:func main() { defer profile.Start().Stop() fmt.Println("running version", version, "built on", date) fmt.Println() cmd.Execute() time.Sleep(2 * time.Second)}cmdcobra 子命令在哪里。我執(zhí)行 go build,然后運(yùn)行二進(jìn)制文件。我可以看到它生成了一個(gè)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但是當(dāng) pprof 打開時(shí),我看到了這個(gè):File: eventedType: cpuTime: Sep 13, 2018 at 6:43pm (UTC)Duration: 5.49s, Total samples = 0如果有幫助,我正在運(yùn)行g(shù)o version go1.11 linux/amd64一個(gè)Ubuntu 16.04.5 LTS. 不確定它是否重要,但我正在嘗試檢查 DigitalOcean 液滴上的 pprof 輸出。我做錯(cuò)了什么嗎?謝謝!
1 回答

慕容森
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
通過配置文件 pkg 的評(píng)論看了一點(diǎn)之后,我設(shè)法獲得了一些樣本,方法是:
runtime.SetCPUProfileRate(5000)
在呼叫defer profile.Start().Stop()
線路之前。
- 1 回答
- 0 關(guān)注
- 111 瀏覽
添加回答
舉報(bào)
0/150
提交
取消