profile

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CollectedProfile

type CollectedProfile struct {
	Type     Type
	FilePath string
	Size     int64
	Duration time.Duration
}

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

func (c *Collector) CheckPprofAvailable(ctx context.Context) error

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

func (c *Collector) CollectByType(ctx context.Context, profileType Type) (*CollectedProfile, error)

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

func ParseProfileTypes(s string) ([]Type, error)

ParseProfileTypes parses a comma-separated string of profile type names (e.g. "goroutine,heap") into a deduplicated slice of Type values.

func (Type) DisplayName

func (t Type) DisplayName() string

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".

Jump to

Keyboard shortcuts

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