diff --git a/cmd/root.go b/cmd/root.go index 87d426c..aca4626 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -29,6 +29,7 @@ var ( maximumFileCount uint32 minimumFileCount uint32 port uint16 + profile bool recursive bool refreshInterval string sorting bool @@ -80,6 +81,7 @@ func init() { rootCmd.Flags().Uint32Var(&maximumFileCount, "maximum-files", 1<<32-1, "skip directories with file counts over this value") rootCmd.Flags().Uint32Var(&minimumFileCount, "minimum-files", 0, "skip directories with file counts under this value") rootCmd.Flags().Uint16VarP(&port, "port", "p", 8080, "port to listen on") + rootCmd.Flags().BoolVar(&profile, "profile", false, "register net/http/pprof handlers") rootCmd.Flags().BoolVarP(&recursive, "recursive", "r", false, "recurse into subdirectories") rootCmd.Flags().StringVar(&refreshInterval, "refresh-interval", "", "force refresh interval equal to this duration (minimum 500ms)") rootCmd.Flags().BoolVarP(&sorting, "sort", "s", false, "enable sorting") diff --git a/cmd/web.go b/cmd/web.go index d13869b..8996d2f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -28,7 +28,7 @@ import ( "syscall" "time" - _ "net/http/pprof" + "net/http/pprof" "github.com/julienschmidt/httprouter" "github.com/klauspost/compress/zstd" @@ -1063,6 +1063,14 @@ func ServePage(args []string) error { mux.GET("/version", serveVersion()) + if profile { + mux.HandlerFunc("GET", "/debug/pprof/", pprof.Index) + mux.HandlerFunc("GET", "/debug/pprof/cmdline", pprof.Cmdline) + mux.HandlerFunc("GET", "/debug/pprof/profile", pprof.Profile) + mux.HandlerFunc("GET", "/debug/pprof/symbol", pprof.Symbol) + mux.HandlerFunc("GET", "/debug/pprof/trace", pprof.Trace) + } + srv := &http.Server{ Addr: net.JoinHostPort(bind, strconv.Itoa(int(port))), Handler: mux,