Skip to content

Commit a4201b8

Browse files
author
Manuel Bovo
committed
first idea about profiling gianarb#16
1 parent f69e771 commit a4201b8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
bin/
2+
.idea/

cmd/daemon.go

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/gianarb/orbiter/api"
1717
"github.com/gianarb/orbiter/autoscaler"
1818
"github.com/gianarb/orbiter/core"
19+
"github.com/pkg/profile"
1920
"time"
2021
)
2122

@@ -24,6 +25,10 @@ type DaemonCmd struct {
2425
}
2526

2627
func (c *DaemonCmd) Run(args []string) int {
28+
29+
var prof interface {
30+
Stop()
31+
}
2732
logrus.Info("orbiter started")
2833
var port string
2934
var configPath string
@@ -39,6 +44,9 @@ func (c *DaemonCmd) Run(args []string) int {
3944
if debug == true {
4045
logrus.SetLevel(logrus.DebugLevel)
4146
logrus.Debug("Daemon started in debug mode")
47+
48+
prof = profile.Start(profile.CPUProfile, profile.NoShutdownHook)
49+
4250
}
4351
coreEngine := core.Core{
4452
Autoscalers: autoscaler.Autoscalers{},
@@ -75,6 +83,9 @@ func (c *DaemonCmd) Run(args []string) int {
7583
<-sigchan
7684
timer1.Stop()
7785
logrus.Info("Stopping and cleaning. Bye!")
86+
if logrus.GetLevel() == logrus.DebugLevel {
87+
prof.Stop()
88+
}
7889
os.Exit(0)
7990
}()
8091

0 commit comments

Comments
 (0)