c967f2d6 by xiemengjun

add pprof support

1 parent d80ba7b0
...@@ -16,6 +16,7 @@ var ( ...@@ -16,6 +16,7 @@ var (
16 HttpPort int 16 HttpPort int
17 RecoverPanic bool 17 RecoverPanic bool
18 AutoRender bool 18 AutoRender bool
19 PprofOn bool
19 ViewsPath string 20 ViewsPath string
20 RunMode string //"dev" or "prod" 21 RunMode string //"dev" or "prod"
21 AppConfig *Config 22 AppConfig *Config
...@@ -35,6 +36,7 @@ func init() { ...@@ -35,6 +36,7 @@ func init() {
35 RunMode = "prod" //default runmod 36 RunMode = "prod" //default runmod
36 AutoRender = true 37 AutoRender = true
37 RecoverPanic = true 38 RecoverPanic = true
39 PprofOn = false
38 ViewsPath = "views" 40 ViewsPath = "views"
39 } else { 41 } else {
40 HttpAddr = AppConfig.String("httpaddr") 42 HttpAddr = AppConfig.String("httpaddr")
...@@ -59,6 +61,11 @@ func init() { ...@@ -59,6 +61,11 @@ func init() {
59 } else { 61 } else {
60 RecoverPanic = ar 62 RecoverPanic = ar
61 } 63 }
64 if ar, err := AppConfig.Bool("pprofon"); err != nil {
65 PprofOn = false
66 } else {
67 PprofOn = ar
68 }
62 if views := AppConfig.String("viewspath"); views == "" { 69 if views := AppConfig.String("viewspath"); views == "" {
63 ViewsPath = "views" 70 ViewsPath = "views"
64 } else { 71 } else {
...@@ -147,5 +154,9 @@ func FilterPrefixPath(path string, filter http.HandlerFunc) *App { ...@@ -147,5 +154,9 @@ func FilterPrefixPath(path string, filter http.HandlerFunc) *App {
147 } 154 }
148 155
149 func Run() { 156 func Run() {
157 if PprofOn {
158 BeeApp.RegisterController(`/debug/pprof`, &ProfController{})
159 BeeApp.RegisterController(`/debug/pprof/:pp([\w+])`, &ProfController{})
160 }
150 BeeApp.Run() 161 BeeApp.Run()
151 } 162 }
......
1 package beego
2
3 import (
4 "net/http/pprof"
5 )
6
7 type ProfController struct {
8 Controller
9 }
10
11 func (this *ProfController) Get() {
12 ptype := this.Ctx.Params[":pp"]
13 if ptype == "" {
14 pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
15 } else if ptype == "cmdline" {
16 pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
17 } else if ptype == "profile" {
18 pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
19 } else if ptype == "symbol" {
20 pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
21 }
22 }
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!