pprof

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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)
	}),
	PreExecute: 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