go筆記-查看golang程序中正在執行的goroutine


在發生goroutine泄漏/內存泄漏時,經常需要查看代碼中哪一部分goroutine數量過多,可采用以下方法

引入pprof包
import _ "net/http/pprof"
開啟http監聽服務

func main() {
        go func() {
                log.Println(http.ListenAndServe("localhost:8888", nil))
        }()
}

方法1:
go tool pprof http://1.2.3.4:8888/debug/pprof/goroutine

輸入 pdf 生成goroutine pdf文件

方法2:
curl http://1.2.3.4:8888/debug/pprof/goroutine?debug=1

參考資料:
https://blog.csdn.net/lanyang123456/article/details/106984623


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM