pprof.go 464 B

123456789101112131415161718192021222324252627
  1. package pprof
  2. import (
  3. "net"
  4. "net/http"
  5. //nolint:gosec
  6. _ "net/http/pprof"
  7. "strconv"
  8. "time"
  9. )
  10. var pprofMux *http.ServeMux
  11. func init() {
  12. pprofMux = http.DefaultServeMux
  13. http.DefaultServeMux = http.NewServeMux()
  14. }
  15. func RunPprofServer(port int) error {
  16. server := http.Server{
  17. Addr: net.JoinHostPort("127.0.0.1", strconv.Itoa(port)),
  18. Handler: pprofMux,
  19. ReadHeaderTimeout: time.Second * 5,
  20. }
  21. return server.ListenAndServe()
  22. }