diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index f0f6296433..ec6dba3fa6 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -23,6 +23,7 @@ import ( "fmt" "sync" + "github.com/VictoriaMetrics/fastcache" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/types" @@ -77,6 +78,14 @@ var ( snapshotBloomStorageFalseHitMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/falsehit", nil) snapshotBloomStorageMissMeter = metrics.NewRegisteredMeter("state/snapshot/bloom/storage/miss", nil) + snapshotCacheGetGauge = metrics.NewRegisteredGauge("state/snapshot/cache/get", nil) + snapshotCacheSetGauge = metrics.NewRegisteredGauge("state/snapshot/cache/set", nil) + snapshotCacheMissGauge = metrics.NewRegisteredGauge("state/snapshot/cache/miss", nil) + snapshotCacheSizeGauge = metrics.NewRegisteredGauge("state/snapshot/cache/size", nil) + snapshotCacheCapacityGauge = metrics.NewRegisteredGauge("state/snapshot/cache/capacity", nil) + snapshotCacheCollisionGauge = metrics.NewRegisteredGauge("state/snapshot/cache/collision", nil) + snapshotCacheEntriesGauge = metrics.NewRegisteredGauge("state/snapshot/cache/entries", nil) + // ErrSnapshotStale is returned from data accessors if the underlying snapshot // layer had been invalidated due to the chain progressing forward far enough // to not maintain the layer's original state. @@ -388,7 +397,17 @@ func (t *Tree) Cap(root common.Hash, layers int) error { // Run the internal capping and discard all stale layers t.lock.Lock() + defer t.lock.Unlock() + var stats fastcache.Stats + diff.origin.cache.UpdateStats(&stats) + snapshotCacheGetGauge.Update(int64(stats.GetCalls)) + snapshotCacheSetGauge.Update(int64(stats.SetCalls)) + snapshotCacheMissGauge.Update(int64(stats.Misses)) + snapshotCacheSizeGauge.Update(int64(stats.BytesSize)) + snapshotCacheCapacityGauge.Update(int64(stats.MaxBytesSize)) + snapshotCacheEntriesGauge.Update(int64(stats.EntriesCount)) + snapshotCacheCollisionGauge.Update(int64(stats.Collisions)) // Flattening the bottom-most diff layer requires special casing since there's // no child to rewire to the grandparent. In that case we can fake a temporary