4 ms·
One thing I find frustrating about the net/http/pprof package is its init method, which does: http.Handle("/debug/pprof/", http.HandlerFunc(Index)) htt
by collinvandyck76 13y ago
One thing I find frustrating about the net/http/pprof package is its init method, which does:
http.Handle("/debug/pprof/", http.HandlerFunc(Index))
http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
In my particular case, I wanted all normal application traffic to be handled by my 8080 handler, and the /debug/* traffic handled by another listener on port 6060. Even if I explicitly link the above handler functions into my port 6060 ServeMux, because of the init() method it still registers across all of my handlers. I.e. port 8080 and 6060 both respond to, for example, /debug/pprof/cmdline.
- scarboy 13y agonet/http/pprof/pprof.go is just some boilerplate around the built in profiling functions. Copy it into your application and use your own init function.
- stevvooe 13y agoCreate a separate ServeMux for your application and let the utilities register to the DefaultServeMux via init (and you can even register your own!). Bind the DefaultServeMux to the debug port (6060) using http.ListenAndServe(debugPort, nil) and bind your app to its port (8080) with http.ListenAndServe(appPort, appMux).
- collinvandyck76 13y agoThis worked great, thanks.