From 20e11e3b90a55084fe2c019500a324490cfaa2e4 Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sat, 17 Jun 2017 21:13:32 +0200 Subject: [PATCH] cmd: crio: enable remote profiler This patch also hides the profile under the debug flag as there's runtime cost to enable the profiler. This removes the old way of profiling (CPU) as that's not really needed. Signed-off-by: Antonio Murdaca --- cmd/crio/main.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cmd/crio/main.go b/cmd/crio/main.go index 6f0930d7..0107d2f5 100644 --- a/cmd/crio/main.go +++ b/cmd/crio/main.go @@ -3,14 +3,14 @@ package main import ( "fmt" "net" + "net/http" + _ "net/http/pprof" "os" "os/signal" "sort" "strings" "syscall" - "runtime/pprof" - "github.com/Sirupsen/logrus" "github.com/containers/storage/pkg/reexec" "github.com/kubernetes-incubator/cri-o/server" @@ -233,9 +233,9 @@ func main() { Name: "cni-plugin-dir", Usage: "CNI plugin binaries directory", }, - cli.StringFlag{ - Name: "cpu-profile", - Usage: "set the CPU profile file path", + cli.BoolFlag{ + Name: "profile", + Usage: "enable pprof remote profiler on localhost:6060", }, } @@ -285,13 +285,10 @@ func main() { } app.Action = func(c *cli.Context) error { - if cp := c.GlobalString("cpu-profile"); cp != "" { - f, err := os.Create(cp) - if err != nil { - return fmt.Errorf("invalid --cpu-profile value %q", err) - } - _ = pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() + if c.GlobalBool("profile") { + go func() { + http.ListenAndServe("localhost:6060", nil) + }() } config := c.App.Metadata["config"].(*server.Config)