From 4b00174821c05fa0d8d82ab5c40cf2997920f7f7 Mon Sep 17 00:00:00 2001 From: joeycli Date: Fri, 6 Sep 2024 09:32:13 +0800 Subject: [PATCH 1/2] chore: add snapshot metrices --- core/state/snapshot/difflayer.go | 14 ++++++++++++++ core/state/snapshot/metrics.go | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/core/state/snapshot/difflayer.go b/core/state/snapshot/difflayer.go index eb9fa2ed1..f07eb776d 100644 --- a/core/state/snapshot/difflayer.go +++ b/core/state/snapshot/difflayer.go @@ -286,6 +286,13 @@ func (dl *diffLayer) Stale() bool { // Account directly retrieves the account associated with a particular hash in // the snapshot slim data format. func (dl *diffLayer) Account(hash common.Hash) (*types.SlimAccount, error) { + defer func(start time.Time) { + snapGetTimer.UpdateSince(start) + snapGetQPS.Mark(1) + snapGetAccountTimer.UpdateSince(start) + snapGetAccountQPS.Mark(1) + }(time.Now()) + data, err := dl.AccountRLP(hash) if err != nil { return nil, err @@ -394,6 +401,13 @@ func (dl *diffLayer) accountRLP(hash common.Hash, depth int) ([]byte, error) { // // Note the returned slot is not a copy, please don't modify it. func (dl *diffLayer) Storage(accountHash, storageHash common.Hash) ([]byte, error) { + defer func(start time.Time) { + snapGetTimer.UpdateSince(start) + snapGetQPS.Mark(1) + snapGetStorageTimer.UpdateSince(start) + snapGetStorageQPS.Mark(1) + }(time.Now()) + // Check the bloom filter first whether there's even a point in reaching into // all the maps in all the layers below dl.lock.RLock() diff --git a/core/state/snapshot/metrics.go b/core/state/snapshot/metrics.go index b2e884588..9a5c67b34 100644 --- a/core/state/snapshot/metrics.go +++ b/core/state/snapshot/metrics.go @@ -50,4 +50,12 @@ var ( snapStorageWriteCounter = metrics.NewRegisteredCounter("state/snapshot/generation/duration/storage/write", nil) // snapStorageCleanCounter measures time spent on deleting storages snapStorageCleanCounter = metrics.NewRegisteredCounter("state/snapshot/generation/duration/storage/clean", nil) + + snapGetTimer = metrics.NewRegisteredTimer("snap/get/time", nil) + snapGetQPS = metrics.NewRegisteredMeter("snap/get/qps", nil) + + snapGetAccountTimer = metrics.NewRegisteredTimer("snap/account/get/time", nil) + snapGetAccountQPS = metrics.NewRegisteredMeter("snap/account/get/qps", nil) + snapGetStorageTimer = metrics.NewRegisteredTimer("snap/storage/get/time", nil) + snapGetStorageQPS = metrics.NewRegisteredMeter("snap/storage/get/qps", nil) ) From d4879836c05c91c5fbf9cf8c6ceb087d788cf272 Mon Sep 17 00:00:00 2001 From: joeycli Date: Fri, 6 Sep 2024 14:06:12 +0800 Subject: [PATCH 2/2] chore: add statedb get metrices --- core/state/state_object.go | 8 ++++++++ core/state/statedb.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/core/state/state_object.go b/core/state/state_object.go index 3f2c8e978..8eda3beaa 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -223,6 +223,14 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash { return common.Hash{} } // If no live objects are available, attempt to use snapshots + + defer func(start time.Time) { + stateDBGetTimer.UpdateSince(start) + stateDBGetQPS.Mark(1) + stateDBGetStorageTimer.UpdateSince(start) + stateDBGetStorageQPS.Mark(1) + }(time.Now()) + var ( enc []byte err error diff --git a/core/state/statedb.go b/core/state/statedb.go index 0e1f76ac5..dab5d4f87 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -54,6 +54,16 @@ type revision struct { journalIndex int } +var ( + stateDBGetTimer = metrics.NewRegisteredTimer("statedb/get/time", nil) + stateDBGetQPS = metrics.NewRegisteredMeter("statedb/get/qps", nil) + + stateDBGetAccountTimer = metrics.NewRegisteredTimer("statedb/account/get/time", nil) + stateDBGetAccountQPS = metrics.NewRegisteredMeter("statedb/account/get/qps", nil) + stateDBGetStorageTimer = metrics.NewRegisteredTimer("statedb/storage/get/time", nil) + stateDBGetStorageQPS = metrics.NewRegisteredMeter("statedb/storage/get/qps", nil) +) + // StateDB structs within the ethereum protocol are used to store anything // within the merkle trie. StateDBs take care of caching and storing // nested states. It's the general query interface to retrieve: @@ -716,6 +726,14 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { if obj := s.stateObjects[addr]; obj != nil { return obj } + + defer func(start time.Time) { + stateDBGetTimer.UpdateSince(start) + stateDBGetQPS.Mark(1) + stateDBGetAccountTimer.UpdateSince(start) + stateDBGetAccountQPS.Mark(1) + }(time.Now()) + // If no live objects are available, attempt to use snapshots var data *types.StateAccount if s.snap != nil {