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:
CPerezz 2026-01-21 23:14:45 +01:00
parent 3344eb9ce8
commit bfe7a6c3dc
No known key found for this signature in database
GPG key ID: 62045F34B97177DD

View file

@ -58,8 +58,12 @@ func TestLogSlowBlockJSON(t *testing.T) {
AccountCacheMiss: 6,
StorageCacheHit: 0,
StorageCacheMiss: 11,
ContractCodeHit: 4,
ContractCodeMiss: 0,
CodeStats: state.ContractCodeReaderStats{
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 {
t.Errorf("Expected gas used 21000000, got %d", logEntry.Block.GasUsed)
}
if logEntry.Timing.ExecutionMs != 500 {
t.Errorf("Expected execution_ms 500, got %d", logEntry.Timing.ExecutionMs)
if logEntry.Timing.ExecutionMs != 500.0 {
t.Errorf("Expected execution_ms 500.0, got %v", logEntry.Timing.ExecutionMs)
}
if logEntry.Timing.TotalMs != 1200 {
t.Errorf("Expected total_ms 1200, got %d", logEntry.Timing.TotalMs)
if logEntry.Timing.TotalMs != 1200.0 {
t.Errorf("Expected total_ms 1200.0, got %v", logEntry.Timing.TotalMs)
}
if logEntry.StateReads.Accounts != 100 {
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 {
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)
}