diff --git a/btcd.go b/btcd.go index c7f292cbc9..1d9a1e5f6b 100644 --- a/btcd.go +++ b/btcd.go @@ -14,6 +14,7 @@ import ( "runtime" "runtime/debug" "runtime/pprof" + "runtime/trace" "github.com/btcsuite/btcd/blockchain/indexers" "github.com/btcsuite/btcd/database" @@ -100,6 +101,18 @@ func btcdMain(serverChan chan<- *server) error { defer runtime.GC() } + // Write execution trace if requested. + if cfg.TraceProfile != "" { + f, err := os.Create(cfg.TraceProfile) + if err != nil { + btcdLog.Errorf("Unable to create execution trace: %v", err) + return err + } + trace.Start(f) + defer f.Close() + defer trace.Stop() + } + // Perform upgrades to btcd as new versions require it. if err := doUpgrades(); err != nil { btcdLog.Errorf("%v", err) diff --git a/config.go b/config.go index 9bbce7f69a..2d2e9c98a6 100644 --- a/config.go +++ b/config.go @@ -114,6 +114,7 @@ type config struct { 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"` + TraceProfile string `long:"traceprofile" description:"Write execution trace 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"`