Skip to content

Commit

Permalink
Merge pull request #2223 from kcalvinalvin/2024-08-06-execution-trace…
Browse files Browse the repository at this point in the history
…-flag

main: add flag to write execution traces
  • Loading branch information
Roasbeef authored Nov 20, 2024
2 parents 684d64a + 10ef9cc commit e9d95ee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions btcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"runtime"
"runtime/debug"
"runtime/pprof"
"runtime/trace"

"github.com/btcsuite/btcd/blockchain/indexers"
"github.com/btcsuite/btcd/database"
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems -- Use show to list available subsystems"`
Expand Down

0 comments on commit e9d95ee

Please sign in to comment.