pprof

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UseProfileFieldName is the command-line flag to enable pprof endpoints.
	UseProfileFieldName = "trace.pprof"

	// EndpointFieldName is the command-line flag for pprof endpoint path.
	EndpointFieldName = "server.http.routes.pprof"

	// UseProfileDefault disables pprof by default.
	UseProfileDefault = false

	// EndpointDefault is the default path for pprof endpoints.
	EndpointDefault = "/debug"
)

Variables

View Source
var Component = &component.Component{
	Dependencies: component.Components{
		chi.Component,
	},
	Init: component.StepFunc(func(container container.Container) error {
		return container.Provide(NewConfig)
	}),
	BindFlags: component.BindFlags(func(flagSet flag.FlagSet, container container.Container) error {
		return container.Invoke(func(config *Config) {
			flagSet.BoolVar(&config.UseProfile, UseProfileFieldName, UseProfileDefault, "if true, add debug path to routing")
			flagSet.StringVar(&config.Endpoint, EndpointFieldName, EndpointDefault, "path for debug endpoint")
		})
	}),
	Configuration: component.StepFunc(func(container container.Container) error {
		return container.Invoke(Configuration)
	}),
	Execute: component.StepFunc(func(container container.Container) error {
		return container.Invoke(func(config *Config, r http.Router, logger logger.Logger) {
			if config.UseProfile {
				logger.Infof("[chi.router] add pprof endpoint - '%s'", config.Endpoint)
				r.Mount(config.Endpoint, middleware.Profiler())
			}
		})
	}),
}

Component adds pprof debugging endpoints to the HTTP router when enabled. It depends on chi.Component for the router.

Usage:

compogo.WithComponents(
    http.Component,
    chi.Component,
    pprof.Component,
)

Enable with: --trace.pprof=true --server.http.routes.pprof=/debug

Functions

This section is empty.

Types

type Config

type Config struct {
	UseProfile bool
	Endpoint   string
}

Config holds the pprof configuration. It can be populated from command-line flags or config files.

func Configuration

func Configuration(config *Config, configurator configurator.Configurator) *Config

Configuration applies configuration values to the Config struct. It reads from the provided configurator and sets defaults if values are not present.

func NewConfig

func NewConfig() *Config

NewConfig creates a new Config instance with default values.

Jump to

Keyboard shortcuts

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