Merge pull request #91 from Quentin-M/fix_pprof

cmd/clair: fix pprof
This commit is contained in:
Quentin Machu 2016-03-07 16:49:26 -05:00
commit 68d0369128
2 changed files with 13 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import (
"math/rand" "math/rand"
"os" "os"
"os/signal" "os/signal"
"syscall"
"time" "time"
"github.com/coreos/clair/api" "github.com/coreos/clair/api"
@ -62,7 +63,7 @@ func Boot(config *config.Config) {
go updater.Run(config.Updater, db, st) go updater.Run(config.Updater, db, st)
// Wait for interruption and shutdown gracefully. // Wait for interruption and shutdown gracefully.
waitForSignals(os.Interrupt) waitForSignals(syscall.SIGINT, syscall.SIGTERM)
log.Info("Received interruption, gracefully stopping ...") log.Info("Received interruption, gracefully stopping ...")
st.Stop() st.Stop()
} }

View File

@ -67,25 +67,30 @@ func main() {
// Enable CPU Profiling if specified // Enable CPU Profiling if specified
if *flagCPUProfilePath != "" { if *flagCPUProfilePath != "" {
startCPUProfiling(*flagCPUProfilePath) defer stopCPUProfiling(startCPUProfiling(*flagCPUProfilePath))
defer stopCPUProfiling()
} }
clair.Boot(config) clair.Boot(config)
} }
func startCPUProfiling(path string) { func startCPUProfiling(path string) *os.File {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
log.Fatalf("failed to create profile file: %s", err) log.Fatalf("failed to create profile file: %s", err)
} }
defer f.Close()
pprof.StartCPUProfile(f) err = pprof.StartCPUProfile(f)
if err != nil {
log.Fatalf("failed to start CPU profiling: %s", err)
}
log.Info("started CPU profiling") log.Info("started CPU profiling")
return f
} }
func stopCPUProfiling() { func stopCPUProfiling(f *os.File) {
pprof.StopCPUProfile() pprof.StopCPUProfile()
f.Close()
log.Info("stopped CPU profiling") log.Info("stopped CPU profiling")
} }