package main
import (
"github.com/gin-gonic/gin"
"github.com/DeanThompson/ginpprof"
)
func main() {
router := gin.Default()
// automatically add routers for net/http/pprof
// e.g. /debug/pprof, /debug/pprof/heap, etc.
ginpprof.Wrap(router)
// ginpprof also plays well with *gin.RouterGroup
// group := router.Group("/debug/pprof")
// ginpprof.WrapGroup(group)
}
benchmark pprof
go test -bench -run none -cpuprofile -cpuprofile-benchmem -memprofile-blockprofile
--nodecount=<n> Show at most so many nodes [default=80]
--nodefraction=<f> Hide nodes below <f>*total [default=.005]
--edgefraction=<f> Hide edges below <f>*total [default=.001]
Flame Graph
使用源代码
listsourceError: could not find file xx on path xxx-source_path-trim_path$GOPATH/personal/demo_old$GOPATH/personal/demo_newgo tool pprof -source_path=$GOPATH/personal/demo_new -trim_path=$GOPATH/personal/demo_old /ln -sln -s $GOPATH /opt/xxx/compile_path
指标分析
CPU
CPU 性能分析启用后,Go runtime 会每 10ms 就暂停一下,记录当前运行的 goroutine 的调用堆栈及相关数据