Skip to content

Commit

Permalink
main: add flag to write execution traces
Browse files Browse the repository at this point in the history
Execution traces are part of the go runtime tooling and is useful to
check what is slowing down the ibd.  For example, a slow ibd because of
slow block downloads from peers won't show up on cpu profiling but will
on a trace.
  • Loading branch information
kcalvinalvin committed Aug 6, 2024
1 parent b161cd6 commit 713536e
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:"trace" 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 713536e

Please sign in to comment.