profiler

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(logger *slog.Logger, enabled bool)

Init initializes the global profiler

func InitFromEnv

func InitFromEnv(logger *slog.Logger)

InitFromEnv initializes the global profiler using environment variables

func IsProfilingEnabled

func IsProfilingEnabled() bool

IsProfilingEnabled checks if profiling is enabled via environment variables

func Start

func Start(ctx context.Context, operation string) func(int, int64) *Profile

Start begins timing using the global profiler

Types

type Profile

type Profile struct {
	Operation    string        `json:"operation"`
	Duration     time.Duration `json:"duration_ns"`
	MemoryBefore uint64        `json:"memory_before_bytes"`
	MemoryAfter  uint64        `json:"memory_after_bytes"`
	MemoryDelta  int64         `json:"memory_delta_bytes"`
	LinesCount   int           `json:"lines_count,omitempty"`
	BytesCount   int64         `json:"bytes_count,omitempty"`
	Timestamp    time.Time     `json:"timestamp"`
}

Profile represents performance metrics for an operation

func ProfileFunc

func ProfileFunc(ctx context.Context, operation string, fn func() error) (*Profile, error)

ProfileFunc profiles a function using the global profiler

func ProfileFuncWithMetrics

func ProfileFuncWithMetrics(ctx context.Context, operation string, fn func() (int, int64, error)) (*Profile, error)

ProfileFuncWithMetrics profiles a function with metrics using the global profiler

func (*Profile) String

func (p *Profile) String() string

String returns a human-readable representation of the profile

type Profiler

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

Profiler provides minimal performance profiling capabilities

func New

func New(logger *slog.Logger, enabled bool) *Profiler

New creates a new Profiler instance

func (*Profiler) ProfileFunc

func (p *Profiler) ProfileFunc(ctx context.Context, operation string, fn func() error) (*Profile, error)

ProfileFunc profiles a function execution

func (*Profiler) ProfileFuncWithMetrics

func (p *Profiler) ProfileFuncWithMetrics(ctx context.Context, operation string, fn func() (int, int64, error)) (*Profile, error)

ProfileFuncWithMetrics profiles a function execution and captures additional metrics

func (*Profiler) Start

func (p *Profiler) Start(ctx context.Context, operation string) func(lines int, bytes int64) *Profile

Start begins timing an operation and returns a function to complete the profiling

Jump to

Keyboard shortcuts

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