feat: observer pattern for statistics

This commit is contained in:
2025-12-29 00:51:50 -05:00
parent e9dc3fe171
commit c2b397a9f6
11 changed files with 165 additions and 70 deletions

View File

@@ -7,6 +7,8 @@ import (
"git.maximhutz.com/max/lambda/internal/cli"
"git.maximhutz.com/max/lambda/internal/config"
"git.maximhutz.com/max/lambda/internal/executer"
"git.maximhutz.com/max/lambda/internal/profiler"
"git.maximhutz.com/max/lambda/internal/statistics"
"git.maximhutz.com/max/lambda/pkg/convert"
"git.maximhutz.com/max/lambda/pkg/lambda"
"git.maximhutz.com/max/lambda/pkg/saccharine"
@@ -41,10 +43,21 @@ func main() {
logger.Info("compiled lambda expression", "tree", lambda.Stringify(compiled))
}
executor := executer.New(options)
results, err := executor.Run(&compiled)
process := executer.New(options)
if options.Profile != "" {
profiler := profiler.New(options.Profile)
process.On("start", profiler.Start)
process.On("end", profiler.End)
}
statistics := &statistics.Profiler{}
process.On("start", statistics.Start)
process.On("step", statistics.Step)
process.On("end", statistics.End)
process.Run(&compiled)
cli.HandleError(err)
fmt.Println(lambda.Stringify(compiled))
fmt.Fprint(os.Stderr, results.String())
fmt.Fprint(os.Stderr, statistics.Results.String())
}