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