mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-13 19:46:39 +00:00
core/state: export statistics to metrics (#33254)
This PR exposes the state size statistics to the metrics, making them easier to demonstrate. Note that the contract code included in the metrics is not de-duplicated, so the reported size will appear larger than the actual storage footprint.
This commit is contained in:
parent
212967d0e1
commit
d3679c2f2e
1 changed files with 34 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/triedb"
|
"github.com/ethereum/go-ethereum/triedb"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
@ -48,6 +49,21 @@ var (
|
||||||
codeKeySize = int64(len(rawdb.CodePrefix) + common.HashLength)
|
codeKeySize = int64(len(rawdb.CodePrefix) + common.HashLength)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// State size metrics
|
||||||
|
var (
|
||||||
|
stateSizeChainHeightGauge = metrics.NewRegisteredGauge("state/height", nil)
|
||||||
|
stateSizeAccountsCountGauge = metrics.NewRegisteredGauge("state/accounts/count", nil)
|
||||||
|
stateSizeAccountsBytesGauge = metrics.NewRegisteredGauge("state/accounts/bytes", nil)
|
||||||
|
stateSizeStoragesCountGauge = metrics.NewRegisteredGauge("state/storages/count", nil)
|
||||||
|
stateSizeStoragesBytesGauge = metrics.NewRegisteredGauge("state/storages/bytes", nil)
|
||||||
|
stateSizeAccountTrieNodesCountGauge = metrics.NewRegisteredGauge("state/trienodes/account/count", nil)
|
||||||
|
stateSizeAccountTrieNodesBytesGauge = metrics.NewRegisteredGauge("state/trienodes/account/bytes", nil)
|
||||||
|
stateSizeStorageTrieNodesCountGauge = metrics.NewRegisteredGauge("state/trienodes/storage/count", nil)
|
||||||
|
stateSizeStorageTrieNodesBytesGauge = metrics.NewRegisteredGauge("state/trienodes/storage/bytes", nil)
|
||||||
|
stateSizeContractsCountGauge = metrics.NewRegisteredGauge("state/contracts/count", nil)
|
||||||
|
stateSizeContractsBytesGauge = metrics.NewRegisteredGauge("state/contracts/bytes", nil)
|
||||||
|
)
|
||||||
|
|
||||||
// SizeStats represents either the current state size statistics or the size
|
// SizeStats represents either the current state size statistics or the size
|
||||||
// differences resulting from a state transition.
|
// differences resulting from a state transition.
|
||||||
type SizeStats struct {
|
type SizeStats struct {
|
||||||
|
|
@ -76,6 +92,20 @@ func (s SizeStats) String() string {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s SizeStats) publish() {
|
||||||
|
stateSizeChainHeightGauge.Update(int64(s.BlockNumber))
|
||||||
|
stateSizeAccountsCountGauge.Update(s.Accounts)
|
||||||
|
stateSizeAccountsBytesGauge.Update(s.AccountBytes)
|
||||||
|
stateSizeStoragesCountGauge.Update(s.Storages)
|
||||||
|
stateSizeStoragesBytesGauge.Update(s.StorageBytes)
|
||||||
|
stateSizeAccountTrieNodesCountGauge.Update(s.AccountTrienodes)
|
||||||
|
stateSizeAccountTrieNodesBytesGauge.Update(s.AccountTrienodeBytes)
|
||||||
|
stateSizeStorageTrieNodesCountGauge.Update(s.StorageTrienodes)
|
||||||
|
stateSizeStorageTrieNodesBytesGauge.Update(s.StorageTrienodeBytes)
|
||||||
|
stateSizeContractsCountGauge.Update(s.ContractCodes)
|
||||||
|
stateSizeContractsBytesGauge.Update(s.ContractCodeBytes)
|
||||||
|
}
|
||||||
|
|
||||||
// add applies the given state diffs and produces a new version of the statistics.
|
// add applies the given state diffs and produces a new version of the statistics.
|
||||||
func (s SizeStats) add(diff SizeStats) SizeStats {
|
func (s SizeStats) add(diff SizeStats) SizeStats {
|
||||||
s.StateRoot = diff.StateRoot
|
s.StateRoot = diff.StateRoot
|
||||||
|
|
@ -309,6 +339,10 @@ func (t *SizeTracker) run() {
|
||||||
stats[u.root] = stat
|
stats[u.root] = stat
|
||||||
last = u.root
|
last = u.root
|
||||||
|
|
||||||
|
// Publish statistics to metric system
|
||||||
|
stat.publish()
|
||||||
|
|
||||||
|
// Evict the stale statistics
|
||||||
heap.Push(&h, stats[u.root])
|
heap.Push(&h, stats[u.root])
|
||||||
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
|
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
|
||||||
delete(stats, h[0].StateRoot)
|
delete(stats, h[0].StateRoot)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue