From c1dabeac6ee78c1df13a02f9430d6fbc8de06bd7 Mon Sep 17 00:00:00 2001 From: 0xbundler <124862913+0xbundler@users.noreply.github.com> Date: Fri, 10 Nov 2023 00:10:09 +0800 Subject: [PATCH] state/stateobject: add read/write/access meters; --- core/state/state_object.go | 14 ++++++++++++++ core/state/statedb.go | 3 +++ 2 files changed, 17 insertions(+) diff --git a/core/state/state_object.go b/core/state/state_object.go index 67ef887d58..ac5a3aa32d 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -431,6 +431,8 @@ func (s *stateObject) updateTrie() (Trie, error) { s.db.setError(fmt.Errorf("state object update trie getTrie err, contract: %v, err: %v", s.address, err)) return nil, err } + storageReadMeter.Mark(int64(len(s.originStorage))) + storageWriteMeter.Mark(int64(len(s.pendingStorage))) // Insert all the pending updates into the trie usedStorage := make([][]byte, 0, len(s.pendingStorage)) dirtyStorage := make(map[common.Hash][]byte) @@ -448,16 +450,28 @@ func (s *stateObject) updateTrie() (Trie, error) { } if s.db.EnableExpire() { + var accessCount int64 // append more access slots to update in db for key := range s.pendingAccessedState { if _, ok := dirtyStorage[key]; ok { continue } + accessCount++ // it must hit in cache value := s.GetState(key) dirtyStorage[key] = common.TrimLeftZeroes(value[:]) //log.Debug("updateTrie access state", "contract", s.address, "key", key, "epoch", s.db.Epoch()) } + for key := range s.pendingFutureReviveState { + if _, ok := dirtyStorage[key]; ok { + continue + } + if _, ok := s.pendingAccessedState[key]; ok { + continue + } + accessCount++ + } + storageAccessMeter.Mark(accessCount) } var wg sync.WaitGroup diff --git a/core/state/statedb.go b/core/state/statedb.go index 24afa2256b..85a4415bf9 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -53,6 +53,9 @@ var ( getCommittedStorageExpiredLocalReviveMeter = metrics.NewRegisteredMeter("state/contract/committed/expired/localrevive", nil) getCommittedStorageUnexpiredMeter = metrics.NewRegisteredMeter("state/contract/committed/unexpired", nil) getCommittedStorageRemoteMeter = metrics.NewRegisteredMeter("state/contract/committed/remote", nil) + storageReadMeter = metrics.NewRegisteredMeter("state/contract/state/read", nil) + storageWriteMeter = metrics.NewRegisteredMeter("state/contract/state/write", nil) + storageAccessMeter = metrics.NewRegisteredMeter("state/contract/state/access", nil) ) type revision struct {