feat: rename profiler to performance, typeless event emitter
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
type Executor struct {
|
||||
Config *config.Config
|
||||
emitter.Emitter[*lambda.Expression]
|
||||
emitter.Emitter
|
||||
}
|
||||
|
||||
func New(config *config.Config) *Executor {
|
||||
@@ -19,14 +19,14 @@ func New(config *config.Config) *Executor {
|
||||
}
|
||||
|
||||
func (e Executor) Run(expr *lambda.Expression) {
|
||||
e.Emit("start", expr)
|
||||
e.Emit("start")
|
||||
|
||||
if e.Config.Explanation {
|
||||
fmt.Println(lambda.Stringify(*expr))
|
||||
}
|
||||
|
||||
for lambda.ReduceOnce(expr) {
|
||||
e.Emit("step", expr)
|
||||
e.Emit("step")
|
||||
if e.Config.Verbose {
|
||||
slog.Info("reduction", "tree", lambda.Stringify(*expr))
|
||||
}
|
||||
@@ -35,5 +35,5 @@ func (e Executor) Run(expr *lambda.Expression) {
|
||||
}
|
||||
}
|
||||
|
||||
e.Emit("end", expr)
|
||||
e.Emit("end")
|
||||
}
|
||||
|
||||
46
internal/performance/performance.go
Normal file
46
internal/performance/performance.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package performance
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
)
|
||||
|
||||
type Tracker struct {
|
||||
File string
|
||||
filePointer *os.File
|
||||
Error error
|
||||
}
|
||||
|
||||
func Track(file string) *Tracker {
|
||||
return &Tracker{File: file}
|
||||
}
|
||||
|
||||
func (t *Tracker) Start() {
|
||||
var absPath string
|
||||
|
||||
absPath, t.Error = filepath.Abs(t.File)
|
||||
if t.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
t.Error = os.MkdirAll(filepath.Dir(absPath), 0777)
|
||||
if t.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
t.filePointer, t.Error = os.Create(absPath)
|
||||
if t.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
t.Error = pprof.StartCPUProfile(t.filePointer)
|
||||
if t.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracker) End() {
|
||||
pprof.StopCPUProfile()
|
||||
t.filePointer.Close()
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package profiler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime/pprof"
|
||||
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
)
|
||||
|
||||
type Profiler struct {
|
||||
File string
|
||||
filePointer *os.File
|
||||
Error error
|
||||
}
|
||||
|
||||
func New(file string) *Profiler {
|
||||
return &Profiler{File: file}
|
||||
}
|
||||
|
||||
func (p *Profiler) Start(*lambda.Expression) {
|
||||
var absPath string
|
||||
|
||||
absPath, p.Error = filepath.Abs(p.File)
|
||||
if p.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.Error = os.MkdirAll(filepath.Dir(absPath), 0777)
|
||||
if p.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.filePointer, p.Error = os.Create(absPath)
|
||||
if p.Error != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p.Error = pprof.StartCPUProfile(p.filePointer)
|
||||
if p.Error != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Profiler) End(*lambda.Expression) {
|
||||
pprof.StopCPUProfile()
|
||||
p.filePointer.Close()
|
||||
}
|
||||
@@ -2,29 +2,31 @@ package statistics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.maximhutz.com/max/lambda/pkg/lambda"
|
||||
)
|
||||
|
||||
type Profiler struct {
|
||||
type Tracker struct {
|
||||
start time.Time
|
||||
steps uint64
|
||||
Results *Results
|
||||
}
|
||||
|
||||
func (p *Profiler) Start(*lambda.Expression) {
|
||||
p.start = time.Now()
|
||||
p.steps = 0
|
||||
p.Results = nil
|
||||
func Track() *Tracker {
|
||||
return &Tracker{}
|
||||
}
|
||||
|
||||
func (p *Profiler) Step(*lambda.Expression) {
|
||||
p.steps++
|
||||
func (t *Tracker) Start() {
|
||||
t.start = time.Now()
|
||||
t.steps = 0
|
||||
t.Results = nil
|
||||
}
|
||||
|
||||
func (p *Profiler) End(*lambda.Expression) {
|
||||
p.Results = &Results{
|
||||
StepsTaken: p.steps,
|
||||
TimeElapsed: uint64(time.Since(p.start).Milliseconds()),
|
||||
func (t *Tracker) Step() {
|
||||
t.steps++
|
||||
}
|
||||
|
||||
func (t *Tracker) End() {
|
||||
t.Results = &Results{
|
||||
StepsTaken: t.steps,
|
||||
TimeElapsed: uint64(time.Since(t.start).Milliseconds()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user