mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
28 lines
443 B
Go
28 lines
443 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"os/signal"
|
|
"runtime/pprof"
|
|
|
|
"github.com/coreos/etcd/log"
|
|
)
|
|
|
|
// profile starts CPU profiling.
|
|
func profile(path string) {
|
|
f, err := os.Create(path)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
pprof.StartCPUProfile(f)
|
|
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt)
|
|
go func() {
|
|
sig := <-c
|
|
log.Infof("captured %v, stopping profiler and exiting..", sig)
|
|
pprof.StopCPUProfile()
|
|
os.Exit(1)
|
|
}()
|
|
}
|