Documentation
¶
Overview ¶
Package pprof exposes Go runtime profiling endpoints (CPU profile, heap, goroutine, block, mutex, etc.) over HTTP via the standard library's net/http/pprof package.
This is the profiling counterpart of the health check handler. It is not a middleware — it is an http.Handler intended to be registered on a dedicated route, typically under "/debug/pprof".
Usage:
// Register on the HTTP server:
h := pprof.NewHandler()
srv.GET("/debug/pprof/*", h.ServeHTTP)
// Or with a custom prefix:
h := pprof.NewHandler(pprof.WithPrefix("/debug/pprof"))
srv.GET("/debug/pprof/*", h.ServeHTTP)
Security note: profiling endpoints leak internal runtime data. In production, protect them with authentication middleware or restrict access to internal networks only.
Index ¶
Constants ¶
const DefaultPrefix = "/debug/pprof"
DefaultPrefix is the default URL prefix for pprof endpoints.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler exposes Go runtime profiling endpoints over HTTP.
It internally uses an http.ServeMux to register the standard pprof handlers: index, cmdline, profile (CPU), symbol, trace, and the individual profile pages (heap, goroutine, block, mutex, allocs, threadcreate).
func NewHandler ¶
NewHandler creates a Handler that serves pprof endpoints under the configured prefix.
func (*Handler) Routes ¶
Routes returns the list of full endpoint paths exposed by this handler. Useful for documentation or automated route registration.
func (*Handler) ServeHTTP ¶
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
type Option ¶
type Option func(*options)
Option configures the pprof handler.
func WithPrefix ¶
WithPrefix sets the URL prefix under which pprof endpoints are exposed. Default: "/debug/pprof".
The prefix should match the route registered on the HTTP server, e.g. if the server registers "/debug/pprof/*", the prefix should be "/debug/pprof".