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"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime/pprof"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya"
|
"github.com/chihaya/chihaya"
|
||||||
|
@ -31,15 +32,29 @@ import (
|
||||||
_ "github.com/chihaya/chihaya/server/store/middleware/swarm"
|
_ "github.com/chihaya/chihaya/server/store/middleware/swarm"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configPath string
|
var (
|
||||||
|
configPath string
|
||||||
|
cpuprofile string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
||||||
|
flag.StringVar(&cpuprofile, "cpuprofile", "", "path to cpu profile output")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
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)
|
cfg, err := chihaya.OpenConfigFile(configPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("failed to load config: " + err.Error())
|
log.Fatal("failed to load config: " + err.Error())
|
||||||
|
|
Loading…
Reference in a new issue