From 70c06996556d84135e6c501ec6116267bc0fa732 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Thu, 9 Oct 2025 10:19:54 +0800 Subject: [PATCH] core/state: add cache hit rate --- core/state/reader.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/state/reader.go b/core/state/reader.go index c1a97fec36..2b91392adb 100644 --- a/core/state/reader.go +++ b/core/state/reader.go @@ -95,7 +95,17 @@ type ReaderStats struct { // String implements fmt.Stringer, returning string format statistics. func (s ReaderStats) String() string { - return fmt.Sprintf("account (hit: %d, miss: %d), storage (hit: %d, miss: %d)", s.AccountHit, s.AccountMiss, s.StorageHit, s.StorageMiss) + var ( + accountRate float64 + storageRate float64 + ) + if s.AccountHit > 0 { + accountRate = float64(s.AccountHit) / float64(s.AccountHit+s.AccountMiss) * 100 + } + if s.StorageHit > 0 { + storageRate = float64(s.StorageHit) / float64(s.StorageHit+s.StorageMiss) * 100 + } + return fmt.Sprintf("account (hit: %d, miss: %d, rate: %.2f), storage (hit: %d, miss: %d, rate: %.2f)", s.AccountHit, s.AccountMiss, accountRate, s.StorageHit, s.StorageMiss, storageRate) } // ReaderWithStats wraps the additional method to retrieve the reader statistics from.