add cpu profiling endpoint

This commit is contained in:
abhishek9686
2024-11-07 18:18:08 +04:00
parent bb06ddaabe
commit 16b693815f
5 changed files with 46 additions and 0 deletions

23
logic/proc.go Normal file
View File

@@ -0,0 +1,23 @@
package logic
import (
"log"
"os"
"runtime/pprof"
)
func StartCPUProfiling() *os.File {
f, err := os.OpenFile("/root/data/cpu.prof", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
return f
}
func StopCPUProfiling(f *os.File) {
pprof.StopCPUProfile()
f.Close()
}