Skip to content

Commit

Permalink
chore(allsrv): add pprof routes
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jsteenb2 committed Jul 10, 2024
1 parent 32a17c0 commit ddafbe2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions allsrv/cmd/allsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"log/slog"
"net/http"
"net/http/pprof"
"os"
"strings"
"time"
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit ddafbe2

Please sign in to comment.