pprof

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

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

View Source
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.

func (*Config) ValidateWithContext

func (c *Config) ValidateWithContext(ctx context.Context) error

ValidateWithContext validates the config struct.

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.

func (*Provider) Shutdown

func (p *Provider) Shutdown(ctx context.Context) error

func (*Provider) Start

func (p *Provider) Start(ctx context.Context) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL