Skip to content

Commit 10ef9cc

Browse files
committed
main: add flag to write execution traces
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.
1 parent b161cd6 commit 10ef9cc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

btcd.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"runtime/debug"
1616
"runtime/pprof"
17+
"runtime/trace"
1718

1819
"github.com/btcsuite/btcd/blockchain/indexers"
1920
"github.com/btcsuite/btcd/database"
@@ -100,6 +101,18 @@ func btcdMain(serverChan chan<- *server) error {
100101
defer runtime.GC()
101102
}
102103

104+
// Write execution trace if requested.
105+
if cfg.TraceProfile != "" {
106+
f, err := os.Create(cfg.TraceProfile)
107+
if err != nil {
108+
btcdLog.Errorf("Unable to create execution trace: %v", err)
109+
return err
110+
}
111+
trace.Start(f)
112+
defer f.Close()
113+
defer trace.Stop()
114+
}
115+
103116
// Perform upgrades to btcd as new versions require it.
104117
if err := doUpgrades(); err != nil {
105118
btcdLog.Errorf("%v", err)

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ type config struct {
114114
ConnectPeers []string `long:"connect" description:"Connect only to the specified peers at startup"`
115115
CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"`
116116
MemoryProfile string `long:"memprofile" description:"Write memory profile to the specified file"`
117+
TraceProfile string `long:"traceprofile" description:"Write execution trace to the specified file"`
117118
DataDir string `short:"b" long:"datadir" description:"Directory to store data"`
118119
DbType string `long:"dbtype" description:"Database backend to use for the Block Chain"`
119120
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"`

0 commit comments

Comments
 (0)