Merge pull request #192 from mrd0ll4r/cpuprofile
general: add CPU profiling
This commit is contained in:
commit
ab6726b895
1 changed files with 16 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/pprof"
|
||||
"syscall"
|
||||
|
||||
"github.com/chihaya/chihaya"
|
||||
|
@ -31,15 +32,29 @@ import (
|
|||
_ "github.com/chihaya/chihaya/server/store/middleware/swarm"
|
||||
)
|
||||
|
||||
var configPath string
|
||||
var (
|
||||
configPath string
|
||||
cpuprofile string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
||||
flag.StringVar(&cpuprofile, "cpuprofile", "", "path to cpu profile output")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if cpuprofile != "" {
|
||||
log.Println("profiling...")
|
||||
f, err := os.Create(cpuprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
cfg, err := chihaya.OpenConfigFile(configPath)
|
||||
if err != nil {
|
||||
log.Fatal("failed to load config: " + err.Error())
|
||||
|
|
Loading…
Reference in a new issue