We use the code below to register http endpoints and do pprof through http. However, we got almost empty output for a 30-seconds CPU profiling. Any suggestions on what we missed?
func pprofRouter(router *httprouter.Router) {
router.HandlerFunc(http.MethodGet, "/debug/pprof/", pprof.Index)
router.HandlerFunc(http.MethodGet, "/debug/pprof/cmdline", pprof.Cmdline)
router.HandlerFunc(http.MethodGet, "/debug/pprof/profile", pprof.Profile)
router.HandlerFunc(http.MethodGet, "/debug/pprof/symbol", pprof.Symbol)
router.HandlerFunc(http.MethodGet, "/debug/pprof/trace", pprof.Trace)
router.Handler(http.MethodGet, "/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handler(http.MethodGet, "/debug/pprof/heap", pprof.Handler("heap"))
router.Handler(http.MethodGet, "/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
router.Handler(http.MethodGet, "/debug/pprof/block", pprof.Handler("block"))
}
....
go func() {
theRouter := httprouter.New()
pprofRouter(theRouter)
profCorsHandler := cors.New(cors.Options{
AllowCredentials: true,
MaxAge: 60,
}).Handler(theRouter)
pprofServer := http.Server{
Addr: "localhost:8997",
Handler: profCorsHandler,
}
launchError := pprofServer.ListenAndServe()
if launchError != nil {
logrus.WithError(err)
}
}()