go profiling相關

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。一、官方文檔
https://blog.golang.org/profiling-go-programs

$cd your_programe_dir
$go build
$./your_programe -cpuprofile=xxx.prof
$go tool pprof ./your_programe xxx.prof
Entering interactive mode (type "help" for commands)
(pprof) top 10
...

(pprof) web  產生svg檔案並開啟

註:mac預設用sublime開啟,需要修改成chrome: http://blog.csdn.net/jiaolongdy/article/details/50945684



1.如果出現提示:
Cannot find dot, have you installed Graphviz?


需要用root使用者安裝Graphviz
$sudo brew install Graphviz


2.如果出現提示:
profile is empty


那是因為預設的pprof的採樣頻率是每秒100次,如果你的程式運行太快,在第一次採樣前就結束了,就會出現這個情況。
要不就在程式裡面加for迴圈或者sleep,要不就調整採樣頻率(見二)


二、
一開始,有人寫了一個package,可以定製化profiing:
https://github.com/davecheney/profile


但是後來又更新了,具體原因如下:
http://dave.cheney.net/2014/10/22/simple-profiling-package-moved-updated


因為有些項目已經用了舊的API,所以作者直接給了個新package:
https://github.com/pkg/profile

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.