Files
lambda/internal/plugins/statistics.go
M.V. Hutz ef5b94545f fix: correct event handler registration in plugins
Fixed incorrect event handler registration in two plugins:

- Statistics plugin was calling Step instead of Stop on StopEvent,
  preventing statistics from being printed at the end of execution.
- Logs plugin was listening to StopEvent instead of StepEvent,
  causing it to only log once at the end instead of on each step.
2026-01-13 19:34:29 -05:00

45 lines
845 B
Go

package plugins
import (
"fmt"
"os"
"time"
"git.maximhutz.com/max/lambda/internal/engine"
"git.maximhutz.com/max/lambda/internal/statistics"
)
// An observer, to track reduction performance.
type Statistics struct {
start time.Time
steps uint64
}
// Create a new reduction performance Statistics.
func NewStatistics(process *engine.Engine) *Statistics {
plugin := &Statistics{}
process.On(engine.StartEvent, plugin.Start)
process.On(engine.StepEvent, plugin.Step)
process.On(engine.StopEvent, plugin.Stop)
return plugin
}
func (t *Statistics) Start() {
t.start = time.Now()
t.steps = 0
}
func (t *Statistics) Step() {
t.steps++
}
func (t *Statistics) Stop() {
results := statistics.Results{
StepsTaken: t.steps,
TimeElapsed: uint64(time.Since(t.start).Milliseconds()),
}
fmt.Fprint(os.Stderr, results.String())
}