Documentation
¶
Overview ¶
Package pprof implements profiling.Provider by serving net/http/pprof from a dedicated HTTP server.
This endpoint is not authenticated ¶
The server listens on its own port (6060 by default) and serves /debug/pprof/* to anyone who can reach it, with no credential of any kind. Everything there is sensitive to some degree — a heap profile carries live allocation shapes, /debug/pprof/cmdline returns the process's arguments, and a CPU profile blocks for its whole duration, which anyone can request repeatedly. So the port belongs on a loopback interface or behind whatever the deployment uses to keep an admin port private. It must not be published alongside the service's own listener.
Profiles are pulled, not pushed: somebody has to fetch one while the interesting behavior is still happening. For a profile that exists after the fact, the pyroscope sibling pushes continuously instead.
Enabling the mutex or block profiles sets the runtime's sampling rate for the whole process, not for this server, and both cost something on every contended lock. They are off by default for that reason.
Start returns as soon as the listener goroutine is launched, so it does not report a port already in use; that failure arrives on the logger instead. Shutdown stops the server.
Index ¶
Constants ¶
const (
// DefaultPort is the default port for the pprof HTTP server.
DefaultPort = 6060
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Port uint16 `env:"PORT" json:"port,omitempty" yaml:"port,omitempty"`
EnableMutexProfile bool `env:"ENABLE_MUTEX_PROFILE" json:"enableMutexProfile,omitempty" yaml:"enableMutexProfile,omitempty"`
EnableBlockProfile bool `env:"ENABLE_BLOCK_PROFILE" json:"enableBlockProfile,omitempty" yaml:"enableBlockProfile,omitempty"`
}
Config holds pprof-specific profiling configuration.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider is the net/http/pprof profiling.Provider implementation. It is exported, and returned by NewProfilingProvider, so a caller who has chosen pprof can depend on that choice rather than on the interface every profiler shares.
func NewProfilingProvider ¶
func NewProfilingProvider(ctx context.Context, logger logging.Logger, cfg *Config) (*Provider, error)
NewProfilingProvider creates a pprof-based profiling provider that exposes /debug/pprof endpoints on an HTTP server.
A nil Config is an error rather than a noop, for the same reason the pyroscope provider refuses one: a provider that profiles nothing is indistinguishable from one that works until somebody goes looking for a profile.