From 435a1c825d640d6819261e56d9a8f8a420933968 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Tue, 20 Sep 2016 10:22:19 -0700 Subject: [PATCH] Refactor api/http to just pprof Signed-off-by: Michael Crosby --- api/http/pprof/pprof.go | 23 ----------------------- api/pprof/pprof.go | 18 ++++++++++++++++++ containerd/main.go | 9 +++++---- 3 files changed, 23 insertions(+), 27 deletions(-) delete mode 100644 api/http/pprof/pprof.go create mode 100644 api/pprof/pprof.go diff --git a/api/http/pprof/pprof.go b/api/http/pprof/pprof.go deleted file mode 100644 index 0e586c0ff..000000000 --- a/api/http/pprof/pprof.go +++ /dev/null @@ -1,23 +0,0 @@ -package pprof - -import ( - // expvar init routine adds the "/debug/vars" handler - _ "expvar" - "net/http" - "net/http/pprof" - - "github.com/Sirupsen/logrus" -) - -// Enable registers the "/debug/pprof" handler -func Enable(address string) { - http.Handle("/", http.RedirectHandler("/debug/pprof", http.StatusMovedPermanently)) - - http.Handle("/debug/pprof/block", pprof.Handler("block")) - http.Handle("/debug/pprof/heap", pprof.Handler("heap")) - http.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) - http.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) - - go http.ListenAndServe(address, nil) - logrus.Debug("pprof listening in address %s", address) -} diff --git a/api/pprof/pprof.go b/api/pprof/pprof.go new file mode 100644 index 000000000..29109261d --- /dev/null +++ b/api/pprof/pprof.go @@ -0,0 +1,18 @@ +package pprof + +import ( + // expvar init routine adds the "/debug/vars" handler + _ "expvar" + "net/http" + "net/http/pprof" +) + +// New returns a new handler serving pprof information +func New() http.Handler { + mux := http.NewServeMux() + mux.Handle("/pprof/block", pprof.Handler("block")) + mux.Handle("/pprof/heap", pprof.Handler("heap")) + mux.Handle("/pprof/goroutine", pprof.Handler("goroutine")) + mux.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) + return mux +} diff --git a/containerd/main.go b/containerd/main.go index febeac32e..96a7f4a84 100644 --- a/containerd/main.go +++ b/containerd/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net/http" "os" "os/signal" "runtime" @@ -19,7 +20,7 @@ import ( "github.com/docker/containerd" "github.com/docker/containerd/api/grpc/server" "github.com/docker/containerd/api/grpc/types" - "github.com/docker/containerd/api/http/pprof" + "github.com/docker/containerd/api/pprof" "github.com/docker/containerd/supervisor" "github.com/docker/docker/pkg/listeners" ) @@ -120,7 +121,9 @@ func main() { logrus.SetLevel(logrus.DebugLevel) } if p := context.GlobalString("pprof-address"); len(p) > 0 { - pprof.Enable(p) + h := pprof.New() + http.Handle("/debug", h) + go http.ListenAndServe(p, nil) } if err := checkLimits(); err != nil { return err @@ -182,8 +185,6 @@ func daemon(context *cli.Context) error { } func startServer(protocol, address string, sv *supervisor.Supervisor) (*grpc.Server, error) { - // TODO: We should use TLS. - // TODO: Add an option for the SocketGroup. sockets, err := listeners.Init(protocol, address, "", nil) if err != nil { return nil, err