diff options
author | Valery Piashchynski <[email protected]> | 2020-02-11 16:48:48 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2020-02-11 16:48:48 +0300 |
commit | 1fd9dc00336e80c875081aac8d8b74dfaa65fd2b (patch) | |
tree | b07f055f20c1090b7ab04d07751975d9c5208a44 | |
parent | 7165d642978262130db2ca029a0597d5c77f6e8c (diff) |
Add pprof endpoint
-rw-r--r-- | cmd/rr/cmd/pprof.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/cmd/rr/cmd/pprof.go b/cmd/rr/cmd/pprof.go new file mode 100644 index 00000000..3e06155c --- /dev/null +++ b/cmd/rr/cmd/pprof.go @@ -0,0 +1,38 @@ +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) + } +} |