您的位置:首页 > 财经 > 金融 > golang性能调试工具net/http/pprof

golang性能调试工具net/http/pprof

2024/12/30 22:40:35 来源:https://blog.csdn.net/flynetcn/article/details/140494485  浏览:    关键词:golang性能调试工具net/http/pprof

代码引入net/http/pprof:

package mainimport ("fmt""net/http"_ "net/http/pprof"
)func main() {go func() {fmt.Println(http.ListenAndServe(":9192", nil))}()
}

编译启动后,通过页面访问:

http://192.168.137.2:9192/debug/pprof/

分为以下项目:

Profile Descriptions:

  • allocs:

    A sampling of all past memory allocations
  • block:

    Stack traces that led to blocking on synchronization primitives
  • cmdline:

    The command line invocation of the current program
  • goroutine:

    Stack traces of all current goroutines. Use debug=2 as a query parameter to export in the same format as an unrecovered panic.
  • heap:

    A sampling of memory allocations of live objects. You can specify the gc GET parameter to run GC before taking the heap sample.
  • mutex:

    Stack traces of holders of contended mutexes
  • profile:

    CPU profile. You can specify the duration in the seconds GET parameter. After you get the profile file, use the go tool pprof command to investigate the profile.
  • threadcreate:

    Stack traces that led to the creation of new OS threads
  • trace:

    A trace of execution of the current program. You can specify the duration in the seconds GET parameter. After you get the trace file, use the go tool trace command to investigate the trace.

但是此种方式查看不够直观,可以通过go tool pprof工具生成动态图像查看:

yum install graphviz

查看内存分配:

go tool pprof -http=192.168.137.2:8000 http://127.0.0.1:9192/debug/pprof/allocs

查看CPU占用:

go tool pprof -http=192.168.137.2:8000 http://127.0.0.1:9192/debug/pprof/profile

本机防火墙开放8000端口,通过页面访问:

firewall-cmd --add-port=8000/tcp --permanent

firewall-cmd --reload

http://192.168.137.2:8000/ui/

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com