github.com/Cloud-Foundations/Dominator@v0.3.4/lib/pprof/impl.go (about) 1 package pprof 2 3 import ( 4 "os" 5 "runtime/pprof" 6 ) 7 8 var ( 9 cpuProfile *os.File 10 ) 11 12 func startCpuProfile(filename string) error { 13 if cpuProfile != nil { 14 panic("CPU profiling already started") 15 } 16 if file, err := os.Create(filename); err != nil { 17 return err 18 } else { 19 if err := pprof.StartCPUProfile(file); err != nil { 20 file.Close() 21 return err 22 } 23 cpuProfile = file 24 return nil 25 } 26 } 27 28 func stopCpuProfile() { 29 if cpuProfile == nil { 30 return 31 } 32 pprof.StopCPUProfile() 33 cpuProfile.Close() 34 cpuProfile = nil 35 }