Manager: add profiler support
Add a `-pprof` CLI option to enable the profiler. It will expose profiler info on the web interface at `/debug/pprof/`. To have a nice view of this, including flame graphs, run: ``` go tool pprof -http localhost:8082 http://localhost:8080/debug/pprof/profile ```
This commit is contained in:
parent
904b6c0d73
commit
b511fad968
@ -11,10 +11,12 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
http_pprof "net/http/pprof"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -55,6 +57,7 @@ var cliArgs struct {
|
|||||||
writeConfig bool
|
writeConfig bool
|
||||||
delayResponses bool
|
delayResponses bool
|
||||||
firstTimeWizard bool
|
firstTimeWizard bool
|
||||||
|
pprof bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -381,6 +384,20 @@ func buildWebService(
|
|||||||
return c.Redirect(http.StatusTemporaryRedirect, "/app/")
|
return c.Redirect(http.StatusTemporaryRedirect, "/app/")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Register profiler functions.
|
||||||
|
if cliArgs.pprof {
|
||||||
|
e.GET("/debug/pprof/", echo.WrapHandler(http.HandlerFunc(http_pprof.Index)))
|
||||||
|
e.GET("/debug/pprof/cmdline", echo.WrapHandler(http.HandlerFunc(http_pprof.Cmdline)))
|
||||||
|
e.GET("/debug/pprof/profile", echo.WrapHandler(http.HandlerFunc(http_pprof.Profile)))
|
||||||
|
e.GET("/debug/pprof/symbol", echo.WrapHandler(http.HandlerFunc(http_pprof.Symbol)))
|
||||||
|
e.GET("/debug/pprof/trace", echo.WrapHandler(http.HandlerFunc(http_pprof.Trace)))
|
||||||
|
for _, profile := range pprof.Profiles() {
|
||||||
|
name := profile.Name()
|
||||||
|
e.GET("/debug/pprof/"+name, echo.WrapHandler(http_pprof.Handler(name)))
|
||||||
|
}
|
||||||
|
log.Info().Msg("profiler debugging info available on /debug/pprof/")
|
||||||
|
}
|
||||||
|
|
||||||
// Log available routes
|
// Log available routes
|
||||||
routeLogger := log.Level(zerolog.TraceLevel)
|
routeLogger := log.Level(zerolog.TraceLevel)
|
||||||
routeLogger.Trace().Msg("available routes:")
|
routeLogger.Trace().Msg("available routes:")
|
||||||
@ -476,6 +493,7 @@ func parseCliArgs() {
|
|||||||
flag.BoolVar(&cliArgs.delayResponses, "delay", false,
|
flag.BoolVar(&cliArgs.delayResponses, "delay", false,
|
||||||
"Add a random delay to any HTTP responses. This aids in development of Flamenco Manager's web frontend.")
|
"Add a random delay to any HTTP responses. This aids in development of Flamenco Manager's web frontend.")
|
||||||
flag.BoolVar(&cliArgs.firstTimeWizard, "wizard", false, "Open a webbrowser with the first-time configuration wizard.")
|
flag.BoolVar(&cliArgs.firstTimeWizard, "wizard", false, "Open a webbrowser with the first-time configuration wizard.")
|
||||||
|
flag.BoolVar(&cliArgs.pprof, "pprof", false, "Expose profiler endpoints on /debug/pprof/.")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user