Go1.5正式版程式效能分析小積累,實驗環境windows64

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

方法一:

使用:set GODEBUG=gctrace=1 / GODEBUG=gctrace=2

直接運行可執行檔:server.exe

格式:gc  # @#s  #%:  #+...+# ms clock, #+...+# ms cpu, #->#-># MB, # MB goal, # P

GC # 表示第幾次GC

@#s   表示程式開始多長時間執行的GC

 #%   表示程式開始GC時間佔用的百分比(percentage of time spent in GC since program start)

#+...+#   表示GC執行時CPU阻塞時間和

#->#-># MB 表示GC開始堆大小,結束堆大小,在活躍堆大小

# MB goal 表示目標對大小

# P 表示程式運行時CPU核心數 

樣本 :

gc 13 @1277.835s 0%: 0+1.0+0+1.0+1.0 ms clock, 0+1.0+0+0/1.0/0+3.0 ms cpu, 0->0->0 MB, 4 MB goal, 4 P


方法二:

import _ "net/http/pprof"go func() {log.Println(http.ListenAndServe("localhost:6060", nil))}()在程式中添加以上代碼.-----------------------------------------------------------使用下面的命令可以查看各項效能:go tool pprof http://localhost:6060/debug/pprof/heap查看30秒內的cpu使用:go tool pprof http://localhost:6060/debug/pprof/profile查看goroutime效能:go tool pprof http://localhost:6060/debug/pprof/block查看5秒的執行trace.wget http://localhost:6060/debug/pprof/trace?seconds=5在瀏覽器開啟查看:http://localhost:6060/debug/pprof/https://blog.golang.org/2011/06/profiling-go-programs.html命令:go tool pprof /mnt/Go/src/main http://localhost:6060/debug/pprof/heap輸入list可以看到詳細情況.輸入web 可以在web頁面查看此外我們也可以運行go tool pprof your-executable-name --dot profile-filename > heap.gv,這樣將得到一個heap.gv檔案,我們在graphviz裡面開啟這個檔案將得到一個更詳細的包括調用關係在內的記憶體消耗圖。當然,我們如果只需要一張圖,也可以運行dot -Tpng heap.gv > heap.png將這個gv檔案另存新檔png圖,這樣就可以像我一樣,在下面展示剖析結果了。

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.