mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
core/state: export statistics to metrics
This commit is contained in:
parent
ca91254259
commit
4bfa8d34a7
1 changed files with 37 additions and 0 deletions
|
|
@ -31,6 +31,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
"github.com/ethereum/go-ethereum/triedb"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
|
@ -48,6 +49,21 @@ var (
|
|||
codeKeySize = int64(len(rawdb.CodePrefix) + common.HashLength)
|
||||
)
|
||||
|
||||
// State size metrics
|
||||
var (
|
||||
stateSizeMetadataGaugeInfo = metrics.NewRegisteredGaugeInfo("state/metadata", 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
|
||||
// differences resulting from a state transition.
|
||||
type SizeStats struct {
|
||||
|
|
@ -76,6 +92,23 @@ func (s SizeStats) String() string {
|
|||
)
|
||||
}
|
||||
|
||||
func (s SizeStats) publish() {
|
||||
stateSizeMetadataGaugeInfo.Update(metrics.GaugeInfoValue{
|
||||
"number": fmt.Sprintf("%d", s.BlockNumber),
|
||||
"hash": s.StateRoot.Hex(),
|
||||
})
|
||||
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.
|
||||
func (s SizeStats) add(diff SizeStats) SizeStats {
|
||||
s.StateRoot = diff.StateRoot
|
||||
|
|
@ -309,6 +342,10 @@ func (t *SizeTracker) run() {
|
|||
stats[u.root] = stat
|
||||
last = u.root
|
||||
|
||||
// Publish statistics to metric system
|
||||
stat.publish()
|
||||
|
||||
// Evict the stale statistics
|
||||
heap.Push(&h, stats[u.root])
|
||||
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
|
||||
delete(stats, h[0].StateRoot)
|
||||
|
|
|
|||
Loading…
Reference in a new issue