|
@@ -9,12 +9,9 @@ import (
|
|
"github.com/gorilla/mux"
|
|
"github.com/gorilla/mux"
|
|
)
|
|
)
|
|
|
|
|
|
-func NewProfiler() http.Handler {
|
|
|
|
- var (
|
|
|
|
- p = &Profiler{}
|
|
|
|
- r = mux.NewRouter()
|
|
|
|
- )
|
|
|
|
- r.HandleFunc("/vars", p.expVars)
|
|
|
|
|
|
+func ProfilerSetup(mainRouter *mux.Router, path string) {
|
|
|
|
+ var r = mainRouter.PathPrefix(path).Subrouter()
|
|
|
|
+ r.HandleFunc("/vars", expVars)
|
|
r.HandleFunc("/pprof/", pprof.Index)
|
|
r.HandleFunc("/pprof/", pprof.Index)
|
|
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
|
|
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
|
|
r.HandleFunc("/pprof/profile", pprof.Profile)
|
|
r.HandleFunc("/pprof/profile", pprof.Profile)
|
|
@@ -23,21 +20,10 @@ func NewProfiler() http.Handler {
|
|
r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
|
|
r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
|
|
r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
|
|
r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
|
|
r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
|
|
r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
|
|
- p.r = r
|
|
|
|
- return p
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-// Profiler enables pprof and expvar support via a HTTP API.
|
|
|
|
-type Profiler struct {
|
|
|
|
- r *mux.Router
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-func (p *Profiler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
|
- p.r.ServeHTTP(w, r)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// Replicated from expvar.go as not public.
|
|
// Replicated from expvar.go as not public.
|
|
-func (p *Profiler) expVars(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
+func expVars(w http.ResponseWriter, r *http.Request) {
|
|
first := true
|
|
first := true
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
fmt.Fprintf(w, "{\n")
|
|
fmt.Fprintf(w, "{\n")
|