Skip to content

Commit 792f45e

Browse files
committed
core/state: add cache hit rate
1 parent 1894279 commit 792f45e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/state/reader.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,17 @@ type ReaderStats struct {
9595

9696
// String implements fmt.Stringer, returning string format statistics.
9797
func (s ReaderStats) String() string {
98-
return fmt.Sprintf("account (hit: %d, miss: %d), storage (hit: %d, miss: %d)", s.AccountHit, s.AccountMiss, s.StorageHit, s.StorageMiss)
98+
var (
99+
accountRate float64
100+
storageRate float64
101+
)
102+
if s.AccountHit > 0 {
103+
accountRate = float64(s.AccountHit) / float64(s.AccountHit+s.AccountMiss) * 100
104+
}
105+
if s.StorageHit > 0 {
106+
storageRate = float64(s.StorageHit) / float64(s.StorageHit+s.StorageMiss) * 100
107+
}
108+
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)
99109
}
100110

101111
// ReaderWithStats wraps the additional method to retrieve the reader statistics from.

0 commit comments

Comments
 (0)