|
| 1 | +## GVA Pprof&Trace 功能插件 |
| 2 | +By using Go’s profiling tools to identify and correct specific bottlenecks, we can make programm faster and shrink resource occupation. |
| 3 | + |
| 4 | + |
| 5 | +### 使用步骤 |
| 6 | + |
| 7 | +#### 1. 前往GVA主程序下的initialize/router.go 在Routers 方法最末尾按照你需要的及安全模式添加本插件 |
| 8 | + 例: |
| 9 | + 本插件可以采用gva的配置文件 也可以直接写死内容作为配置 建议为gva添加配置文件结构 然后将配置传入: |
| 10 | + PluginInit(PrivateGroup, pprof.CreatePprofPlug(global.GVA_CONFIG.Pprof.Prefix)) |
| 11 | + |
| 12 | + 同样也可以在传入时写死: |
| 13 | + PluginInit(PrivateGroup, pprof.CreatePprofPlug("debug/pprof")) |
| 14 | + |
| 15 | +### 2. 配置说明 |
| 16 | + |
| 17 | +#### 2-1 全局配置结构体说明 |
| 18 | + |
| 19 | + type Pprof struct { |
| 20 | + Prefix string `mapstructure:"prefix" json:"prefix" yaml:"prefix"` // path prefix |
| 21 | + } |
| 22 | + |
| 23 | + |
| 24 | +### 3. 方法API |
| 25 | +All routers are listed in `plugin\pprof\router\pprof.go` |
| 26 | +* pprofRouter.GET("/", pprofHandler(pprof.Index)) |
| 27 | +Index responds with the pprof-formatted profile named by the request. For example, "/debug/pprof/heap" serves the "heap" profile. |
| 28 | + |
| 29 | +* pprofRouter.GET("/cmdline", pprofHandler(pprof.Cmdline)) |
| 30 | +Cmdline responds with the running program's command line, with arguments separated by NUL bytes. The package initialization registers it as /debug/pprof/cmdline. |
| 31 | + |
| 32 | +* pprofRouter.GET("/profile", pprofHandler(pprof.Profile)) |
| 33 | +Profile responds with the pprof-formatted cpu profile. Profiling lasts for duration specified in seconds GET parameter, or for 30 seconds if not specified. The package initialization registers it as /debug/pprof/profile. |
| 34 | + |
| 35 | +* pprofRouter.POST("/symbol", pprofHandler(pprof.Symbol)) |
| 36 | +Symbol looks up the program counters listed in the request, responding with a table mapping program counters to function names. The package initialization registers it as /debug/pprof/symbol. |
| 37 | + |
| 38 | +* pprofRouter.GET("/symbol", pprofHandler(pprof.Symbol)) |
| 39 | +Symbol looks up the program counters listed in the request, responding with a table mapping program counters to function names. The package initialization registers it as /debug/pprof/symbol. |
| 40 | + |
| 41 | +* pprofRouter.GET("/trace", pprofHandler(pprof.Trace)) |
| 42 | +Trace responds with the execution trace in binary form. Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified. The package initialization registers it as /debug/pprof/trace. |
| 43 | + |
| 44 | +* pprofRouter.GET("/allocs", pprofHandler(pprof.Handler("allocs").ServeHTTP)) |
| 45 | +The endpoint "/allocs" responds with the memory allocations of your running programm. |
| 46 | + |
| 47 | +* pprofRouter.GET("/block", pprofHandler(pprof.Handler("block").ServeHTTP)) |
| 48 | +The endpoint "/block" responds with the goroutine blocking profile, after calling runtime.SetBlockProfileRate in your program. |
| 49 | + |
| 50 | +* pprofRouter.GET("/goroutine", pprofHandler(pprof.Handler("goroutine").ServeHTTP)) |
| 51 | +The endpoint "/gorotine" responds with the gorotine profile of your running programm. |
| 52 | + |
| 53 | +* pprofRouter.GET("/heap", pprofHandler(pprof.Handler("heap").ServeHTTP)) |
| 54 | +The endpoint "/heap" responds with the heap profile of your running programm. |
| 55 | + |
| 56 | +* pprofRouter.GET("/mutex", pprofHandler(pprof.Handler("mutex").ServeHTTP)) |
| 57 | +The endpoint "/mutex" responds with the holders of contended mutexes, after calling runtime.SetMutexProfileFraction in your program. |
| 58 | + |
| 59 | +* pprofRouter.GET("/threadcreate", pprofHandler(pprof.Handler("threadcreate").ServeHTTP)) |
| 60 | +The endpoint "/threadcreate" responds with the created threads profile of your programm. |
| 61 | + |
| 62 | +### Reference: |
| 63 | +* Package Doc, https://pkg.go.dev/net/http/pprof |
| 64 | +* Profiling Go Programs-The go blog, https://go.dev/blog/pprof |
0 commit comments