go语言开发工具分享

2020-12-18  本文已影响0人  voidFan

一、google的go语言分析诊断工具

二、go代码调试工具

GO语言调试利器——dlv

三、Golang Tool pprof 性能分析工具

goroutine - 所有goroutine的信息
heap - 堆内存的信息
allocs - a sampling of all past memory allocations
threadcreate - 线程信息
block - stack traces that led to blocking on synchronization primitives
mutex - 锁的信息
goroutine: 获取程序当前所有 goroutine 的堆栈信息。
heap: 包含每个 goroutine 分配大小,分配堆栈等。每分配 runtime.MemProfileRate(默认为512K) 个字节进行一次数据采样。
threadcreate: 获取导致创建 OS 线程的 goroutine 堆栈
block: 获取导致goroutine阻塞的堆栈(如 channel, mutex 等),使用前需要先调用 runtime.SetBlockProfileRate
mutex: 获取导致 mutex 争用的 goroutine 堆栈,使用前需要先调用 runtime.SetMutexProfileFraction

上面通过浏览器访问http服务的方式,需要有图形界面。而线上服务器通常是没有图形界面的,可以通过命令行方式来分析,或者将profile拷贝到本地,再生成调用关系图

import _ "net/http/pprof"
func main() {
    ......
    go func() {
        log.Println(http.ListenAndServe("localhost:8211", nil))
    }()
    ......
}
go tool pprof http://localhost:8211/debug/pprof/goroutine
go tool pprof http://localhost:8211/debug/pprof/profile
go tool pprof http://localhost:8211/debug/pprof/heap

什么是内存泄露

怎么发现内存泄露

四、golang代码级调优方法

五、业务调优

上一篇下一篇

猜你喜欢

热点阅读