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