summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/rr/cmd/pprof.go38
-rw-r--r--cmd/rr/cmd/root.go24
2 files changed, 24 insertions, 38 deletions
diff --git a/cmd/rr/cmd/pprof.go b/cmd/rr/cmd/pprof.go
deleted file mode 100644
index 3e06155c..00000000
--- a/cmd/rr/cmd/pprof.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package cmd
-
-import (
- "github.com/spf13/cobra"
- "log"
- "net/http"
- "net/http/pprof"
-)
-
-func init() {
- CLI.AddCommand(&cobra.Command{
- Use: "pprof",
- Short: "Profile RoadRunner service(s)",
- Example: "rr serve -d -v pprof http://localhost:6061",
- Run: runDebugServer,
- })
-}
-
-func runDebugServer(cmd *cobra.Command, args []string) {
- var address string = "http://localhost:6061"
- // guess that user set the address
- if len(args) > 0 {
- address = args[0]
- }
- mux := http.NewServeMux()
- mux.HandleFunc("/debug/pprof/", pprof.Index)
- mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
- mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
- mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
- mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
- srv := http.Server{
- Addr: address,
- Handler: mux,
- }
- if err := srv.ListenAndServe(); err != nil {
- log.Fatal(err)
- }
-}
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 515e6419..456cfc6a 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -26,6 +26,9 @@ import (
"github.com/spiral/roadrunner/cmd/util"
"github.com/spiral/roadrunner/service"
"github.com/spiral/roadrunner/service/limit"
+ "log"
+ "net/http"
+ "net/http/pprof"
"os"
)
@@ -116,8 +119,29 @@ func init() {
})
}
}
+
+ // if debug --> also run pprof service
+ if Debug {
+ go runDebugServer()
+ }
})
}
+func runDebugServer() {
+ mux := http.NewServeMux()
+ mux.HandleFunc("/debug/pprof/", pprof.Index)
+ mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
+ mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
+ mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
+ mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
+ srv := http.Server{
+ Addr: ":6061",
+ Handler: mux,
+ }
+
+ if err := srv.ListenAndServe(); err != nil {
+ log.Fatal(err)
+ }
+}
func configureLogger(format string) {
util.Colorize = false