From 0910d2ccabc71ae584ee31462023bf59090b74e2 Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Mon, 1 Aug 2016 16:51:48 -0400 Subject: [PATCH] general: add CPU profiling --- cmd/chihaya/main.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/chihaya/main.go b/cmd/chihaya/main.go index 30e74f6..54d9c57 100644 --- a/cmd/chihaya/main.go +++ b/cmd/chihaya/main.go @@ -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())