Revision 3e4f8a382e9c8006e3ee37ba2e36f7a0e7e695d6 authored by Xiang Li on 11 December 2013, 18:19:16 UTC, committed by Xiang Li on 11 December 2013, 18:19:16 UTC
1 parent 44b08fe
Raw File
profile.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)
	}()
}
back to top