From 655d6bbd518000546b532a4c3c0cf3d0f138a966 Mon Sep 17 00:00:00 2001 From: Frank Yang Date: Wed, 11 Apr 2018 22:25:37 +0800 Subject: [PATCH] feature: setup profiler and don't bother to enable debug level log Signed-off-by: Frank Yang --- apis/server/router.go | 2 +- daemon/config/config.go | 3 +++ main.go | 5 ++++- pkg/debug/debug.go | 4 ---- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apis/server/router.go b/apis/server/router.go index f80ef7577..43cb06560 100644 --- a/apis/server/router.go +++ b/apis/server/router.go @@ -77,7 +77,7 @@ func initRoute(s *Server) http.Handler { r.Path(versionMatcher + "/metrics").Methods(http.MethodGet).Handler(prometheus.Handler()) r.Path("/metrics").Methods(http.MethodGet).Handler(prometheus.Handler()) - if s.Config.Debug { + if s.Config.Debug || s.Config.EnableProfiler { profilerSetup(r) } return r diff --git a/daemon/config/config.go b/daemon/config/config.go index 936da48b5..52291a5c5 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -82,6 +82,9 @@ type Config struct { // Labels is the metadata of daemon Labels []string `json:"labels,omitempty"` + + // EnableProfiler indicates whether pouchd setup profiler like pprof and stack dumping etc + EnableProfiler bool `json:"enableProfiler"` } // Validate validates the user input config. diff --git a/main.go b/main.go index a015c363b..b803ffd04 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "github.com/alibaba/pouch/daemon" "github.com/alibaba/pouch/daemon/config" "github.com/alibaba/pouch/lxcfs" + "github.com/alibaba/pouch/pkg/debug" "github.com/alibaba/pouch/pkg/exec" "github.com/alibaba/pouch/pkg/quota" "github.com/alibaba/pouch/pkg/utils" @@ -98,6 +99,7 @@ func setupFlags(cmd *cobra.Command) { flagSet.StringVar(&cfg.CgroupParent, "cgroup-parent", "default", "Set parent cgroup for all containers") flagSet.StringVar(&cfg.PluginPath, "plugin", "", "Set the path where plugin shared library file put") flagSet.StringSliceVar(&cfg.Labels, "label", []string{}, "Set metadata for Pouch daemon") + flagSet.BoolVar(&cfg.EnableProfiler, "enable-profiler", false, "Set if pouchd setup profiler") } // parse flags @@ -127,10 +129,11 @@ func runDaemon() error { } // import debugger tools for pouch when in debug mode. - if cfg.Debug { + if cfg.Debug || cfg.EnableProfiler { if err := agent.Listen(agent.Options{}); err != nil { logrus.Fatal(err) } + debug.SetupDumpStackTrap() } // initialize home dir. diff --git a/pkg/debug/debug.go b/pkg/debug/debug.go index aeaf9ab9e..f90d9f8df 100644 --- a/pkg/debug/debug.go +++ b/pkg/debug/debug.go @@ -9,10 +9,6 @@ import ( "github.com/sirupsen/logrus" ) -func init() { - SetupDumpStackTrap() -} - // SetupDumpStackTrap setups signal trap to dump stack. func SetupDumpStackTrap() { c := make(chan os.Signal, 1)