Created
March 22, 2023 16:05
-
-
Save jwhonce/c0d75530f50fc45f5e3c94b0b3b11d80 to your computer and use it in GitHub Desktop.
Podman API pprof endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setupPprof enables pprof default endpoints | |
// Note: These endpoints and the podman flag --cpu-profile are mutually exclusive | |
// | |
// Examples: | |
// #1 go tool pprof -http localhost:8889 localhost:8888/debug/pprof/heap?seconds=120 | |
// Note: web page will only render after a sample has been recorded | |
// #2 curl http://localhost:8888/debug/pprof/heap > heap.pprof && go tool pprof heap.pprof | |
func (s *APIServer) setupPprof() { | |
if s.PProfAddr == "" { | |
return | |
} | |
logrus.Infof("pprof service listening on %q", s.PProfAddr) | |
go func() { | |
old := runtime.SetMutexProfileFraction(1) | |
defer runtime.SetMutexProfileFraction(old) | |
runtime.SetBlockProfileRate(1) | |
defer runtime.SetBlockProfileRate(0) | |
router := mux.NewRouter() | |
router.PathPrefix("/debug/pprof/").HandlerFunc(pprof.Index) | |
err := http.ListenAndServe(s.PProfAddr, router) | |
if err != nil && err != http.ErrServerClosed { | |
logrus.Warnf("pprof service failed: %v", err) | |
} | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment