Documentation
¶
Overview ¶
Package profile provides pprof profile collection functionality. It connects to target services exposing /debug/pprof endpoints and retrieves CPU, heap, and block profiles for performance analysis.
Index ¶
- type CollectedProfile
- type Collector
- func (c *Collector) CheckPprofAvailable(ctx context.Context) error
- func (c *Collector) CollectBlock(ctx context.Context) (*CollectedProfile, error)
- func (c *Collector) CollectByType(ctx context.Context, profileType Type) (*CollectedProfile, error)
- func (c *Collector) CollectCPU(ctx context.Context) (*CollectedProfile, error)
- func (c *Collector) CollectGoroutine(ctx context.Context) (*CollectedProfile, error)
- func (c *Collector) CollectHeap(ctx context.Context) (*CollectedProfile, error)
- func (c *Collector) CollectSeries(ctx context.Context, profileType Type, interval time.Duration, maxSamples int) ([]*CollectedProfile, error)
- type CollectorConfig
- type Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CollectedProfile ¶
CollectedProfile represents a successfully collected profile.
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector handles retrieving pprof profiles from a target service.
func NewCollector ¶
func NewCollector(cfg CollectorConfig) (*Collector, error)
NewCollector creates a profile collector with the given configuration.
func (*Collector) CheckPprofAvailable ¶
CheckPprofAvailable verifies that pprof endpoints are accessible on the target.
func (*Collector) CollectBlock ¶
func (c *Collector) CollectBlock(ctx context.Context) (*CollectedProfile, error)
CollectBlock retrieves a blocking profile from the target service.
func (*Collector) CollectByType ¶
CollectByType dispatches to the appropriate collection method based on profile type.
func (*Collector) CollectCPU ¶
func (c *Collector) CollectCPU(ctx context.Context) (*CollectedProfile, error)
CollectCPU retrieves a CPU profile from the target service. The profile collection takes at least CPUDuration seconds.
func (*Collector) CollectGoroutine ¶
func (c *Collector) CollectGoroutine(ctx context.Context) (*CollectedProfile, error)
CollectGoroutine retrieves a goroutine profile from the target service.
func (*Collector) CollectHeap ¶
func (c *Collector) CollectHeap(ctx context.Context) (*CollectedProfile, error)
CollectHeap retrieves a heap memory profile from the target service.
func (*Collector) CollectSeries ¶
func (c *Collector) CollectSeries(ctx context.Context, profileType Type, interval time.Duration, maxSamples int) ([]*CollectedProfile, error)
CollectSeries collects samples of the given profile type at regular intervals. It stops when ctx is cancelled or maxSamples is reached (0 = unlimited). On context cancellation, it returns the samples collected so far (not an error).
type CollectorConfig ¶
type CollectorConfig struct {
TargetURL string
OutputDir string
CPUDuration time.Duration
Timeout time.Duration
}
CollectorConfig holds configuration for profile collection.
func DefaultCollectorConfig ¶
func DefaultCollectorConfig() CollectorConfig
DefaultCollectorConfig returns a CollectorConfig with sensible defaults.
type Type ¶
type Type string
Type represents the kind of pprof profile to collect.
const ( ProfileCPU Type = "profile" // CPU profile (requires duration parameter) ProfileHeap Type = "heap" // Heap memory profile ProfileBlock Type = "block" // Blocking profile ProfileGoroutine Type = "goroutine" // Goroutine profile )
Supported profile types.
func ParseProfileTypes ¶
ParseProfileTypes parses a comma-separated string of profile type names (e.g. "goroutine,heap") into a deduplicated slice of Type values.
func (Type) DisplayName ¶
DisplayName returns the user-facing name for a profile type. ProfileCPU's internal value is "profile" (the pprof endpoint), but users know it as "cpu".