mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 21:01:31 +00:00
add pprof support
This commit is contained in:
parent
d80ba7b084
commit
c967f2d63f
11
beego.go
11
beego.go
@ -16,6 +16,7 @@ var (
|
|||||||
HttpPort int
|
HttpPort int
|
||||||
RecoverPanic bool
|
RecoverPanic bool
|
||||||
AutoRender bool
|
AutoRender bool
|
||||||
|
PprofOn bool
|
||||||
ViewsPath string
|
ViewsPath string
|
||||||
RunMode string //"dev" or "prod"
|
RunMode string //"dev" or "prod"
|
||||||
AppConfig *Config
|
AppConfig *Config
|
||||||
@ -35,6 +36,7 @@ func init() {
|
|||||||
RunMode = "prod" //default runmod
|
RunMode = "prod" //default runmod
|
||||||
AutoRender = true
|
AutoRender = true
|
||||||
RecoverPanic = true
|
RecoverPanic = true
|
||||||
|
PprofOn = false
|
||||||
ViewsPath = "views"
|
ViewsPath = "views"
|
||||||
} else {
|
} else {
|
||||||
HttpAddr = AppConfig.String("httpaddr")
|
HttpAddr = AppConfig.String("httpaddr")
|
||||||
@ -59,6 +61,11 @@ func init() {
|
|||||||
} else {
|
} else {
|
||||||
RecoverPanic = ar
|
RecoverPanic = ar
|
||||||
}
|
}
|
||||||
|
if ar, err := AppConfig.Bool("pprofon"); err != nil {
|
||||||
|
PprofOn = false
|
||||||
|
} else {
|
||||||
|
PprofOn = ar
|
||||||
|
}
|
||||||
if views := AppConfig.String("viewspath"); views == "" {
|
if views := AppConfig.String("viewspath"); views == "" {
|
||||||
ViewsPath = "views"
|
ViewsPath = "views"
|
||||||
} else {
|
} else {
|
||||||
@ -147,5 +154,9 @@ func FilterPrefixPath(path string, filter http.HandlerFunc) *App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Run() {
|
func Run() {
|
||||||
|
if PprofOn {
|
||||||
|
BeeApp.RegisterController(`/debug/pprof`, &ProfController{})
|
||||||
|
BeeApp.RegisterController(`/debug/pprof/:pp([\w+])`, &ProfController{})
|
||||||
|
}
|
||||||
BeeApp.Run()
|
BeeApp.Run()
|
||||||
}
|
}
|
||||||
|
22
pprof.go
Normal file
22
pprof.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package beego
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http/pprof"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProfController struct {
|
||||||
|
Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *ProfController) Get() {
|
||||||
|
ptype := this.Ctx.Params[":pp"]
|
||||||
|
if ptype == "" {
|
||||||
|
pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
|
||||||
|
} else if ptype == "cmdline" {
|
||||||
|
pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
|
||||||
|
} else if ptype == "profile" {
|
||||||
|
pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
|
||||||
|
} else if ptype == "symbol" {
|
||||||
|
pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user