From 5851e7450cd5b3c99a2992d40f1a401097b6714e Mon Sep 17 00:00:00 2001 From: Johnny Steenbergen Date: Sun, 7 Jul 2024 15:15:49 -0500 Subject: [PATCH] chore(allsrv): add pprof routes One last bit of important data we're missing is our profiling. This can be applied at any time in the development. Its added here last because there is already a lot to cover before thi. However, with these endpoints, you can create profiles that will breakdown difference performance characteristics of your system. One of the beautiful things here is you can grab the profiles ad-hoc or create a recurring drop to grab profiles at different intervals. Regardless when or how you do it, it all goes through the HTTP API :chef_kiss:. See the references below for a a number of good resources for [pprof](https://pkg.go.dev/runtime/pprof). Refs: [pprof tool package](https://pkg.go.dev/runtime/pprof) Refs: [pprof HTTP integration](https://pkg.go.dev/net/http/pprof) Refs: [Profiling Go Programs - Russ Cox](https://go.dev/blog/pprof) --- allsrv/cmd/allsrv/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/allsrv/cmd/allsrv/main.go b/allsrv/cmd/allsrv/main.go index ba74c36..72275e0 100644 --- a/allsrv/cmd/allsrv/main.go +++ b/allsrv/cmd/allsrv/main.go @@ -6,6 +6,7 @@ import ( "errors" "log/slog" "net/http" + "net/http/pprof" "os" "strings" "time" @@ -36,6 +37,13 @@ func main() { } mux := http.NewServeMux() + + // Register pprof handlers + 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) selectedSVR := strings.TrimSpace(strings.ToLower(os.Getenv("ALLSRV_SERVER"))) if selectedSVR != "v2" {