diff --git a/profiler.go b/profiler.go new file mode 100644 index 0000000..4fec6f9 --- /dev/null +++ b/profiler.go @@ -0,0 +1,29 @@ +package middleware + +import ( + "expvar" + "net/http" + "net/http/pprof" +) + +// Profiler is a convenient subrouter used for mounting net/http/pprof +func Profiler() http.Handler { + mux := http.NewServeMux() + + mux.HandleFunc("/pprof/", pprof.Index) + mux.HandleFunc("/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/pprof/profile", pprof.Profile) + mux.HandleFunc("/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/pprof/trace", pprof.Trace) + + mux.Handle("/pprof/goroutine", pprof.Handler("goroutine")) + mux.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) + mux.Handle("/pprof/mutex", pprof.Handler("mutex")) + mux.Handle("/pprof/heap", pprof.Handler("heap")) + mux.Handle("/pprof/block", pprof.Handler("block")) + mux.Handle("/pprof/allocs", pprof.Handler("allocs")) + + mux.Handle("/vars", expvar.Handler()) + + return Wrap(mux, NoCache) +}