GoFrameWeb ServerpprofEnablePProf/debug/pprof
启用EnablePProf
我们来看一个简单的例子:
s.EnablePProf()
/debug/pprof/*action
/debug/pprof/cmdline
/debug/pprof/profile
/debug/pprof/symbol
/debug/pprof/trace
/debug/pprof/*actiongo tool pprof
StartPProfServer
StartPProfServerPProf ServerHTTP ServerGRPCPProf Server
goroutinePProd Server
以上示例可以改进为:
指标heapthreadcreategoroutinegoroutineblockgoroutineruntime.SetBlockProfileRatemutexruntime.SetMutexProfileFraction
页面/debug/pprof
pprof
2、堆使用量
goroutine
性能采集分析go tool pprof
go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"
pprof3030WebServertop10webgo tool pprofpprof
CPU性能分析
本示例中的命令行性能分析结果如下:
$ go tool pprof "http://127.0.0.1:8199/debug/pprof/profile"
Fetching profile over HTTP from http://127.0.0.1:8199/debug/pprof/profile
Saved profile in /home/john/pprof/pprof.___go_build_pprof_go.samples.cpu.001.pb.gz
File: ___go_build_pprof_go
Type: cpu
Time: Apr 17, 2018 at 10:53pm (CST)
Duration: 30s, Total samples = 80ms ( 0.27%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) top10
Showing nodes accounting for 80ms, 100% of 80ms total
Showing top 10 nodes out of 49
flat flat% sum% cum cum%
10ms 12.50% 12.50% 10ms 12.50% github.com/gogf/gf/v2/net/ghttp.(*Cookie).Get /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/net/ghttp/http_server_cookie.go
10ms 12.50% 25.00% 10ms 12.50% internal/poll.runtime_pollReset /home/john/Softs/go1.9.2/src/runtime/netpoll.go
10ms 12.50% 37.50% 10ms 12.50% runtime.futex /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s
10ms 12.50% 50.00% 10ms 12.50% runtime.getitab /home/john/Softs/go1.9.2/src/runtime/iface.go
10ms 12.50% 62.50% 10ms 12.50% runtime.newarray /home/john/Softs/go1.9.2/src/runtime/slice.go
10ms 12.50% 75.00% 10ms 12.50% runtime.rawstringtmp /home/john/Softs/go1.9.2/src/runtime/string.go
10ms 12.50% 87.50% 10ms 12.50% runtime.usleep /home/john/Softs/go1.9.2/src/runtime/sys_linux_amd64.s
10ms 12.50% 100% 10ms 12.50% sync.(*RWMutex).Lock /home/john/Softs/go1.9.2/src/sync/rwmutex.go
0 0% 100% 10ms 12.50% bufio.(*Writer).Flush /home/john/Softs/go1.9.2/src/bufio/bufio.go
0 0% 100% 10ms 12.50% github.com/gogf/gf/v2/container/gqueue.(*Queue).PopFront /home/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/v2/container/gqueue/gqueue.go
(pprof) web
Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH
(pprof) web
(pprof)
webGraphvizUbuntusudo apt-get install graphvizMacOSbrew install Graphvizweb
内存使用分析
go tool pprof
web