Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/clair: fix pprof #91

Merged
merged 2 commits into from
Mar 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clair.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"math/rand"
"os"
"os/signal"
"syscall"
"time"

"github.com/coreos/clair/api"
Expand Down Expand Up @@ -62,7 +63,7 @@ func Boot(config *config.Config) {
go updater.Run(config.Updater, db, st)

// Wait for interruption and shutdown gracefully.
waitForSignals(os.Interrupt)
waitForSignals(syscall.SIGINT, syscall.SIGTERM)
log.Info("Received interruption, gracefully stopping ...")
st.Stop()
}
Expand Down
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")
}