[lbry] runtime: Add --memprofile option

* Add --memprofile option. Add memprofile to sample config.
* Add --memprofile to doc.go.
This commit is contained in:
Jonathan Moody 2022-06-03 15:08:09 -04:00 committed by GitHub
parent 92a7a2087a
commit 15191b7ede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View file

@ -117,6 +117,7 @@ type config struct {
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
ConnectPeers []string `long:"connect" description:"Connect only to the specified peers at startup"`
CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"`
MemProfile string `long:"memprofile" description:"Write memory profile to the specified file"`
DataDir string `short:"b" long:"datadir" description:"Directory to store data"`
DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"`
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"`

1
doc.go
View file

@ -78,6 +78,7 @@ Application Options:
memory (default: 100)
--maxpeers= Max number of inbound and outbound peers
(default: 125)
--memprofile= Write memory profile to the specified file
--miningaddr= Add the specified payment address to the list of
addresses to use for generated blocks -- At least
one address is required if the generate option is

19
lbcd.go
View file

@ -92,6 +92,25 @@ func btcdMain(serverChan chan<- *server) error {
defer pprof.StopCPUProfile()
}
// Write memory profile if requested.
if cfg.MemProfile != "" {
f, err := os.Create(cfg.MemProfile + ".heap")
if err != nil {
btcdLog.Errorf("Unable to create mem profile: %v", err)
return err
}
defer f.Close()
defer pprof.Lookup("heap").WriteTo(f, 0)
f, err = os.Create(cfg.MemProfile + ".allocs")
if err != nil {
btcdLog.Errorf("Unable to create mem profile: %v", err)
return err
}
defer f.Close()
defer pprof.Lookup("allocs").WriteTo(f, 0)
}
// Perform upgrades to btcd as new versions require it.
if err := doUpgrades(); err != nil {
btcdLog.Errorf("%v", err)

View file

@ -376,6 +376,9 @@
; Write CPU profile to the specified file.
; cpuprofile=
; Write memory profile to the specified file.
; memprofile=
; The port used to listen for HTTP profile requests. The profile server will
; be disabled if this option is not specified. The profile information can be
; accessed at http://localhost:<profileport>/debug/pprof once running.