亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

“go test -cpuprofile”不會生成完整的跟蹤

“go test -cpuprofile”不會生成完整的跟蹤

Go
喵喔喔 2022-06-21 16:31:15
問題我有一個帶有測試套件的 go 包。當我為此包運行測試套件時,總運行時間約為 7 秒:$ go test ./mydbpackage/ -count 1ok      mymodule/mydbpackage    7.253s但是,當我添加一個-cpuprofile=cpu.out選項時,采樣不會覆蓋整個運行:$ go test ./mydbpackage/ -count 1 -cpuprofile=cpu.outok      mymodule/mydbpackage    7.029s$ go tool pprof -text -cum cpu.outFile: mydbpackage.testType: cpuTime: Aug 6, 2020 at 9:42am (CEST)Duration: 5.22s, Total samples = 780ms (14.95%)     # <--- depending on the runs, I get 400ms to 1sShowing nodes accounting for 780ms, 100% of 780ms total      flat  flat%   sum%        cum   cum%         0     0%     0%      440ms 56.41%  testing.tRunner      10ms  1.28%  1.28%      220ms 28.21%  database/sql.withLock      10ms  1.28%  2.56%      180ms 23.08%  runtime.findrunnable         0     0%  2.56%      180ms 23.08%  runtime.mcall      ...查看收集的樣本:# sample from another run :$ go tool pprof -traces cpu.out | grep "ms "  # get the first line of each sample      10ms   runtime.nanotime      10ms   fmt.(*readRune).ReadRune      30ms   syscall.Syscall      10ms   runtime.scanobject      10ms   runtime.gentraceback      ...# 98 samples collected, for a total sum of 1.12s我看到的問題是:由于某種原因,采樣分析器停止收集樣本,或者在某個時候被阻塞/減速。語境go版本是1.14.6,平臺是linux/amd64$ go versiongo version go1.14.6 linux/amd64這個包包含與數據庫交互的代碼,測試是在一個實時的 postgresql 服務器上運行的。我嘗試過的一件事:t.Skip()內部調用runtime.Goexit(),所以我用t.Skip簡單的return;替換了對和變體的調用。但這并沒有改變結果。問題為什么不收集更多樣本?我有一些已知的模式會阻止/減慢采樣器,或者提前終止采樣器?
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

-cpuprofile創建一個配置文件,其中僅對積極使用 CPU 的 goroutine 進行采樣。

在我的用例中:我的 go 代碼花費大量時間等待 postgresql 服務器的答案。

使用 生成跟蹤go test -trace=trace.out,然后使用 提取網絡阻塞配置文件go tool trace -pprof=net trace.out > network.out會產生更多相關信息。

作為參考,除了使用 打開完整跟蹤go tool trace trace.out之外,您還可以傳遞以下值-pprof=

來自go tool trace文檔

  • net:網絡阻止配置文件

  • sync:同步阻塞配置文件

  • 系統調用:系統調用阻塞配置文件

  • sched:調度程序延遲配置文件


查看完整回答
反對 回復 2022-06-21
  • 1 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號