Skip to content

Commit 4f2b88a

Browse files
committed
cmd, core, eth: change the slowblock flag to time duration
1 parent 2d22f23 commit 4f2b88a

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
@@ -651,9 +651,10 @@ var (
651651
Usage: "Disables db compaction after import",
652652
Category: flags.LoggingCategory,
653653
}
654-
LogSlowBlockFlag = &cli.Uint64Flag{
654+
LogSlowBlockFlag = &cli.DurationFlag{
655655
Name: "debug.logslowblock",
656-
Usage: "The block execution speed threshold (Mgas/s) below which detailed statistics are logged",
656+
Usage: "Block execution time threshold beyond which detailed statistics will be logged (0 means disable)",
657+
Value: ethconfig.Defaults.SlowBlockThreshold,
657658
Category: flags.LoggingCategory,
658659
}
659660

@@ -1705,7 +1706,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17051706
cfg.LogNoHistory = true
17061707
}
17071708
if ctx.IsSet(LogSlowBlockFlag.Name) {
1708-
cfg.SlowBlockThreshold = ctx.Uint64(LogSlowBlockFlag.Name)
1709+
cfg.SlowBlockThreshold = ctx.Duration(LogSlowBlockFlag.Name)
17091710
}
17101711
if ctx.IsSet(LogExportCheckpointsFlag.Name) {
17111712
cfg.LogExportCheckpoints = ctx.String(LogExportCheckpointsFlag.Name)
@@ -2274,7 +2275,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
22742275
StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name),
22752276

22762277
// Configure the slow block statistic logger
2277-
SlowBlockThreshold: ctx.Uint64(LogSlowBlockFlag.Name),
2278+
SlowBlockThreshold: ctx.Duration(LogSlowBlockFlag.Name),
22782279
}
22792280
if options.ArchiveMode && !options.Preimages {
22802281
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
@@ -70,6 +70,7 @@ var Defaults = Config{
7070
RPCEVMTimeout: 5 * time.Second,
7171
GPO: FullNodeGPO,
7272
RPCTxFeeCap: 1, // 1 ether
73+
SlowBlockThreshold: time.Second * 2,
7374
}
7475

7576
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
@@ -118,7 +119,7 @@ type Config struct {
118119

119120
// SlowBlockThreshold is the block execution speed threshold (Mgas/s)
120121
// below which detailed statistics are logged.
121-
SlowBlockThreshold uint64 `toml:",omitempty"`
122+
SlowBlockThreshold time.Duration `toml:",omitempty"`
122123

123124
// Database options
124125
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)