Files
lambda/internal/executer/profiler.go
2025-12-28 22:52:10 -05:00

41 lines
571 B
Go

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()
}