Skip to content

Commit

Permalink
core: fix metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
rjl493456442 committed Jul 18, 2024
1 parent 783fef1 commit 81377ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
24 changes: 12 additions & 12 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1947,18 +1947,6 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
}
proctime := time.Since(start) // processing + validation

// Update the metrics touched during block processing and validation
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing)
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing)
accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation)
storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation)
accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation)
triehash := statedb.AccountHashes // The time spent on tries hashing
trieUpdate := statedb.AccountUpdates + statedb.StorageUpdates // The time spent on tries update
trieRead := statedb.AccountReads + statedb.StorageReads // The time spent on account read and storage read
blockExecutionTimer.Update(ptime - trieRead) // The time spent on EVM processing
blockValidationTimer.Update(vtime - (triehash + trieUpdate)) // The time spent on block validation

// Write the block to the chain and get the status.
var (
wstart = time.Now()
Expand All @@ -1973,6 +1961,18 @@ func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, s
if err != nil {
return nil, err
}
// Update the metrics touched during block processing and validation
accountReadTimer.Update(statedb.AccountReads) // Account reads are complete(in processing)
storageReadTimer.Update(statedb.StorageReads) // Storage reads are complete(in processing)
accountUpdateTimer.Update(statedb.AccountUpdates) // Account updates are complete(in validation)
storageUpdateTimer.Update(statedb.StorageUpdates) // Storage updates are complete(in validation)
accountHashTimer.Update(statedb.AccountHashes) // Account hashes are complete(in validation)
triehash := statedb.AccountHashes // The time spent on account trie hashing
trieUpdate := statedb.AccountUpdates + statedb.StorageUpdates // The time spent on account trie update + storage tries update and hashing
trieRead := statedb.AccountReads + statedb.StorageReads // The time spent on account read and storage read
blockExecutionTimer.Update(ptime - trieRead) // The time spent on EVM processing
blockValidationTimer.Update(vtime - (triehash + trieUpdate)) // The time spent on block validation

// Update the metrics touched during block commit
accountCommitTimer.Update(statedb.AccountCommits) // Account commits are complete, we can mark them
storageCommitTimer.Update(statedb.StorageCommits) // Storage commits are complete, we can mark them
Expand Down
5 changes: 0 additions & 5 deletions core/state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,4 @@ var (
slotDeletionTimer = metrics.NewRegisteredResettingTimer("state/delete/storage/timer", nil)
slotDeletionCount = metrics.NewRegisteredMeter("state/delete/storage/slot", nil)
slotDeletionSize = metrics.NewRegisteredMeter("state/delete/storage/size", nil)

trieAccountReadTimer = metrics.NewRegisteredResettingTimer("state/trie/account/reads", nil)
trieStorageReadTimer = metrics.NewRegisteredResettingTimer("state/trie/storage/reads", nil)
snapshotAccountReadTimer = metrics.NewRegisteredResettingTimer("state/snapshot/account/reads", nil)
snapshotStorageReadTimer = metrics.NewRegisteredResettingTimer("state/snapshot/storage/reads", nil)
)
4 changes: 0 additions & 4 deletions core/state/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func newStateReader(root common.Hash, snaps *snapshot.Tree) (*stateReader, error
func (r *stateReader) Account(addr common.Address) (*types.StateAccount, error) {
defer func(start time.Time) {
r.accountTime += time.Since(start)
snapshotAccountReadTimer.UpdateSince(start)
}(time.Now())

ret, err := r.snap.Account(crypto.HashData(r.buff, addr.Bytes()))
Expand Down Expand Up @@ -123,7 +122,6 @@ func (r *stateReader) Account(addr common.Address) (*types.StateAccount, error)
func (r *stateReader) Storage(addr common.Address, key common.Hash) (common.Hash, error) {
defer func(start time.Time) {
r.storageTime += time.Since(start)
snapshotStorageReadTimer.UpdateSince(start)
}(time.Now())

addrHash := crypto.HashData(r.buff, addr.Bytes())
Expand Down Expand Up @@ -207,7 +205,6 @@ func newTrieReader(root common.Hash, db *triedb.Database, cache *utils.PointCach
func (r *trieReader) Account(addr common.Address) (*types.StateAccount, error) {
defer func(start time.Time) {
r.accountTime += time.Since(start)
trieAccountReadTimer.UpdateSince(start)
}(time.Now())

account, err := r.mainTrie.GetAccount(addr)
Expand All @@ -230,7 +227,6 @@ func (r *trieReader) Account(addr common.Address) (*types.StateAccount, error) {
func (r *trieReader) Storage(addr common.Address, key common.Hash) (common.Hash, error) {
defer func(start time.Time) {
r.storageTime += time.Since(start)
trieStorageReadTimer.UpdateSince(start)
}(time.Now())

var (
Expand Down
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1310,7 +1310,7 @@ func (s *StateDB) commitAndFlush(block uint64, deleteEmptyObjects bool) (*stateU
// Submit the statistics of reader to metric system and reset it with new root
aTime, sTime := s.reader.Stats()
s.AccountReads += aTime
s.AccountReads += sTime
s.StorageReads += sTime

s.reader, _ = s.db.Reader(s.originalRoot)
return ret, err
Expand Down

0 comments on commit 81377ad

Please sign in to comment.