2
0

proc.go 498 B

123456789101112131415161718192021222324
  1. package logic
  2. import (
  3. "os"
  4. "runtime/pprof"
  5. "github.com/gravitl/netmaker/logger"
  6. )
  7. func StartCPUProfiling() *os.File {
  8. f, err := os.OpenFile("/root/data/cpu.prof", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0755)
  9. if err != nil {
  10. logger.Log(0, "could not create CPU profile: ", err.Error())
  11. }
  12. if err := pprof.StartCPUProfile(f); err != nil {
  13. logger.Log(0, "could not start CPU profile: ", err.Error())
  14. }
  15. return f
  16. }
  17. func StopCPUProfiling(f *os.File) {
  18. pprof.StopCPUProfile()
  19. f.Close()
  20. }