middleware/profiler.go

30 lines
837 B
Go
Raw Normal View History

2023-12-25 01:06:48 +00:00
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)
}