github.com/jpetazzo/etcd@v0.2.1-0.20140113055439-97f1363afac5/profile.go (about)

     1  package main
     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  }