profiling

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine manages capture, storage, and retrieval of runtime profiles.

func New

func New(profileDir string, maxProfiles int) *Engine

New creates a profiling engine that stores profiles in profileDir. maxProfiles controls the circular buffer size; oldest profiles are evicted when exceeded.

func (*Engine) Capture

func (e *Engine) Capture(service, profileType string, duration time.Duration) (*Profile, error)

Capture takes a runtime profile of the given type for the named service. Supported types: "cpu", "heap", "goroutine".

func (*Engine) FilePath

func (e *Engine) FilePath(id string) (string, error)

FilePath returns the file system path for a profile by ID.

func (*Engine) FindRelevant

func (e *Engine) FindRelevant(service string, around time.Time) []Profile

FindRelevant returns profiles for a service captured within 5 minutes of the given time.

func (*Engine) FoldedStacks

func (e *Engine) FoldedStacks(id string) (string, error)

FoldedStacks reads a captured pprof profile by ID and converts it to folded stack format suitable for flame graph generation. Each line has the format: "func1;func2;func3 count".

func (*Engine) Get

func (e *Engine) Get(id string) (*Profile, error)

Get returns a profile by ID.

func (*Engine) List

func (e *Engine) List(service string) ([]Profile, error)

List returns all profiles for a service. If service is empty, all profiles are returned.

type Profile

type Profile struct {
	ID         string        `json:"id"`
	Service    string        `json:"service"`
	Type       string        `json:"type"`
	FilePath   string        `json:"-"`
	CapturedAt time.Time     `json:"captured_at"`
	Duration   time.Duration `json:"duration,omitempty"`
	Size       int64         `json:"size_bytes"`
}

Profile represents a captured runtime profile (CPU, heap, goroutine).

type SpanStack

type SpanStack struct {
	Point  string       `json:"point"`
	Frames []StackFrame `json:"frames"`
}

SpanStack captures the call stack at a named point.

func CaptureStack

func CaptureStack(point string, skip int) SpanStack

CaptureStack captures the current goroutine's call stack at the named point. skip controls how many additional caller frames to skip (0 = caller of CaptureStack).

type StackFrame

type StackFrame struct {
	Function string `json:"function"`
	File     string `json:"file"`
	Line     int    `json:"line"`
	Module   string `json:"module,omitempty"`
}

StackFrame represents a single frame in a call stack.

type Symbolizer

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

Symbolizer parses Source Map v3 format and resolves generated file:line to original file:line.

func NewSymbolizer

func NewSymbolizer() *Symbolizer

NewSymbolizer returns an initialised Symbolizer.

func (*Symbolizer) LoadMap

func (s *Symbolizer) LoadMap(filePath string, mapData []byte) error

LoadMap loads a source map for the given generated file path.

func (*Symbolizer) Symbolicate

func (s *Symbolizer) Symbolicate(frames []StackFrame) []StackFrame

Symbolicate resolves generated frames to original source locations. Frames without matching source maps pass through unchanged.

Jump to

Keyboard shortcuts

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