cmd/clair: fix pprof
This commit is contained in:
parent
ee28073d61
commit
09dda9bfd7
@ -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)
|
||||||
log.Info("started CPU profiling")
|
if err != nil {
|
||||||
|
log.Fatalf("failed to start CPU profiling: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func stopCPUProfiling() {
|
log.Info("started CPU profiling")
|
||||||
|
|
||||||
|
return f
|
||||||
|
}
|
||||||
|
|
||||||
|
func stopCPUProfiling(f *os.File) {
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
|
f.Close()
|
||||||
log.Info("stopped CPU profiling")
|
log.Info("stopped CPU profiling")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user