mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-27 05:08:11 +08:00
add cpu profiling endpoint
This commit is contained in:
23
logic/proc.go
Normal file
23
logic/proc.go
Normal 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()
|
||||
}
|
Reference in New Issue
Block a user