第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Golang 分析 - top10 僅顯示一行 100%

Golang 分析 - top10 僅顯示一行 100%

Go
Qyouu 2021-12-20 15:52:27
我嘗試分析我的 go 庫,以找出比 C++ 中的同一件事慢得多的原因。我有簡單的基準func BenchmarkFile(t *testing.B) {    tmpFile, err := ioutil.TempFile("", TMP_FILE_PREFIX)    fw, err := NewFile(tmpFile.Name())    text := []byte("testing")    for i := 0; i < b.N; i++ {        _, err = fw.Write(text)    }    fw.Close()}NewFile 返回我的自定義 Writer,它將數(shù)據(jù)編碼為我們的二進制表示,甚至壓縮它們,并寫入文件系統(tǒng)。運行go test -bench . -memprofile mem.out -cpuprofile cpu.out我得到PASSBenchmarkFile-16    2000000000           0.20 ns/opok      .../writer/iowriter 9.074s比分析它# go tool pprof cpu.out Entering interactive mode (type "help" for commands)(pprof) top10930ms of 930ms total (  100%)      flat  flat%   sum%        cum   cum%     930ms   100%   100%      930ms   100%  (pprof) 我什至嘗試編寫使用我的編寫器的 example.go 應用程序,并添加pprof.StartCPUProfile(f)如http://blog.golang.org/profiling-go-programs 中所示的內(nèi)容,但結果相同。我做錯了什么,我如何確定我的庫的瓶頸是什么?先感謝您
查看完整描述

2 回答

?
米脂

TA貢獻1836條經(jīng)驗 獲得超3個贊

好吧,這很簡單,我想添加二進制文件到 go tool pprof,si 它必須是


# go tool pprof write cpu.out 

Entering interactive mode (type "help" for commands)

(pprof) top10

7.02s of 7.38s total (95.12%)

Dropped 14 nodes (cum <= 0.04s)

Showing top 10 nodes out of 32 (cum >= 0.19s)

      flat  flat%   sum%        cum   cum%

     6.55s 88.75% 88.75%      6.76s 91.60%  syscall.Syscall

    ...

并且在使用基準測試時,會在那里創(chuàng)建二進制文件并使用它給出相同的結果。


查看完整回答
反對 回復 2021-12-20
?
一只名叫tom的貓

TA貢獻1906條經(jīng)驗 獲得超3個贊

要擴展 sejvolnd 的答案:

pprof需要實際生成cpu.out文件的二進制文件作為第一個參數(shù)。

所以你需要運行命令 go tool pprof <go binary of your program> <generaged profiling output file>

例如 go tool pprof go_binary cpu.pprof


查看完整回答
反對 回復 2021-12-20
  • 2 回答
  • 0 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號