Files
lambda/internal/profiler/profiler.go

49 lines
754 B
Go

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