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 committed 2017-10-14 17:08:34 -07:00
1 parent b7704e2de3
commit 7a2ce62346
2 files changed
+15

No files matched your search

+13
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)