mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-20 11:46:44 +00:00
fix(metrics): use float64 for sub-millisecond timing precision
Convert timing fields from int64 to float64 to preserve sub-millisecond precision in slow block JSON output. Previously, durations under 1ms would truncate to 0 due to integer division. Changes: - slowBlockTime struct fields: int64 -> float64 - Add durationToMs() helper for nanosecond to float ms conversion - Update test assertions for float comparisons
This commit is contained in:
parent
3344eb9ce8
commit
bfe7a6c3dc
1 changed files with 17 additions and 6 deletions
|
|
@ -58,8 +58,12 @@ func TestLogSlowBlockJSON(t *testing.T) {
|
||||||
AccountCacheMiss: 6,
|
AccountCacheMiss: 6,
|
||||||
StorageCacheHit: 0,
|
StorageCacheHit: 0,
|
||||||
StorageCacheMiss: 11,
|
StorageCacheMiss: 11,
|
||||||
ContractCodeHit: 4,
|
CodeStats: state.ContractCodeReaderStats{
|
||||||
ContractCodeMiss: 0,
|
CacheHit: 4,
|
||||||
|
CacheMiss: 0,
|
||||||
|
CacheHitBytes: 102400, // ~100KB served from cache
|
||||||
|
CacheMissBytes: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,11 +114,11 @@ func TestLogSlowBlockJSON(t *testing.T) {
|
||||||
if logEntry.Block.GasUsed != 21000000 {
|
if logEntry.Block.GasUsed != 21000000 {
|
||||||
t.Errorf("Expected gas used 21000000, got %d", logEntry.Block.GasUsed)
|
t.Errorf("Expected gas used 21000000, got %d", logEntry.Block.GasUsed)
|
||||||
}
|
}
|
||||||
if logEntry.Timing.ExecutionMs != 500 {
|
if logEntry.Timing.ExecutionMs != 500.0 {
|
||||||
t.Errorf("Expected execution_ms 500, got %d", logEntry.Timing.ExecutionMs)
|
t.Errorf("Expected execution_ms 500.0, got %v", logEntry.Timing.ExecutionMs)
|
||||||
}
|
}
|
||||||
if logEntry.Timing.TotalMs != 1200 {
|
if logEntry.Timing.TotalMs != 1200.0 {
|
||||||
t.Errorf("Expected total_ms 1200, got %d", logEntry.Timing.TotalMs)
|
t.Errorf("Expected total_ms 1200.0, got %v", logEntry.Timing.TotalMs)
|
||||||
}
|
}
|
||||||
if logEntry.StateReads.Accounts != 100 {
|
if logEntry.StateReads.Accounts != 100 {
|
||||||
t.Errorf("Expected accounts 100, got %d", logEntry.StateReads.Accounts)
|
t.Errorf("Expected accounts 100, got %d", logEntry.StateReads.Accounts)
|
||||||
|
|
@ -157,6 +161,13 @@ func TestLogSlowBlockJSON(t *testing.T) {
|
||||||
if logEntry.Cache.Code.HitRate != 100.0 {
|
if logEntry.Cache.Code.HitRate != 100.0 {
|
||||||
t.Errorf("Expected code cache hit_rate 100.0, got %f", logEntry.Cache.Code.HitRate)
|
t.Errorf("Expected code cache hit_rate 100.0, got %f", logEntry.Cache.Code.HitRate)
|
||||||
}
|
}
|
||||||
|
// Verify new byte-level cache statistics
|
||||||
|
if logEntry.Cache.Code.HitBytes != 102400 {
|
||||||
|
t.Errorf("Expected code cache hit_bytes 102400, got %d", logEntry.Cache.Code.HitBytes)
|
||||||
|
}
|
||||||
|
if logEntry.Cache.Code.MissBytes != 0 {
|
||||||
|
t.Errorf("Expected code cache miss_bytes 0, got %d", logEntry.Cache.Code.MissBytes)
|
||||||
|
}
|
||||||
|
|
||||||
t.Logf("Parsed JSON:\n%+v", logEntry)
|
t.Logf("Parsed JSON:\n%+v", logEntry)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue