core/state: add cache hit rate

This commit is contained in:
Gary Rong 2025-10-09 10:19:54 +08:00
parent 49b0050d18
commit 70c0699655

View file

@ -95,7 +95,17 @@ type ReaderStats struct {
// String implements fmt.Stringer, returning string format statistics. // String implements fmt.Stringer, returning string format statistics.
func (s ReaderStats) String() string { 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. // ReaderWithStats wraps the additional method to retrieve the reader statistics from.