Added --profile flag for net/http/pprof

This commit is contained in:
Seednode 2023-09-06 10:15:11 -05:00
parent ec8b5c9c7f
commit de9bc0af97
2 changed files with 11 additions and 1 deletions

View File

@ -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")

View File

@ -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,