Skip to content

Commit

Permalink
ciao-launcher: Ensure cpu profile and logs are flushed
Browse files Browse the repository at this point in the history
Launcher was mistakenly using defer to flush logs and to stop
the CPU profiling when shutting down.  However, as launcher is
quit by calling os.Exit, deferred functions do not get called.
This was leading to incomplete CPU profiles being generated.

Fixes: ciao-project#163

Signed-off-by: Mark Ryan <[email protected]>
  • Loading branch information
Mark Ryan committed Jul 12, 2016
1 parent 4838236 commit 31a9688
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions ciao-launcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,32 +528,34 @@ func main() {
log.Fatalf("Unable to initialise logs: %v", err)
}

glog.Info("Starting Launcher")

exitCode := 0
var stopProfile func()
if profileFN != nil {
stopProfile := profileFN()
if stopProfile != nil {
defer stopProfile()
}
stopProfile = profileFN()
}

defer func() {
glog.Flush()
glog.Info("Exit")
}()

glog.Info("Starting Launcher")

if hardReset {
purgeLauncherState()
os.Exit(0)
}
} else {
setLimits()

glog.Infof("Launcher will allow a maximum of %d instances", maxInstances)

setLimits()
if err := createMandatoryDirs(); err != nil {
glog.Fatalf("Unable to create mandatory dirs: %v", err)
}

glog.Infof("Launcher will allow a maximum of %d instances", maxInstances)
exitCode = startLauncher()
}

if err := createMandatoryDirs(); err != nil {
glog.Fatalf("Unable to create mandatory dirs: %v", err)
if stopProfile != nil {
stopProfile()
}

os.Exit(startLauncher())
glog.Flush()
glog.Info("Exit")

os.Exit(exitCode)
}

0 comments on commit 31a9688

Please sign in to comment.