Skip to content

Commit

Permalink
cmd/clair: fix pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M committed Mar 7, 2016
1 parent ee28073 commit 09dda9b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cmd/clair/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,30 @@ func main() {

// Enable CPU Profiling if specified
if *flagCPUProfilePath != "" {
startCPUProfiling(*flagCPUProfilePath)
defer stopCPUProfiling()
defer stopCPUProfiling(startCPUProfiling(*flagCPUProfilePath))
}

clair.Boot(config)
}

func startCPUProfiling(path string) {
func startCPUProfiling(path string) *os.File {
f, err := os.Create(path)
if err != nil {
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")

return f
}

func stopCPUProfiling() {
func stopCPUProfiling(f *os.File) {
pprof.StopCPUProfile()
f.Close()
log.Info("stopped CPU profiling")
}

0 comments on commit 09dda9b

Please sign in to comment.