Skip to content

Commit

Permalink
bug: cpuProfile & memProfile dont populate
Browse files Browse the repository at this point in the history
Current scenario, `start()` is called, but immediately returns. As such, `defer
memProfFile.Close()` and `defer pprof.StopCPUProfile()` get called too
quickly.

This change moves the profiling logic just after `start()`.
  • Loading branch information
asoorm authored and buger committed Feb 20, 2018
1 parent acfd099 commit f8e0db2
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,28 @@ func main() {

start()

if *memProfile {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Debug("Memory profiling active")
var err error
if memProfFile, err = os.Create("tyk.mprof"); err != nil {
panic(err)
}
defer memProfFile.Close()
}
if *cpuProfile {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Info("Cpu profiling active")
cpuProfFile, err := os.Create("tyk.prof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(cpuProfFile)
defer pprof.StopCPUProfile()
}

if goAgainErr != nil {
var err error
if l, err = generateListener(config.Global.ListenPort); err != nil {
Expand Down Expand Up @@ -1146,28 +1168,6 @@ func main() {
}

func start() {
if *memProfile {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Debug("Memory profiling active")
var err error
if memProfFile, err = os.Create("tyk.mprof"); err != nil {
panic(err)
}
defer memProfFile.Close()
}
if *cpuProfile {
log.WithFields(logrus.Fields{
"prefix": "main",
}).Info("Cpu profiling active")
cpuProfFile, err := os.Create("tyk.prof")
if err != nil {
panic(err)
}
pprof.StartCPUProfile(cpuProfFile)
defer pprof.StopCPUProfile()
}

// Set up a default org manager so we can traverse non-live paths
if !config.Global.SupressDefaultOrgStore {
log.WithFields(logrus.Fields{
Expand Down

0 comments on commit f8e0db2

Please sign in to comment.