buildr/internal/profiling/recorder.go
Peter 1261932bdc
All checks were successful
continuous-integration/drone/push Build is passing
refactor: apply golangci-lint findings
2023-06-22 19:16:00 +02:00

27 lines
371 B
Go

package profiling
import (
"errors"
"os"
"runtime/pprof"
)
type Recorder struct {
profile *pprof.Profile
outFile *os.File
cpuProfile bool
}
func (r *Recorder) Close() error {
if r == nil {
return nil
}
if r.cpuProfile {
pprof.StopCPUProfile()
return r.outFile.Close()
}
return errors.Join(r.profile.WriteTo(r.outFile, 0), r.outFile.Close())
}