feat: added optional profiling

This commit is contained in:
2025-12-28 22:52:10 -05:00
parent a4c049c0ff
commit e9dc3fe171
8 changed files with 124 additions and 77 deletions

View File

@@ -0,0 +1,40 @@
package executer
import (
"os"
"path/filepath"
"runtime/pprof"
)
type Profiler struct {
File string
filePointer *os.File
}
func (p *Profiler) Start() error {
absPath, err := filepath.Abs(p.File)
if err != nil {
return err
}
err = os.MkdirAll(filepath.Dir(absPath), 0777)
if err != nil {
return err
}
p.filePointer, err = os.Create(absPath)
if err != nil {
return err
}
if err = pprof.StartCPUProfile(p.filePointer); err != nil {
return err
}
return nil
}
func (p *Profiler) End() {
pprof.StopCPUProfile()
p.filePointer.Close()
}