Add way to dynamically profile

Added new `--http-pprof` option, example: "--http-pprof :8181"
It starts web server on given address, and expose special /debug/pprof
endpoint

See https://golang.org/pkg/net/http/pprof/
This commit is contained in:
Leonid Bugaev
2019-02-16 08:59:43 +01:00
parent 85c6070775
commit ec3f104c8c
2 changed files with 10 additions and 0 deletions
+7
View File
@@ -9,6 +9,7 @@ import (
"log"
"net/http"
"net/http/httputil"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
@@ -77,6 +78,12 @@ func main() {
profileCPU(*cpuprofile)
}
if Settings.pprof != "" {
go func() {
log.Println(http.ListenAndServe(Settings.pprof, nil))
}()
}
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
+3
View File
@@ -30,6 +30,8 @@ type AppSettings struct {
stats bool
exitAfter time.Duration
pprof string
splitOutput bool
inputDummy MultiOption
@@ -83,6 +85,7 @@ func usage() {
func init() {
flag.Usage = usage
flag.StringVar(&Settings.pprof, "http-pprof", "", "Enable profiling. Starts http server on specified port, exposing special /debug/pprof endpoint. Example: `:8181`")
flag.BoolVar(&Settings.verbose, "verbose", false, "Turn on more verbose output")
flag.BoolVar(&Settings.debug, "debug", false, "Turn on debug output, shows all intercepted traffic. Works only when with `verbose` flag")
flag.BoolVar(&Settings.stats, "stats", false, "Turn on queue stats output")