diff --git a/config.go b/config.go index 8879d62c..5ea281be 100644 --- a/config.go +++ b/config.go @@ -107,6 +107,8 @@ type config struct { DebugLevel string `short:"d" long:"debuglevel" description:"Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify =,=,... to set the log level for individual subsystems -- Use show to list available subsystems"` + CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"` + Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536"` PeerPort int `long:"peerport" description:"The port to listen on for incoming p2p connections"` diff --git a/lnd.go b/lnd.go index 5e2f3e78..9e38c122 100644 --- a/lnd.go +++ b/lnd.go @@ -16,6 +16,7 @@ import ( _ "net/http/pprof" "os" "runtime" + "runtime/pprof" "strconv" "time" @@ -88,6 +89,18 @@ func lndMain() error { }() } + // Write cpu profile if requested. + if cfg.CPUProfile != "" { + f, err := os.Create(cfg.CPUProfile) + if err != nil { + ltndLog.Errorf("Unable to create cpu profile: %v", err) + return err + } + pprof.StartCPUProfile(f) + defer f.Close() + defer pprof.StopCPUProfile() + } + // Open the channeldb, which is dedicated to storing channel, and // network related metadata. chanDB, err := channeldb.Open(cfg.DataDir)