diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 4cac9cd8bc..8f2d98195c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -667,9 +667,10 @@ var ( Usage: "Disables db compaction after import", Category: flags.LoggingCategory, } - LogSlowBlockFlag = &cli.Uint64Flag{ + LogSlowBlockFlag = &cli.DurationFlag{ Name: "debug.logslowblock", - Usage: "The block execution speed threshold (Mgas/s) below which detailed statistics are logged", + Usage: "Block execution time threshold beyond which detailed statistics will be logged (0 means disable)", + Value: ethconfig.Defaults.SlowBlockThreshold, Category: flags.LoggingCategory, } @@ -1716,7 +1717,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { cfg.LogNoHistory = true } if ctx.IsSet(LogSlowBlockFlag.Name) { - cfg.SlowBlockThreshold = ctx.Uint64(LogSlowBlockFlag.Name) + cfg.SlowBlockThreshold = ctx.Duration(LogSlowBlockFlag.Name) } if ctx.IsSet(LogExportCheckpointsFlag.Name) { cfg.LogExportCheckpoints = ctx.String(LogExportCheckpointsFlag.Name) @@ -2303,7 +2304,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name), // Configure the slow block statistic logger - SlowBlockThreshold: ctx.Uint64(LogSlowBlockFlag.Name), + SlowBlockThreshold: ctx.Duration(LogSlowBlockFlag.Name), } if options.ArchiveMode && !options.Preimages { options.Preimages = true diff --git a/core/blockchain.go b/core/blockchain.go index b9ffd8283e..7fe39e2b65 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -199,9 +199,9 @@ type BlockChainConfig struct { // StateSizeTracking indicates whether the state size tracking is enabled. StateSizeTracking bool - // SlowBlockThreshold is the block execution speed threshold (Mgas/s) - // below which detailed statistics are logged. - SlowBlockThreshold uint64 + // SlowBlockThreshold is the block execution time threshold beyond which + // detailed statistics will be logged. + SlowBlockThreshold time.Duration } // DefaultConfig returns the default config. @@ -341,8 +341,8 @@ type BlockChain struct { logger *tracing.Hooks stateSizer *state.SizeTracker // State size tracking - lastForkReadyAlert time.Time // Last time there was a fork readiness print out - slowBlockThreshold uint64 // Block execution speed threshold (Mgas/s) below which detailed statistics are logged + lastForkReadyAlert time.Time // Last time there was a fork readiness print out + slowBlockThreshold time.Duration // Block execution time threshold beyond which detailed statistics will be logged } // NewBlockChain returns a fully initialised block chain using information diff --git a/core/blockchain_stats.go b/core/blockchain_stats.go index 58726895e5..0cebebc20a 100644 --- a/core/blockchain_stats.go +++ b/core/blockchain_stats.go @@ -99,16 +99,16 @@ func (s *ExecuteStats) reportMetrics() { } // logSlow prints the detailed execution statistics if the block is regarded as slow. -func (s *ExecuteStats) logSlow(block *types.Block, slowBlockThreshold uint64) { - if slowBlockThreshold == 0 || s.MgasPerSecond == 0 { +func (s *ExecuteStats) logSlow(block *types.Block, slowBlockThreshold time.Duration) { + if slowBlockThreshold == 0 { return } - if s.MgasPerSecond > float64(slowBlockThreshold) { + if s.TotalTime < slowBlockThreshold { return } msg := fmt.Sprintf(` ########## SLOW BLOCK ######### -Block: %v (%#x) txs: %d, mgasps: %.2f +Block: %v (%#x) txs: %d, mgasps: %.2f, elapsed: %v EVM execution: %v Validation: %v @@ -118,18 +118,17 @@ Account hash: %v Storage hash: %v DB commit: %v Block write: %v -Total: %v %s ############################## -`, block.Number(), block.Hash(), len(block.Transactions()), s.MgasPerSecond, +`, block.Number(), block.Hash(), len(block.Transactions()), s.MgasPerSecond, common.PrettyDuration(s.TotalTime), common.PrettyDuration(s.Execution), common.PrettyDuration(s.Validation+s.CrossValidation), common.PrettyDuration(s.AccountReads), s.AccountLoaded, common.PrettyDuration(s.StorageReads), s.StorageLoaded, common.PrettyDuration(s.AccountHashes+s.AccountCommits+s.AccountUpdates), common.PrettyDuration(s.StorageCommits+s.StorageUpdates), common.PrettyDuration(s.TrieDBCommit+s.SnapshotCommit), common.PrettyDuration(s.BlockWrite), - common.PrettyDuration(s.TotalTime), s.StateReadCacheStats) + s.StateReadCacheStats) for _, line := range strings.Split(msg, "\n") { if line == "" { continue diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 2c916aadde..d6ed2c2576 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -72,6 +72,7 @@ var Defaults = Config{ RPCTxFeeCap: 1, // 1 ether TxSyncDefaultTimeout: 20 * time.Second, TxSyncMaxTimeout: 1 * time.Minute, + SlowBlockThreshold: time.Second * 2, } //go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go @@ -120,7 +121,7 @@ type Config struct { // SlowBlockThreshold is the block execution speed threshold (Mgas/s) // below which detailed statistics are logged. - SlowBlockThreshold uint64 `toml:",omitempty"` + SlowBlockThreshold time.Duration `toml:",omitempty"` // Database options SkipBcVersionCheck bool `toml:"-"` diff --git a/eth/ethconfig/gen_config.go b/eth/ethconfig/gen_config.go index db4cd740c2..97c5db3ecd 100644 --- a/eth/ethconfig/gen_config.go +++ b/eth/ethconfig/gen_config.go @@ -33,7 +33,7 @@ func (c Config) MarshalTOML() (interface{}, error) { StateHistory uint64 `toml:",omitempty"` StateScheme string `toml:",omitempty"` RequiredBlocks map[uint64]common.Hash `toml:"-"` - SlowBlockThreshold uint64 `toml:",omitempty"` + SlowBlockThreshold time.Duration `toml:",omitempty"` SkipBcVersionCheck bool `toml:"-"` DatabaseHandles int `toml:"-"` DatabaseCache int @@ -137,7 +137,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { StateHistory *uint64 `toml:",omitempty"` StateScheme *string `toml:",omitempty"` RequiredBlocks map[uint64]common.Hash `toml:"-"` - SlowBlockThreshold *uint64 `toml:",omitempty"` + SlowBlockThreshold *time.Duration `toml:",omitempty"` SkipBcVersionCheck *bool `toml:"-"` DatabaseHandles *int `toml:"-"` DatabaseCache *int