feat: added optional profiling
This commit is contained in:
40
internal/executer/profiler.go
Normal file
40
internal/executer/profiler.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user