Refactor HTTP profiling and flag handling

- hardcode the base path for profiling endpoints to '/debug/pprof/'
- change profiling flag 'httprof_path' to boolean 'http_pprof'
  (because of the above)
- remove redundant profiling endpoint registrations (handled by pprof.Index)
- move profiling registration log after actual registration
- make profiling registration log more descriptive
- use utils.Logger instead of log.Print for the log mentioned above
- refactor flags test into a table test (adding also verification for default
  flag values)
- change 'scheduledShutdown' flag type from string to time.Duration (to avoid
  unnecessary time parsing)
- revise flags usage descriptions
- rename flag 'singlecpu' to 'singleCPU'
- switch to 'ExitOnError' for flag parsing to simplify error handling and
  automatically handle 'ErrHelp' by exiting with status 0 when help is
  requested and status 2 for other parsing errors. Before the following error
  log would have been received:
  '<InitS> error received: <flag: help requested>, exiting!'
- update cgr-engine documentation
This commit is contained in:
ionutboangiu
2024-07-17 23:47:06 +03:00
committed by Dan Christian Bogos
parent 9eeee38824
commit 958aa267cf
6 changed files with 183 additions and 155 deletions

View File

@@ -182,26 +182,17 @@ func (s *Server) handleRequest(w http.ResponseWriter, r *http.Request) {
io.Copy(w, res)
}
func registerProfiler(addr string, mux *http.ServeMux) {
mux.HandleFunc(addr, pprof.Index)
mux.HandleFunc(addr+"cmdline", pprof.Cmdline)
mux.HandleFunc(addr+"profile", pprof.Profile)
mux.HandleFunc(addr+"symbol", pprof.Symbol)
mux.HandleFunc(addr+"trace", pprof.Trace)
mux.Handle(addr+"goroutine", pprof.Handler("goroutine"))
mux.Handle(addr+"heap", pprof.Handler("heap"))
mux.Handle(addr+"threadcreate", pprof.Handler("threadcreate"))
mux.Handle(addr+"block", pprof.Handler("block"))
mux.Handle(addr+"allocs", pprof.Handler("allocs"))
mux.Handle(addr+"mutex", pprof.Handler("mutex"))
func registerProfiler(mux *http.ServeMux) {
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)
}
func (s *Server) RegisterProfiler(addr string) {
if addr[len(addr)-1] != '/' {
addr = addr + "/"
}
registerProfiler(addr, s.httpMux)
registerProfiler(addr, s.httpsMux)
func (s *Server) RegisterProfiler() {
registerProfiler(s.httpMux)
registerProfiler(s.httpsMux)
}
func (s *Server) ServeHTTP(addr string, jsonRPCURL string, wsRPCURL string,

View File

@@ -99,7 +99,7 @@ func TestRegisterProfiler(t *testing.T) {
caps := engine.NewCaps(0, utils.MetaBusy)
rcv := NewServer(caps)
rcv.RegisterProfiler("/test_prefix")
rcv.RegisterProfiler()
rcv.StopBiRPC()
}