在發生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