diff --git a/cmd.go b/cmd.go index c7acf3d..7dc50d1 100644 --- a/cmd.go +++ b/cmd.go @@ -26,6 +26,9 @@ import ( "github.com/conformal/btcwire" "github.com/conformal/btcws" "io/ioutil" + "net" + "net/http" + _ "net/http/pprof" "os" "path/filepath" "sync" @@ -295,6 +298,17 @@ func main() { loggers = setLogLevel(cfg.DebugLevel) } + if cfg.Profile != "" { + go func() { + listenAddr := net.JoinHostPort("", cfg.Profile) + log.Infof("Profile server listening on %s", listenAddr) + profileRedirect := http.RedirectHandler("/debug/pprof", + http.StatusSeeOther) + http.Handle("/", profileRedirect) + log.Errorf("%v", http.ListenAndServe(listenAddr, nil)) + }() + } + // Open default account a, err := OpenAccount(cfg, "") switch err { diff --git a/config.go b/config.go index c1fb5ff..774174e 100644 --- a/config.go +++ b/config.go @@ -56,6 +56,7 @@ type config struct { Proxy string `long:"proxy" description:"Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)"` ProxyUser string `long:"proxyuser" description:"Username for proxy server"` ProxyPass string `long:"proxypass" default-mask:"-" description:"Password for proxy server"` + Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"` } // cleanAndExpandPath expands environement variables and leading ~ in the