Skip to content

Commit 5e60382

Browse files
committed
cmd, core, eth: change the slowblock flag to time duration
1 parent df53e28 commit 5e60382

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

cmd/utils/flags.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,10 @@ var (
667667
Usage: "Disables db compaction after import",
668668
Category: flags.LoggingCategory,
669669
}
670-
LogSlowBlockFlag = &cli.Uint64Flag{
670+
LogSlowBlockFlag = &cli.DurationFlag{
671671
Name: "debug.logslowblock",
672-
Usage: "The block execution speed threshold (Mgas/s) below which detailed statistics are logged",
672+
Usage: "Block execution time threshold beyond which detailed statistics will be logged (0 means disable)",
673+
Value: ethconfig.Defaults.SlowBlockThreshold,
673674
Category: flags.LoggingCategory,
674675
}
675676

@@ -1716,7 +1717,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17161717
cfg.LogNoHistory = true
17171718
}
17181719
if ctx.IsSet(LogSlowBlockFlag.Name) {
1719-
cfg.SlowBlockThreshold = ctx.Uint64(LogSlowBlockFlag.Name)
1720+
cfg.SlowBlockThreshold = ctx.Duration(LogSlowBlockFlag.Name)
17201721
}
17211722
if ctx.IsSet(LogExportCheckpointsFlag.Name) {
17221723
cfg.LogExportCheckpoints = ctx.String(LogExportCheckpointsFlag.Name)
@@ -2303,7 +2304,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
23032304
StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
23042305

23052306
// Configure the slow block statistic logger
2306-
SlowBlockThreshold: ctx.Uint64(LogSlowBlockFlag.Name),
2307+
SlowBlockThreshold: ctx.Duration(LogSlowBlockFlag.Name),
23072308
}
23082309
if options.ArchiveMode && !options.Preimages {
23092310
options.Preimages = true

core/blockchain.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ type BlockChainConfig struct {
199199
// StateSizeTracking indicates whether the state size tracking is enabled.
200200
StateSizeTracking bool
201201

202-
// SlowBlockThreshold is the block execution speed threshold (Mgas/s)
203-
// below which detailed statistics are logged.
204-
SlowBlockThreshold uint64
202+
// SlowBlockThreshold is the block execution time threshold beyond which
203+
// detailed statistics will be logged.
204+
SlowBlockThreshold time.Duration
205205
}
206206

207207
// DefaultConfig returns the default config.
@@ -341,8 +341,8 @@ type BlockChain struct {
341341
logger *tracing.Hooks
342342
stateSizer *state.SizeTracker // State size tracking
343343

344-
lastForkReadyAlert time.Time // Last time there was a fork readiness print out
345-
slowBlockThreshold uint64 // Block execution speed threshold (Mgas/s) below which detailed statistics are logged
344+
lastForkReadyAlert time.Time // Last time there was a fork readiness print out
345+
slowBlockThreshold time.Duration // Block execution time threshold beyond which detailed statistics will be logged
346346
}
347347

348348
// NewBlockChain returns a fully initialised block chain using information

core/blockchain_stats.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ func (s *ExecuteStats) reportMetrics() {
9999
}
100100

101101
// logSlow prints the detailed execution statistics if the block is regarded as slow.
102-
func (s *ExecuteStats) logSlow(block *types.Block, slowBlockThreshold uint64) {
103-
if slowBlockThreshold == 0 || s.MgasPerSecond == 0 {
102+
func (s *ExecuteStats) logSlow(block *types.Block, slowBlockThreshold time.Duration) {
103+
if slowBlockThreshold == 0 {
104104
return
105105
}
106-
if s.MgasPerSecond > float64(slowBlockThreshold) {
106+
if s.TotalTime < slowBlockThreshold {
107107
return
108108
}
109109
msg := fmt.Sprintf(`
110110
########## SLOW BLOCK #########
111-
Block: %v (%#x) txs: %d, mgasps: %.2f
111+
Block: %v (%#x) txs: %d, mgasps: %.2f, elapsed: %v
112112
113113
EVM execution: %v
114114
Validation: %v
@@ -118,18 +118,17 @@ Account hash: %v
118118
Storage hash: %v
119119
DB commit: %v
120120
Block write: %v
121-
Total: %v
122121
123122
%s
124123
##############################
125-
`, block.Number(), block.Hash(), len(block.Transactions()), s.MgasPerSecond,
124+
`, block.Number(), block.Hash(), len(block.Transactions()), s.MgasPerSecond, common.PrettyDuration(s.TotalTime),
126125
common.PrettyDuration(s.Execution), common.PrettyDuration(s.Validation+s.CrossValidation),
127126
common.PrettyDuration(s.AccountReads), s.AccountLoaded,
128127
common.PrettyDuration(s.StorageReads), s.StorageLoaded,
129128
common.PrettyDuration(s.AccountHashes+s.AccountCommits+s.AccountUpdates),
130129
common.PrettyDuration(s.StorageCommits+s.StorageUpdates),
131130
common.PrettyDuration(s.TrieDBCommit+s.SnapshotCommit), common.PrettyDuration(s.BlockWrite),
132-
common.PrettyDuration(s.TotalTime), s.StateReadCacheStats)
131+
s.StateReadCacheStats)
133132
for _, line := range strings.Split(msg, "\n") {
134133
if line == "" {
135134
continue

eth/ethconfig/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ var Defaults = Config{
7272
RPCTxFeeCap: 1, // 1 ether
7373
TxSyncDefaultTimeout: 20 * time.Second,
7474
TxSyncMaxTimeout: 1 * time.Minute,
75+
SlowBlockThreshold: time.Second * 2,
7576
}
7677

7778
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
@@ -120,7 +121,7 @@ type Config struct {
120121

121122
// SlowBlockThreshold is the block execution speed threshold (Mgas/s)
122123
// below which detailed statistics are logged.
123-
SlowBlockThreshold uint64 `toml:",omitempty"`
124+
SlowBlockThreshold time.Duration `toml:",omitempty"`
124125

125126
// Database options
126127
SkipBcVersionCheck bool `toml:"-"`

eth/ethconfig/gen_config.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)