Skip to content

Commit

Permalink
feature: setup profiler and don't bother to enable debug level log
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Yang <[email protected]>
  • Loading branch information
yyb196 committed Apr 11, 2018
1 parent 204c39c commit 655d6bb
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apis/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions pkg/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 655d6bb

Please sign in to comment.