From 0fc0b407f72987ef03cc43763a254d038f05bf8b Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Fri, 25 Apr 2025 11:29:45 +0200 Subject: [PATCH] Expose IO measurements from statedb --- core/state/statedb.go | 14 ++++++++++++++ core/state/statedb_hooked.go | 4 ++++ core/tracing/hooks.go | 16 ++++++++++++++++ core/vm/interface.go | 4 ++++ 4 files changed, 38 insertions(+) diff --git a/core/state/statedb.go b/core/state/statedb.go index e3f5b9e1a0..ac04c87fb8 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1434,3 +1434,17 @@ func (s *StateDB) Witness() *stateless.Witness { func (s *StateDB) AccessEvents() *AccessEvents { return s.accessEvents } + +func (s *StateDB) GetAccumulatedIOMeasurements() *tracing.IOMeasurements { + return &tracing.IOMeasurements{ + AccountReads: s.AccountReads, + AccountHashes: s.AccountHashes, + AccountUpdates: s.AccountUpdates, + AccountCommits: s.AccountCommits, + StorageReads: s.StorageReads, + StorageUpdates: s.StorageUpdates, + StorageCommits: s.StorageCommits, + SnapshotCommits: s.SnapshotCommits, + TrieDBCommits: s.TrieDBCommits, + } +} diff --git a/core/state/statedb_hooked.go b/core/state/statedb_hooked.go index a2fdfe9a21..feaa51dd2c 100644 --- a/core/state/statedb_hooked.go +++ b/core/state/statedb_hooked.go @@ -276,3 +276,7 @@ func (s *hookedStateDB) Finalise(deleteEmptyObjects bool) { } } } + +func (s *hookedStateDB) GetAccumulatedIOMeasurements() *tracing.IOMeasurements { + return s.inner.GetAccumulatedIOMeasurements() +} diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 0485f7a3eb..f550b3f807 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -26,6 +26,7 @@ package tracing import ( "math/big" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -55,6 +56,21 @@ type StateDB interface { GetTransientState(common.Address, common.Hash) common.Hash Exist(common.Address) bool GetRefund() uint64 + GetAccumulatedIOMeasurements() *IOMeasurements +} + +// IOMeasurements is a struct that contains the measurements of +// the I/O operations performed by the statedb. +type IOMeasurements struct { + AccountReads time.Duration + AccountHashes time.Duration + AccountUpdates time.Duration + AccountCommits time.Duration + StorageReads time.Duration + StorageUpdates time.Duration + StorageCommits time.Duration + SnapshotCommits time.Duration + TrieDBCommits time.Duration } // VMContext provides the context for the EVM execution. diff --git a/core/vm/interface.go b/core/vm/interface.go index 57f35cb249..2451f8e29e 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -101,4 +101,8 @@ type StateDB interface { // Finalise must be invoked at the end of a transaction Finalise(bool) + + // GetAccumulatedGasMeasurements returns measurements of IO operations that have + // been accumulated since the execution of the block started. + GetAccumulatedIOMeasurements() *tracing.IOMeasurements }