From 4f86fa83324bf949c0ab8fed6b1436df1788b0c8 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 9 Jun 2017 21:01:50 +0200 Subject: [PATCH] cmd: support for pprof over http --- cmd/main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index bf91a56..9f39f09 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -10,6 +10,8 @@ import ( "golang.org/x/sys/unix" "io" "log" + "net/http" + _ "net/http/pprof" "os" "runtime/debug" "sync" @@ -45,9 +47,11 @@ func main() { app.Flags = []cli.Flag{ cli.StringFlag{Name: "config"}, cli.StringFlag{Name: "logfile"}, + cli.StringFlag{Name: "debug.pprof.http"}, } app.Before = func(c *cli.Context) (err error) { + // Logging if c.GlobalIsSet("logfile") { var logFile *os.File logFile, err = os.OpenFile(c.String("logfile"), os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) @@ -63,8 +67,16 @@ func main() { } else { logOut = os.Stderr } - defaultLog = log.New(logOut, "", logFlags) + + // CPU profiling + if c.GlobalIsSet("debug.pprof.http") { + go func() { + http.ListenAndServe(c.GlobalString("debug.pprof.http"), nil) + }() + } + + // Config if !c.GlobalIsSet("config") { return cli.NewExitError("config flag not set", 2) }