From 99f9b697165f1f081499b45b7789508dcf0c2553 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Sat, 30 Mar 2013 10:33:10 -0700 Subject: [PATCH] Add debug infos in CmdInfo to know the amount of fds and goroutines in use --- commands.go | 6 ++++++ utils.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/commands.go b/commands.go index b48aa4af9b..891d3d10c6 100644 --- a/commands.go +++ b/commands.go @@ -203,6 +203,12 @@ func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string len(srv.runtime.List()), VERSION, imgcount) + + if !rcli.DEBUG_FLAG { + return nil + } + fmt.Fprintf(stdout, "debug mode enabled\n") + fmt.Fprintf(stdout, "fds: %d\ngoroutines: %d\n", getTotalUsedFds(), runtime.NumGoroutine()) return nil } diff --git a/utils.go b/utils.go index fbbad34081..3c6c3c91ee 100644 --- a/utils.go +++ b/utils.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/dotcloud/docker/rcli" "io" + "io/ioutil" "net/http" "os" "os/exec" @@ -260,3 +261,12 @@ func (w *writeBroadcaster) Close() error { func newWriteBroadcaster() *writeBroadcaster { return &writeBroadcaster{list.New()} } + +func getTotalUsedFds() int { + if fds, err := ioutil.ReadDir(fmt.Sprintf("/proc/%d/fd", os.Getpid())); err != nil { + Debugf("Error opening /proc/%d/fd: %s", os.Getpid(), err) + } else { + return len(fds) + } + return -1 +}