github.com/ghodss/etcd@v0.3.1-0.20140417172404-cc329bfa55cb/etcd/profile.go (about) 1 package etcd 2 3 import ( 4 "os" 5 "os/signal" 6 "runtime/pprof" 7 8 "github.com/coreos/etcd/log" 9 ) 10 11 // profile starts CPU profiling. 12 func profile(path string) { 13 f, err := os.Create(path) 14 if err != nil { 15 log.Fatal(err) 16 } 17 pprof.StartCPUProfile(f) 18 19 c := make(chan os.Signal, 1) 20 signal.Notify(c, os.Interrupt) 21 go func() { 22 sig := <-c 23 log.Infof("captured %v, stopping profiler and exiting..", sig) 24 pprof.StopCPUProfile() 25 os.Exit(1) 26 }() 27 }