27 lines
371 B
Go
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())
|
|
}
|