config+lnd: add new option --cpuprofile for writing cpuprofile to file

In this commit we add a new option to lnd, cpuprofile. With this option
we add additional telemetry hooks into and, allowing users to generate
CPU profiling files to measure hot spots within the daemon.
This commit is contained in:
Olaoluwa Osuntokun 2017-10-14 17:08:27 -07:00
parent b7704e2de3
commit 7a2ce62346
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 15 additions and 0 deletions

View File

@ -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 <subsystem>=<level>,<subsystem2>=<level>,... 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"`

13
lnd.go
View File

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