我正在嘗試分析Go二進制文件,并且得到了令人驚訝的結(jié)果。該代碼的中有以下(被截斷的)main.go代碼,其余代碼在軟件包中monte:package mainimport ( "monte" "runtime/pprof")var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")func main() { flag.Parse() if *cpuprofile != "" { f, err := os.Create(*cpuprofile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) } monte.ExpensiveOperation() pprof.StopCPUProfile()}我用構(gòu)建我的可執(zhí)行文件go build src/main.go,然后用運行它./main -cpuprofile=monte.prof。當(dāng)我使用檢查輸出時go tool pprof main monte.prof,得到以下輸出:(pprof) top10 --cumTotal: 346 samples 280 80.9% 80.9% 343 99.1% time.Time.Format 0 0.0% 80.9% 341 98.6% runtime.interhash 0 0.0% 80.9% 341 98.6% runtime.main 0 0.0% 80.9% 251 72.5% strconv.Unquote 13 3.8% 84.7% 31 9.0% strconv.roundShortest 11 3.2% 87.9% 18 5.2% strconv.fmtE 9 2.6% 90.5% 9 2.6% runtime.markallocated 1 0.3% 90.8% 8 2.3% math/rand.Float64 2 0.6% 91.3% 8 2.3% runtime.FixAlloc_Free 7 2.0% 93.4% 8 2.3% time.nextStdChunk具有最大累積時間的函數(shù)是time.Time.Format,這對我來說似乎是錯誤的(應(yīng)該不是main嗎?)monte,盡管“昂貴的操作”大約需要10秒鐘才能完成,但沒有任何提及讓采樣器看到它。如果我將--focus=monte標(biāo)志傳遞給go tool pprof,則根本不會顯示任何示例。我認(rèn)為我在某處缺少一些標(biāo)志;有人有什么想法嗎?謝謝!
2 回答

元芳怎么了
TA貢獻1798條經(jīng)驗 獲得超7個贊
它看起來像是僅用于CPU的探查器,因此,如果您ExpensiveOperation
花費大量時間進行I / O或睡眠或類似操作,則它將不可見。(這就是“ cpu”分析器的問題。)
就數(shù)字的含義而言,看起來總共有346個樣本。根據(jù)配置程序的工作方式,這些數(shù)字有點糊涂也就不足為奇了,但是如果它是一個真正的堆棧采樣器,那么這些數(shù)字就意味著:
341/346個樣品具有main
和interhash
。您可能希望所有樣本都在堆棧上,但是那是黏糊糊的部分。
Format
堆棧上有343/346個樣本。(為什么其中的main
數(shù)目比誰知道的還要多?)
Unquote
堆棧上有251/346個樣本。因此,這些樣品251的,它們也可能有main
,interhash
和Format
堆棧。
通過這種偵探工作,您可以慢慢地整理出樣本告訴您的內(nèi)容。
當(dāng)然,如果您實際上可以看到堆棧樣本,則不必先查看其中的很多樣本,就可以確切知道發(fā)生了什么。
- 2 回答
- 0 關(guān)注
- 230 瀏覽
添加回答
舉報
0/150
提交
取消