Skip to content

Commit

Permalink
Merge pull request #1953 from kcalvinalvin/add-memory-profiling
Browse files Browse the repository at this point in the history
btcd: Add memory profiling flag
  • Loading branch information
guggero committed May 10, 2023
2 parents 52ede32 + d628705 commit 1287f1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions btcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func btcdMain(serverChan chan<- *server) error {
defer pprof.StopCPUProfile()
}

// Write mem profile if requested.
if cfg.MemoryProfile != "" {
f, err := os.Create(cfg.MemoryProfile)
if err != nil {
btcdLog.Errorf("Unable to create memory profile: %v", err)
return err
}
defer f.Close()
defer pprof.WriteHeapProfile(f)
defer runtime.GC()
}

// Perform upgrades to btcd as new versions require it.
if err := doUpgrades(); err != nil {
btcdLog.Errorf("%v", err)
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,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"`
MemoryProfile 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"`
Expand Down

0 comments on commit 1287f1e

Please sign in to comment.