2022-02-13 08:22:50 +13:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/pprof"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi"
|
|
|
|
|
2022-07-14 10:58:22 +12:00
|
|
|
"github.com/demodesk/neko/pkg/types"
|
2022-02-13 08:22:50 +13:00
|
|
|
)
|
|
|
|
|
|
|
|
func pprofHandler(r types.Router) {
|
|
|
|
r.Get("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) error {
|
|
|
|
pprof.Index(w, r)
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
|
|
|
r.Get("/debug/pprof/{action}", func(w http.ResponseWriter, r *http.Request) error {
|
|
|
|
action := chi.URLParam(r, "action")
|
|
|
|
|
|
|
|
switch action {
|
|
|
|
case "cmdline":
|
|
|
|
pprof.Cmdline(w, r)
|
|
|
|
case "profile":
|
|
|
|
pprof.Profile(w, r)
|
|
|
|
case "symbol":
|
|
|
|
pprof.Symbol(w, r)
|
|
|
|
case "trace":
|
|
|
|
pprof.Trace(w, r)
|
|
|
|
default:
|
|
|
|
pprof.Handler(action).ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|