Skip to content

Commit

Permalink
add metrics for MVStates
Browse files Browse the repository at this point in the history
  • Loading branch information
welkin22 committed Nov 15, 2024
1 parent 186da7b commit cc5d775
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
23 changes: 23 additions & 0 deletions core/types/mvstates.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
"golang.org/x/exp/slices"
)

var DebugMVStateDuration time.Duration
var DebugMVStateCount int64

type AccountState byte

var (
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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++
Expand Down
8 changes: 5 additions & 3 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down
6 changes: 6 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit cc5d775

Please sign in to comment.