From 121e36130d36eae65c74b60b2034684cedeb7a3f Mon Sep 17 00:00:00 2001 From: jsvisa Date: Wed, 9 Apr 2025 11:16:26 +0000 Subject: [PATCH] tridb/pathdb: add fastcache metrics Signed-off-by: jsvisa --- triedb/pathdb/disklayer.go | 10 ++++++++++ triedb/pathdb/metrics.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/triedb/pathdb/disklayer.go b/triedb/pathdb/disklayer.go index bee4cd1e8a..da25cd83c7 100644 --- a/triedb/pathdb/disklayer.go +++ b/triedb/pathdb/disklayer.go @@ -306,6 +306,16 @@ func (dl *diskLayer) update(root common.Hash, id uint64, block uint64, nodes *no // and returns a newly constructed disk layer. Note the current disk // layer must be tagged as stale first to prevent re-access. func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) { + var stats fastcache.Stats + dl.nodes.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)) + dl.lock.Lock() defer dl.lock.Unlock() diff --git a/triedb/pathdb/metrics.go b/triedb/pathdb/metrics.go index 502c34fc62..7b6da47a92 100644 --- a/triedb/pathdb/metrics.go +++ b/triedb/pathdb/metrics.go @@ -72,6 +72,14 @@ var ( historyBuildTimeMeter = metrics.NewRegisteredResettingTimer("pathdb/history/time", nil) historyDataBytesMeter = metrics.NewRegisteredMeter("pathdb/history/bytes/data", nil) historyIndexBytesMeter = metrics.NewRegisteredMeter("pathdb/history/bytes/index", nil) + + snapshotCacheGetGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/get", nil) + snapshotCacheSetGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/set", nil) + snapshotCacheMissGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/miss", nil) + snapshotCacheSizeGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/size", nil) + snapshotCacheCapacityGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/capacity", nil) + snapshotCacheCollisionGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/collision", nil) + snapshotCacheEntriesGauge = metrics.NewRegisteredGauge("pathdb/snapshot/cache/entries", nil) ) // Metrics in generation