主页 > 游戏开发  > 

go使用gopprof分析内存泄露


假设我们使用的是比如beego这样的网络框架,我们可以这样加代码来使用gopprof来进行内存泄露分析:

beego框架加gopprof分析代码:

1.先在router.go里添加路由信息:

beego.Router("/debug/pprof", &controllers.ProfController{}) beego.Router("/debug/pprof/:app([\\w]+)", &controllers.ProfController{})

2.在controller里添加接口处理:

type ProfController struct { beego.Controller } func (this *ProfController) Get() { switch this.Ctx.Input.Param(":app") { default: pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request) case "": pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request) case "cmdline": pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request) case "profile": pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request) case "symbol": pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Requ
标签:

go使用gopprof分析内存泄露由讯客互联游戏开发栏目发布,感谢您对讯客互联的认可,以及对我们原创作品以及文章的青睐,非常欢迎各位朋友分享到个人网站或者朋友圈,但转载请说明文章出处“go使用gopprof分析内存泄露