diff --git a/core/types/mvstates.go b/core/types/mvstates.go index 300f1cf47..3957f5089 100644 --- a/core/types/mvstates.go +++ b/core/types/mvstates.go @@ -12,6 +12,9 @@ import ( "golang.org/x/exp/slices" ) +var DebugMVStateDuration time.Duration +var DebugMVStateCount int64 + type AccountState byte var ( @@ -610,6 +613,10 @@ func (s *MVStates) RecordAccountRead(addr common.Address, state AccountState) { if !s.asyncRunning || !s.recordingRead { return } + defer func(start time.Time) { + DebugMVStateDuration += time.Since(start) + DebugMVStateCount++ + }(time.Now()) if s.rwEventCacheIndex < len(s.rwEventCache) { s.rwEventCache[s.rwEventCacheIndex].Event = ReadAccRWEvent s.rwEventCache[s.rwEventCacheIndex].Addr = addr @@ -629,6 +636,10 @@ func (s *MVStates) RecordStorageRead(addr common.Address, slot common.Hash) { if !s.asyncRunning || !s.recordingRead { return } + defer func(start time.Time) { + DebugMVStateDuration += time.Since(start) + DebugMVStateCount++ + }(time.Now()) if s.rwEventCacheIndex < len(s.rwEventCache) { s.rwEventCache[s.rwEventCacheIndex].Event = ReadSlotRWEvent s.rwEventCache[s.rwEventCacheIndex].Addr = addr @@ -648,6 +659,10 @@ func (s *MVStates) RecordAccountWrite(addr common.Address, state AccountState) { if !s.asyncRunning || !s.recordingWrite { return } + defer func(start time.Time) { + DebugMVStateDuration += time.Since(start) + DebugMVStateCount++ + }(time.Now()) if s.rwEventCacheIndex < len(s.rwEventCache) { s.rwEventCache[s.rwEventCacheIndex].Event = WriteAccRWEvent s.rwEventCache[s.rwEventCacheIndex].Addr = addr @@ -667,6 +682,10 @@ func (s *MVStates) RecordStorageWrite(addr common.Address, slot common.Hash) { if !s.asyncRunning || !s.recordingWrite { return } + defer func(start time.Time) { + DebugMVStateDuration += time.Since(start) + DebugMVStateCount++ + }(time.Now()) if s.rwEventCacheIndex < len(s.rwEventCache) { s.rwEventCache[s.rwEventCacheIndex].Event = WriteSlotRWEvent s.rwEventCache[s.rwEventCacheIndex].Addr = addr @@ -686,6 +705,10 @@ func (s *MVStates) RecordCannotDelayGasFee() { if !s.asyncRunning || !s.recordingWrite { return } + defer func(start time.Time) { + DebugMVStateDuration += time.Since(start) + DebugMVStateCount++ + }(time.Now()) if s.rwEventCacheIndex < len(s.rwEventCache) { s.rwEventCache[s.rwEventCacheIndex].Event = CannotGasFeeDelayRWEvent s.rwEventCacheIndex++ diff --git a/miner/miner.go b/miner/miner.go index 09c5be664..001ab9dbe 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -64,9 +64,11 @@ var ( snapshotAccountReadTimer = metrics.NewRegisteredTimer("miner/snapshot/account/reads", nil) snapshotStorageReadTimer = metrics.NewRegisteredTimer("miner/snapshot/storage/reads", nil) - waitPayloadTimer = metrics.NewRegisteredTimer("miner/wait/payload", nil) - txDAGGenerateTimer = metrics.NewRegisteredTimer("miner/txdag/gen", nil) - txDAGAppendTimer = metrics.NewRegisteredTimer("miner/txdag/appendtx", nil) + waitPayloadTimer = metrics.NewRegisteredTimer("miner/wait/payload", nil) + txDAGGenerateTimer = metrics.NewRegisteredTimer("miner/txdag/gen", nil) + txDAGAppendTimer = metrics.NewRegisteredTimer("miner/txdag/appendtx", nil) + txDAGRecordCostTimer = metrics.NewRegisteredTimer("miner/txdag/record/cost", nil) + txDAGRecordCounter = metrics.NewRegisteredCounter("miner/txdag/record/count", nil) isBuildBlockInterruptCounter = metrics.NewRegisteredCounter("miner/build/interrupt", nil) ) diff --git a/miner/worker.go b/miner/worker.go index 852c0eb78..9fc58bad3 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1352,8 +1352,12 @@ func (w *worker) estimateGasForTxDAG(env *environment) uint64 { func (w *worker) generateWork(genParams *generateParams) *newPayloadResult { // TODO delete after debug performance metrics core.DebugInnerExecutionDuration = 0 + types.DebugMVStateDuration = 0 + types.DebugMVStateCount = 0 defer func() { core.DebugInnerExecutionDuration = 0 + types.DebugMVStateDuration = 0 + types.DebugMVStateCount = 0 }() work, err := w.prepareWork(genParams) @@ -1483,6 +1487,8 @@ func (w *worker) generateWork(genParams *generateParams) *newPayloadResult { accountHashTimer.Update(work.state.AccountHashes) // Account hashes are complete(in FinalizeAndAssemble) storageHashTimer.Update(work.state.StorageHashes) // Storage hashes are complete(in FinalizeAndAssemble) txDAGGenerateTimer.Update(work.state.TxDAGGenerate) + txDAGRecordCostTimer.Update(types.DebugMVStateDuration) + txDAGRecordCounter.Inc(types.DebugMVStateCount) innerExecutionTimer.Update(core.DebugInnerExecutionDuration)