部分文章内容为公开资料查询整理,原文出处可能未标注,如有侵权,请联系我,谢谢。邮箱地址:gnivor@163.com ►►►需要气球么?请点击我吧!

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

posted @ 2021-05-21 11:14  流了个火  阅读(1034)  评论(0编辑  收藏  举报
►►►需要气球么?请点击我吧!►►►
View My Stats