|
|
@ -19,28 +19,45 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
func init() { |
|
|
|
v := os.Getenv("HTTP_PERF") |
|
|
|
v := os.Getenv("HTTP_PERF") |
|
|
|
if v == "" { |
|
|
|
|
|
|
|
v = "tcp://0.0.0.0:2333" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
flag.StringVar(&_perfDSN, "http.perf", v, "listen http perf dsn, or use HTTP_PERF env variable.") |
|
|
|
flag.StringVar(&_perfDSN, "http.perf", v, "listen http perf dsn, or use HTTP_PERF env variable.") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func startPerf() { |
|
|
|
func startPerf(engine *Engine) { |
|
|
|
_perfOnce.Do(func() { |
|
|
|
_perfOnce.Do(func() { |
|
|
|
mux := http.NewServeMux() |
|
|
|
if os.Getenv("HTTP_PERF") == "" { |
|
|
|
mux.HandleFunc("/debug/pprof/", pprof.Index) |
|
|
|
prefixRouter := engine.Group("/debug/pprof") |
|
|
|
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) |
|
|
|
{ |
|
|
|
mux.HandleFunc("/debug/pprof/profile", pprof.Profile) |
|
|
|
prefixRouter.GET("/", pprofHandler(pprof.Index)) |
|
|
|
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) |
|
|
|
prefixRouter.GET("/cmdline", pprofHandler(pprof.Cmdline)) |
|
|
|
|
|
|
|
prefixRouter.GET("/profile", pprofHandler(pprof.Profile)) |
|
|
|
|
|
|
|
prefixRouter.POST("/symbol", pprofHandler(pprof.Symbol)) |
|
|
|
|
|
|
|
prefixRouter.GET("/symbol", pprofHandler(pprof.Symbol)) |
|
|
|
|
|
|
|
prefixRouter.GET("/trace", pprofHandler(pprof.Trace)) |
|
|
|
|
|
|
|
prefixRouter.GET("/allocs", pprofHandler(pprof.Handler("allocs").ServeHTTP)) |
|
|
|
|
|
|
|
prefixRouter.GET("/block", pprofHandler(pprof.Handler("block").ServeHTTP)) |
|
|
|
|
|
|
|
prefixRouter.GET("/goroutine", pprofHandler(pprof.Handler("goroutine").ServeHTTP)) |
|
|
|
|
|
|
|
prefixRouter.GET("/heap", pprofHandler(pprof.Handler("heap").ServeHTTP)) |
|
|
|
|
|
|
|
prefixRouter.GET("/mutex", pprofHandler(pprof.Handler("mutex").ServeHTTP)) |
|
|
|
|
|
|
|
prefixRouter.GET("/threadcreate", pprofHandler(pprof.Handler("threadcreate").ServeHTTP)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
go func() { |
|
|
|
d, err := dsn.Parse(_perfDSN) |
|
|
|
d, err := dsn.Parse(_perfDSN) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
panic(errors.Errorf("blademaster: http perf dsn must be tcp://$host:port, %s:error(%v)", _perfDSN, err)) |
|
|
|
panic(errors.Errorf("blademaster: http perf dsn must be tcp://$host:port, %s:error(%v)", _perfDSN, err)) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := http.ListenAndServe(d.Host, mux); err != nil { |
|
|
|
if err := http.ListenAndServe(d.Host, nil); err != nil { |
|
|
|
panic(errors.Errorf("blademaster: listen %s: error(%v)", d.Host, err)) |
|
|
|
panic(errors.Errorf("blademaster: listen %s: error(%v)", d.Host, err)) |
|
|
|
} |
|
|
|
} |
|
|
|
}() |
|
|
|
}() |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func pprofHandler(h http.HandlerFunc) HandlerFunc { |
|
|
|
|
|
|
|
handler := http.HandlerFunc(h) |
|
|
|
|
|
|
|
return func(c *Context) { |
|
|
|
|
|
|
|
handler.ServeHTTP(c.Writer, c.Request) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|