Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com>
| ... | ... |
@@ -9,12 +9,9 @@ import ( |
| 9 | 9 |
"github.com/gorilla/mux" |
| 10 | 10 |
) |
| 11 | 11 |
|
| 12 |
-func NewProfiler() http.Handler {
|
|
| 13 |
- var ( |
|
| 14 |
- p = &Profiler{}
|
|
| 15 |
- r = mux.NewRouter() |
|
| 16 |
- ) |
|
| 17 |
- r.HandleFunc("/vars", p.expVars)
|
|
| 12 |
+func ProfilerSetup(mainRouter *mux.Router, path string) {
|
|
| 13 |
+ var r = mainRouter.PathPrefix(path).Subrouter() |
|
| 14 |
+ r.HandleFunc("/vars", expVars)
|
|
| 18 | 15 |
r.HandleFunc("/pprof/", pprof.Index)
|
| 19 | 16 |
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
|
| 20 | 17 |
r.HandleFunc("/pprof/profile", pprof.Profile)
|
| ... | ... |
@@ -23,21 +20,10 @@ func NewProfiler() http.Handler {
|
| 23 | 23 |
r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
|
| 24 | 24 |
r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
|
| 25 | 25 |
r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
|
| 26 |
- p.r = r |
|
| 27 |
- return p |
|
| 28 |
-} |
|
| 29 |
- |
|
| 30 |
-// Profiler enables pprof and expvar support via a HTTP API. |
|
| 31 |
-type Profiler struct {
|
|
| 32 |
- r *mux.Router |
|
| 33 |
-} |
|
| 34 |
- |
|
| 35 |
-func (p *Profiler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
| 36 |
- p.r.ServeHTTP(w, r) |
|
| 37 | 26 |
} |
| 38 | 27 |
|
| 39 | 28 |
// Replicated from expvar.go as not public. |
| 40 |
-func (p *Profiler) expVars(w http.ResponseWriter, r *http.Request) {
|
|
| 29 |
+func expVars(w http.ResponseWriter, r *http.Request) {
|
|
| 41 | 30 |
first := true |
| 42 | 31 |
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
| 43 | 32 |
fmt.Fprintf(w, "{\n")
|
| ... | ... |
@@ -1300,7 +1300,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local |
| 1300 | 1300 |
func createRouter(eng *engine.Engine, logging, enableCors bool, corsHeaders string, dockerVersion string) *mux.Router {
|
| 1301 | 1301 |
r := mux.NewRouter() |
| 1302 | 1302 |
if os.Getenv("DEBUG") != "" {
|
| 1303 |
- r.Handle("/debug", NewProfiler())
|
|
| 1303 |
+ ProfilerSetup(r, "/debug/") |
|
| 1304 | 1304 |
} |
| 1305 | 1305 |
m := map[string]map[string]HttpApiFunc{
|
| 1306 | 1306 |
"GET": {
|