feat: explanation as observer too

This commit is contained in:
2025-12-29 01:31:09 -05:00
parent 5ceb845137
commit 17cf8f86f8
6 changed files with 47 additions and 26 deletions

View File

@@ -0,0 +1,46 @@
package performance
import (
"os"
"path/filepath"
"runtime/pprof"
)
type Tracker struct {
File string
filePointer *os.File
Error error
}
func Track(file string) *Tracker {
return &Tracker{File: file}
}
func (t *Tracker) Start() {
var absPath string
absPath, t.Error = filepath.Abs(t.File)
if t.Error != nil {
return
}
t.Error = os.MkdirAll(filepath.Dir(absPath), 0777)
if t.Error != nil {
return
}
t.filePointer, t.Error = os.Create(absPath)
if t.Error != nil {
return
}
t.Error = pprof.StartCPUProfile(t.filePointer)
if t.Error != nil {
return
}
}
func (t *Tracker) End() {
pprof.StopCPUProfile()
t.filePointer.Close()
}