Log range map for debugging. (#2754)

* Log range map for debugging.

* log details on errors

* log details
This commit is contained in:
Raja Subramanian
2024-06-04 08:00:26 +05:30
committed by GitHub
parent 1e52b09e24
commit 03bb468472
2 changed files with 60 additions and 4 deletions
+28
View File
@@ -19,6 +19,8 @@ import (
"fmt"
"math"
"unsafe"
"go.uber.org/zap/zapcore"
)
const (
@@ -40,12 +42,23 @@ type valueType interface {
uint32 | uint64
}
// ---------------------------------------------------
type rangeVal[RT rangeType, VT valueType] struct {
start RT
end RT
value VT
}
func (r rangeVal[RT, VT]) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddUint64("start", uint64(r.start))
e.AddUint64("end", uint64(r.end))
e.AddUint64("value", uint64(r.value))
return nil
}
// ---------------------------------------------------
type RangeMap[RT rangeType, VT valueType] struct {
halfRange RT
@@ -63,6 +76,21 @@ func NewRangeMap[RT rangeType, VT valueType](size int) *RangeMap[RT, VT] {
return r
}
func (r *RangeMap[RT, VT]) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddInt("numRanges", len(r.ranges))
// just the last 10 ranges max
startIdx := len(r.ranges) - 10
if startIdx < 0 {
startIdx = 0
}
for i := startIdx; i < len(r.ranges); i++ {
e.AddObject(fmt.Sprintf("range[%d]", i), r.ranges[i])
}
return nil
}
func (r *RangeMap[RT, VT]) ClearAndResetValue(start RT, val VT) {
r.initRanges(start, val)
}