From 141a40e2469f35f9790b04aea635439da00ce2cc Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Fri, 20 May 2022 11:12:05 -0400 Subject: [PATCH 1/2] Add --memprofile option. Add memprofile to sample config. --- config.go | 1 + lbcd.go | 19 +++++++++++++++++++ sample-lbcd.conf | 3 +++ 3 files changed, 23 insertions(+) diff --git a/config.go b/config.go index fe77a8180e..aee85c3fed 100644 --- a/config.go +++ b/config.go @@ -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 =,=,... to set the log level for individual subsystems -- Use show to list available subsystems"` diff --git a/lbcd.go b/lbcd.go index 1110eeaba1..0bc6841d47 100644 --- a/lbcd.go +++ b/lbcd.go @@ -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) diff --git a/sample-lbcd.conf b/sample-lbcd.conf index 2a84c79729..f2c0b8c7ad 100644 --- a/sample-lbcd.conf +++ b/sample-lbcd.conf @@ -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:/debug/pprof once running. From 3772b1ef1d7625b6f71f107e00d47f89136e5071 Mon Sep 17 00:00:00 2001 From: Jonathan Moody <103143855+moodyjon@users.noreply.github.com> Date: Fri, 3 Jun 2022 14:56:27 -0400 Subject: [PATCH 2/2] Add --memprofile to doc.go. --- doc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/doc.go b/doc.go index ee4a9405f4..84a96ea82b 100644 --- a/doc.go +++ b/doc.go @@ -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