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/classifier/classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func detectBudget(t *trace.Trace) *Classification {

func detectContextOverflow(t *trace.Trace) *Classification {
maxFill := t.MaxContextFill()
compactions := t.TotalCompactions()
compactions := t.MaxCompactions()

if compactions >= 3 && maxFill >= 90 {
return &Classification{
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runStats(cmd *cobra.Command, args []string) error {
fmt.Printf("Max context: %.0f%%\n", ctx)
}

compactions := t.TotalCompactions()
compactions := t.MaxCompactions()
if compactions > 0 {
fmt.Printf("Compactions: %d\n", compactions)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/trace/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func (t *Trace) MaxContextFill() float64 {
return max
}

func (t *Trace) TotalCompactions() int {
// MaxCompactions returns the highest ContextState.Compactions value across
// iterations. Compactions is a running counter (compactions so far in the
// loop), so the max is the total observed; the name MaxCompactions matches
// the aggregation (unlike the former TotalCompactions).
func (t *Trace) MaxCompactions() int {
var max int
for _, it := range t.Iterations {
if it.Context.Compactions > max {
Expand Down
33 changes: 33 additions & 0 deletions internal/trace/metrics_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package trace

import "testing"

func TestMaxCompactions(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.MaxCompactions(); got != 4 {
t.Errorf("MaxCompactions() = %d, want 4 (max of running counter, not sum 5)", got)
}
}

func TestMaxCompactionsEmpty(t *testing.T) {
tr := &Trace{}
if got := tr.MaxCompactions(); got != 0 {
t.Errorf("MaxCompactions() = %d, want 0", got)
}
}

func TestMaxCompactionsOutOfOrder(t *testing.T) {
// Max (not last) so out-of-order iterations still yield the peak counter.
tr := &Trace{Iterations: []Iteration{
{Number: 3, Context: ContextState{Compactions: 4}},
{Number: 1, Context: ContextState{Compactions: 0}},
{Number: 2, Context: ContextState{Compactions: 1}},
}}
if got := tr.MaxCompactions(); got != 4 {
t.Errorf("MaxCompactions() = %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: so far in the loop, not per-iteration
CacheHitPct float64
}

Expand Down