Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/parser/ltf.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ltfContext struct {
WindowUsed int `json:"window_used"`
WindowMax int `json:"window_max"`
FillPct float64 `json:"fill_pct"`
Compactions int `json:"compactions"`
Compactions int `json:"compactions"` // running counter: compactions so far in the loop
CacheHitPct float64 `json:"cache_hit_pct"`
}

Expand Down
5 changes: 5 additions & 0 deletions internal/trace/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func (t *Trace) MaxContextFill() float64 {
return max
}

// TotalCompactions returns the total number of context compactions in the
// loop. ContextState.Compactions is a running counter (compactions so far,
// not per-iteration), so the max across iterations is the total. Max is used
// instead of the last iteration's value to be robust to out-of-order
// iterations.
func (t *Trace) TotalCompactions() int {
var max int
for _, it := range t.Iterations {
Expand Down
16 changes: 16 additions & 0 deletions internal/trace/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package trace

import "testing"

// Compactions is a running counter, so the total is the max across
// iterations (4 here), not the sum (5).
func TestTotalCompactionsIsMaxOfRunningCounter(t *testing.T) {
tr := &Trace{Iterations: []Iteration{
{Number: 1, Context: ContextState{Compactions: 0}},
{Number: 2, Context: ContextState{Compactions: 1}},
{Number: 3, Context: ContextState{Compactions: 4}},
}}
if got := tr.TotalCompactions(); got != 4 {
t.Errorf("TotalCompactions() = %d, want 4", got)
}
}
2 changes: 1 addition & 1 deletion internal/trace/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type ContextState struct {
WindowUsed int
WindowMax int
FillPct float64
Compactions int
Compactions int // running counter: compactions so far in the loop, not per-iteration
CacheHitPct float64
}

Expand Down