profiler

package
v1.198.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedProfileType is returned when an unsupported profile type is used.
	ErrUnsupportedProfileType = errors.New("unsupported profile type")
	// ErrStartCPUProfile is returned when CPU profiling fails to start.
	ErrStartCPUProfile = errors.New("failed to start CPU profile")
	// ErrStartTraceProfile is returned when trace profiling fails to start.
	ErrStartTraceProfile = errors.New("failed to start trace profile")
	// ErrCreateProfileFile is returned when profile file creation fails.
	ErrCreateProfileFile = errors.New("failed to create profile file")
)

Profiler-specific errors.

Functions

func IsValidProfileType

func IsValidProfileType(profileType ProfileType) bool

IsValidProfileType checks if the given profile type is supported.

Types

type Config

type Config struct {
	Enabled     bool        `json:"enabled" yaml:"enabled" mapstructure:"enabled"`
	Port        int         `json:"port" yaml:"port" mapstructure:"port"`
	Host        string      `json:"host" yaml:"host" mapstructure:"host"`
	File        string      `json:"file" yaml:"file" mapstructure:"file"`
	ProfileType ProfileType `json:"profile_type" yaml:"profile_type" mapstructure:"profile_type"`
}

Config holds the configuration for the profiler.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default profiler configuration.

type ProfileType

type ProfileType string

ProfileType represents the type of profile to collect.

const (
	// DefaultProfilerPort is the default port for the profiler server.
	DefaultProfilerPort = 6060
	// DefaultReadHeaderTimeout is the default timeout for reading request headers.
	DefaultReadHeaderTimeout = 10 * time.Second

	// ProfileTypeCPU collects CPU profile data.
	ProfileTypeCPU ProfileType = "cpu"
	// ProfileTypeHeap collects heap memory profile data.
	ProfileTypeHeap ProfileType = "heap"
	// ProfileTypeAllocs collects allocation profile data.
	ProfileTypeAllocs ProfileType = "allocs"
	// ProfileTypeGoroutine collects goroutine profile data.
	ProfileTypeGoroutine ProfileType = "goroutine"
	// ProfileTypeBlock collects blocking profile data.
	ProfileTypeBlock ProfileType = "block"
	// ProfileTypeMutex collects mutex contention profile data.
	ProfileTypeMutex ProfileType = "mutex"
	// ProfileTypeThreadCreate collects thread creation profile data.
	ProfileTypeThreadCreate ProfileType = "threadcreate"
	// ProfileTypeTrace collects execution trace data.
	ProfileTypeTrace ProfileType = "trace"
)

func GetSupportedProfileTypes

func GetSupportedProfileTypes() []ProfileType

GetSupportedProfileTypes returns a list of all supported profile types.

func ParseProfileType

func ParseProfileType(s string) (ProfileType, error)

ParseProfileType converts a string to ProfileType, with case-insensitive matching.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a pprof profiling server.

func New

func New(config Config) *Server

New creates a new profiler server with the given configuration.

func (*Server) GetAddress

func (p *Server) GetAddress() string

GetAddress returns the address the profiler server is listening on.

func (*Server) GetURL

func (p *Server) GetURL() string

GetURL returns the full URL to access the pprof web interface.

func (*Server) IsRunning

func (p *Server) IsRunning() bool

IsRunning returns true if the profiler (server or file-based) is currently running.

func (*Server) Start

func (p *Server) Start() error

Start starts the profiling server or file-based profiling if enabled.

func (*Server) Stop

func (p *Server) Stop() error

Stop stops the profiling server or file-based profiling.

Jump to

Keyboard shortcuts

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