profiler

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package profiler provides comprehensive performance profiling for BubblyUI applications.

The profiler enables runtime performance analysis, CPU and memory profiling, rendering benchmarks, component performance tracking, and optimization recommendations. It integrates with Go's built-in pprof tools and operates with minimal overhead (< 3% when enabled, < 0.1% when disabled).

This package is an alias for github.com/newbpydev/bubblyui/pkg/bubbly/profiler, providing a cleaner import path for users.

Quick Start

import "github.com/newbpydev/bubblyui/profiler"

func main() {
    prof := profiler.New(profiler.WithEnabled(true))
    prof.Start()
    defer prof.Stop()

    // Run your BubblyUI application
    tea.NewProgram(app).Run()

    // Generate performance report
    report := prof.GenerateReport()
    exporter := profiler.NewExporter()
    exporter.ExportHTML(report, "performance-report.html")
}

Features

  • CPU and memory profiling with pprof integration
  • FPS and render timing tracking
  • Component performance metrics
  • Memory leak detection
  • Bottleneck detection and recommendations
  • Flame graph generation
  • Timeline visualization
  • HTTP handlers for remote profiling

Index

Constants

View Source
const (
	EnvEnabled      = profiler.EnvEnabled
	EnvSamplingRate = profiler.EnvSamplingRate
	EnvMaxSamples   = profiler.EnvMaxSamples
)

Environment variable names for configuration.

View Source
const (
	DefaultSamplingRate   = profiler.DefaultSamplingRate
	DefaultMaxSamples     = profiler.DefaultMaxSamples
	DefaultUpdateInterval = profiler.DefaultUpdateInterval
	DefaultFPSWindowSize  = profiler.DefaultFPSWindowSize
)

Default configuration values.

View Source
const (
	DefaultFlameGraphWidth = profiler.DefaultFlameGraphWidth
	DefaultTimelineWidth   = profiler.DefaultTimelineWidth
)

Default dimensions.

View Source
const (
	DefaultMaxCPUProfileDuration = profiler.DefaultMaxCPUProfileDuration
)

Default limits.

Variables

View Source
var (
	ErrAlreadyStarted   = profiler.ErrAlreadyStarted
	ErrCPUProfileActive = profiler.ErrCPUProfileActive
	ErrInvalidDuration  = profiler.ErrInvalidDuration
	ErrEmptyPanelName   = profiler.ErrEmptyPanelName
	ErrNilBenchmark     = profiler.ErrNilBenchmark
)

Common errors.

View Source
var ApplyOptions = profiler.ApplyOptions

ApplyOptions applies options to a configuration.

View Source
var ConfigFromEnv = profiler.ConfigFromEnv

ConfigFromEnv loads configuration from environment variables.

View Source
var DefaultBottleneckThresholds = profiler.DefaultBottleneckThresholds

DefaultBottleneckThresholds returns default bottleneck thresholds.

View Source
var DefaultConfig = profiler.DefaultConfig

DefaultConfig returns the default configuration.

View Source
var DefaultLeakThresholds = profiler.DefaultLeakThresholds

DefaultLeakThresholds returns default leak detection thresholds.

View Source
var DefaultRenderConfig = profiler.DefaultRenderConfig

DefaultRenderConfig returns the default render configuration.

View Source
var LoadBaseline = profiler.LoadBaseline

LoadBaseline loads a baseline from a file.

New creates a new Profiler with the given options.

View Source
var NewBottleneckDetector = profiler.NewBottleneckDetector

NewBottleneckDetector creates a new bottleneck detector.

View Source
var NewBottleneckDetectorWithThresholds = profiler.NewBottleneckDetectorWithThresholds

NewBottleneckDetectorWithThresholds creates a detector with custom thresholds.

View Source
var NewCPUProfiler = profiler.NewCPUProfiler

NewCPUProfiler creates a new CPU profiler.

View Source
var NewComponentTracker = profiler.NewComponentTracker

NewComponentTracker creates a new component tracker.

View Source
var NewCompositeHook = profiler.NewCompositeHook

NewCompositeHook creates a new composite hook that forwards to multiple hooks.

View Source
var NewDataAggregator = profiler.NewDataAggregator

NewDataAggregator creates a new data aggregator.

View Source
var NewDevToolsIntegration = profiler.NewDevToolsIntegration

NewDevToolsIntegration creates a new DevTools integration.

View Source
var NewExporter = profiler.NewExporter

NewExporter creates a new exporter.

View Source
var NewFPSCalculator = profiler.NewFPSCalculator

NewFPSCalculator creates a new FPS calculator.

View Source
var NewFPSCalculatorWithWindowSize = profiler.NewFPSCalculatorWithWindowSize

NewFPSCalculatorWithWindowSize creates an FPS calculator with custom window.

View Source
var NewFlameGraphGenerator = profiler.NewFlameGraphGenerator

NewFlameGraphGenerator creates a new flame graph generator.

View Source
var NewFlameGraphGeneratorWithDimensions = profiler.NewFlameGraphGeneratorWithDimensions

NewFlameGraphGeneratorWithDimensions creates a generator with custom dimensions.

View Source
var NewHTTPHandler = profiler.NewHTTPHandler

NewHTTPHandler creates a new HTTP handler for the profiler.

View Source
var NewHookAdapter = profiler.NewHookAdapter

NewHookAdapter creates a new profiler hook adapter. Use this to integrate the profiler with the framework's hook system.

Example:

prof := profiler.New(profiler.WithEnabled(true))
hookAdapter := profiler.NewHookAdapter(prof)
prof.SetHookAdapter(hookAdapter)
View Source
var NewInstrumentor = profiler.NewInstrumentor

NewInstrumentor creates a new instrumentor.

View Source
var NewLeakDetector = profiler.NewLeakDetector

NewLeakDetector creates a new leak detector.

View Source
var NewLeakDetectorWithThresholds = profiler.NewLeakDetectorWithThresholds

NewLeakDetectorWithThresholds creates a leak detector with custom thresholds.

View Source
var NewMemoryProfiler = profiler.NewMemoryProfiler

NewMemoryProfiler creates a new memory profiler.

View Source
var NewMemoryTracker = profiler.NewMemoryTracker

NewMemoryTracker creates a new memory tracker.

View Source
var NewMetricCollector = profiler.NewMetricCollector

NewMetricCollector creates a new metric collector.

View Source
var NewPatternAnalyzer = profiler.NewPatternAnalyzer

NewPatternAnalyzer creates a new pattern analyzer.

View Source
var NewPatternAnalyzerWithPatterns = profiler.NewPatternAnalyzerWithPatterns

NewPatternAnalyzerWithPatterns creates an analyzer with custom patterns.

View Source
var NewRecommendationEngine = profiler.NewRecommendationEngine

NewRecommendationEngine creates a new recommendation engine.

View Source
var NewRecommendationEngineWithRules = profiler.NewRecommendationEngineWithRules

NewRecommendationEngineWithRules creates an engine with custom rules.

View Source
var NewRenderProfiler = profiler.NewRenderProfiler

NewRenderProfiler creates a new render profiler.

View Source
var NewRenderProfilerWithConfig = profiler.NewRenderProfilerWithConfig

NewRenderProfilerWithConfig creates a render profiler with custom config.

View Source
var NewReportGenerator = profiler.NewReportGenerator

NewReportGenerator creates a new report generator.

View Source
var NewStackAnalyzer = profiler.NewStackAnalyzer

NewStackAnalyzer creates a new stack analyzer.

View Source
var NewThresholdMonitor = profiler.NewThresholdMonitor

NewThresholdMonitor creates a new threshold monitor.

View Source
var NewThresholdMonitorWithConfig = profiler.NewThresholdMonitorWithConfig

NewThresholdMonitorWithConfig creates a monitor with custom config.

View Source
var NewTimelineGenerator = profiler.NewTimelineGenerator

NewTimelineGenerator creates a new timeline generator.

View Source
var NewTimelineGeneratorWithDimensions = profiler.NewTimelineGeneratorWithDimensions

NewTimelineGeneratorWithDimensions creates a generator with custom dimensions.

View Source
var NewTimingTracker = profiler.NewTimingTracker

NewTimingTracker creates a new timing tracker.

View Source
var NewTimingTrackerWithMaxSamples = profiler.NewTimingTrackerWithMaxSamples

NewTimingTrackerWithMaxSamples creates a timing tracker with custom max samples.

View Source
var ServeCPUProfile = profiler.ServeCPUProfile

ServeCPUProfile is an HTTP handler for CPU profiles.

View Source
var ServeHeapProfile = profiler.ServeHeapProfile

ServeHeapProfile is an HTTP handler for heap profiles.

View Source
var WithEnabled = profiler.WithEnabled

WithEnabled enables or disables the profiler.

View Source
var WithMaxSamples = profiler.WithMaxSamples

WithMaxSamples sets the maximum number of samples to store.

View Source
var WithMinimalMetrics = profiler.WithMinimalMetrics

WithMinimalMetrics enables minimal metrics mode for production.

View Source
var WithSamplingRate = profiler.WithSamplingRate

WithSamplingRate sets the sampling rate (0.0-1.0).

Functions

func RegisterHandlers

func RegisterHandlers(mux *http.ServeMux, prof *Profiler)

RegisterHandlers registers profiler handlers with an HTTP mux.

Types

type AggregatedAllocation

type AggregatedAllocation = profiler.AggregatedAllocation

AggregatedAllocation contains aggregated allocation data.

type AggregatedCounter

type AggregatedCounter = profiler.AggregatedCounter

AggregatedCounter contains aggregated counter data.

type AggregatedData

type AggregatedData = profiler.AggregatedData

AggregatedData contains aggregated profiling data.

type AggregatedTiming

type AggregatedTiming = profiler.AggregatedTiming

AggregatedTiming contains aggregated timing data.

type Alert

type Alert = profiler.Alert

Alert represents a threshold violation alert.

type AlertHandler

type AlertHandler = profiler.AlertHandler

AlertHandler handles threshold violation alerts.

type AllocationStats

type AllocationStats = profiler.AllocationStats

AllocationStats contains allocation statistics.

type Baseline

type Baseline = profiler.Baseline

Baseline contains baseline performance data for comparison.

type BenchmarkProfiler

type BenchmarkProfiler = profiler.BenchmarkProfiler

BenchmarkProfiler integrates with Go's testing.B.

func NewBenchmarkProfiler

func NewBenchmarkProfiler(b *testing.B) *BenchmarkProfiler

NewBenchmarkProfiler creates a benchmark profiler.

type BenchmarkStats

type BenchmarkStats = profiler.BenchmarkStats

BenchmarkStats contains benchmark statistics.

type BottleneckDetector

type BottleneckDetector = profiler.BottleneckDetector

BottleneckDetector identifies performance bottlenecks.

type BottleneckInfo

type BottleneckInfo = profiler.BottleneckInfo

BottleneckInfo describes a detected bottleneck.

type BottleneckThresholds

type BottleneckThresholds = profiler.BottleneckThresholds

BottleneckThresholds configures bottleneck detection sensitivity.

type BottleneckType

type BottleneckType = profiler.BottleneckType

BottleneckType categorizes the bottleneck.

type CPUProfileData

type CPUProfileData = profiler.CPUProfileData

CPUProfileData contains CPU profile results.

type CPUProfiler

type CPUProfiler = profiler.CPUProfiler

CPUProfiler manages CPU profiling.

type CallNode

type CallNode = profiler.CallNode

CallNode represents a node in a call tree.

type Category

type Category = profiler.Category

Category categorizes recommendations.

type Component

type Component = profiler.Component

Component interface for trackable components.

type ComponentMetrics

type ComponentMetrics = profiler.ComponentMetrics

ComponentMetrics contains metrics for a component.

type ComponentSortField

type ComponentSortField = profiler.ComponentSortField

ComponentSortField specifies how to sort components.

type ComponentTracker

type ComponentTracker = profiler.ComponentTracker

ComponentTracker tracks component performance metrics.

type CompositeHook

type CompositeHook = profiler.CompositeHook

CompositeHook multiplexes framework events to multiple hook implementations. This allows both DevTools and Profiler to receive events simultaneously.

Example:

// Get existing DevTools hook
devtoolsHook := bubbly.GetRegisteredHook()

// Create profiler hook
profilerHook := profiler.NewHookAdapter(prof)

// Combine them
composite := profiler.NewCompositeHook(devtoolsHook, profilerHook)
bubbly.RegisterHook(composite)

type Config

type Config = profiler.Config

Config holds profiler configuration.

type CounterStats

type CounterStats = profiler.CounterStats

CounterStats contains counter statistics.

type CounterTracker

type CounterTracker = profiler.CounterTracker

CounterTracker tracks counter metrics.

type DataAggregator

type DataAggregator = profiler.DataAggregator

DataAggregator aggregates profiling data.

type DevToolsIntegration

type DevToolsIntegration = profiler.DevToolsIntegration

DevToolsIntegration provides DevTools integration for the profiler.

type EventType

type EventType = profiler.EventType

EventType categorizes timeline events.

type ExportFormat

type ExportFormat = profiler.ExportFormat

ExportFormat specifies the export format.

type Exporter

type Exporter = profiler.Exporter

Exporter exports profiling data to various formats.

type FPSCalculator

type FPSCalculator = profiler.FPSCalculator

FPSCalculator calculates frames per second.

type FlameGraphGenerator

type FlameGraphGenerator = profiler.FlameGraphGenerator

FlameGraphGenerator generates flame graph visualizations.

type FrameInfo

type FrameInfo = profiler.FrameInfo

FrameInfo contains information about a rendered frame.

type HTTPHandler

type HTTPHandler = profiler.HTTPHandler

HTTPHandler provides HTTP endpoints for profiling.

type HookAdapter

type HookAdapter = profiler.HookAdapter

HookAdapter implements bubbly.FrameworkHook to collect profiling data. It tracks component render times and other metrics via the framework hook system.

type HotFunction

type HotFunction = profiler.HotFunction

HotFunction represents a function with high CPU usage.

type ImpactLevel

type ImpactLevel = profiler.ImpactLevel

ImpactLevel indicates the impact level.

type Instrumentor

type Instrumentor = profiler.Instrumentor

Instrumentor instruments code for profiling.

type KeyBinding

type KeyBinding = profiler.KeyBinding

KeyBinding defines a key binding for profiler controls.

type LeakDetector

type LeakDetector = profiler.LeakDetector

LeakDetector detects memory and goroutine leaks.

type LeakInfo

type LeakInfo = profiler.LeakInfo

LeakInfo describes a detected leak.

type LeakThresholds

type LeakThresholds = profiler.LeakThresholds

LeakThresholds configures leak detection sensitivity.

type MemProfileData

type MemProfileData = profiler.MemProfileData

MemProfileData contains memory profile results.

type MemoryProfiler

type MemoryProfiler = profiler.MemoryProfiler

MemoryProfiler manages memory profiling.

type MemoryTracker

type MemoryTracker = profiler.MemoryTracker

MemoryTracker tracks memory allocations over time.

type MetricCollector

type MetricCollector = profiler.MetricCollector

MetricCollector collects various metrics.

type MetricsSnapshot

type MetricsSnapshot = profiler.MetricsSnapshot

MetricsSnapshot contains a snapshot of all metrics.

type MetricsUpdateCallback

type MetricsUpdateCallback = profiler.MetricsUpdateCallback

MetricsUpdateCallback is called when metrics are updated.

type Option

type Option = profiler.Option

Option configures a Profiler.

func WithThreshold

func WithThreshold(operation string, threshold time.Duration) Option

WithThreshold sets a threshold for an operation.

type Pattern

type Pattern = profiler.Pattern

Pattern defines a performance pattern to detect.

type PatternAnalyzer

type PatternAnalyzer = profiler.PatternAnalyzer

PatternAnalyzer analyzes performance patterns.

type PerformanceMetrics

type PerformanceMetrics = profiler.PerformanceMetrics

PerformanceMetrics contains overall performance data.

type Priority

type Priority = profiler.Priority

Priority levels for recommendations.

type ProfileData

type ProfileData = profiler.ProfileData

ProfileData contains raw profile data.

type Profiler

type Profiler = profiler.Profiler

Profiler is the main performance profiler.

type Recommendation

type Recommendation = profiler.Recommendation

Recommendation describes an optimization suggestion.

type RecommendationEngine

type RecommendationEngine = profiler.RecommendationEngine

RecommendationEngine generates optimization recommendations.

type RecommendationRule

type RecommendationRule = profiler.RecommendationRule

RecommendationRule defines a rule for generating recommendations.

type RegressionInfo

type RegressionInfo = profiler.RegressionInfo

RegressionInfo describes a performance regression.

type RenderConfig

type RenderConfig = profiler.RenderConfig

RenderConfig configures render profiling.

type RenderProfiler

type RenderProfiler = profiler.RenderProfiler

RenderProfiler tracks render performance and FPS.

type Report

type Report = profiler.Report

Report contains a complete performance report.

type ReportGenerator

type ReportGenerator = profiler.ReportGenerator

ReportGenerator generates performance reports.

func NewReportGeneratorWithTemplate

func NewReportGeneratorWithTemplate(tmpl *template.Template) *ReportGenerator

NewReportGeneratorWithTemplate creates a generator with a custom template.

type Severity

type Severity = profiler.Severity

Severity indicates the severity of an issue.

type StackAnalyzer

type StackAnalyzer = profiler.StackAnalyzer

StackAnalyzer analyzes call stacks.

type Summary

type Summary = profiler.Summary

Summary contains a summary of profiling data.

type ThresholdConfig

type ThresholdConfig = profiler.ThresholdConfig

ThresholdConfig configures threshold monitoring.

type ThresholdMonitor

type ThresholdMonitor = profiler.ThresholdMonitor

ThresholdMonitor monitors for threshold violations.

type TimedEvent

type TimedEvent = profiler.TimedEvent

TimedEvent represents an event on the timeline.

type TimelineData

type TimelineData = profiler.TimelineData

TimelineData contains data for timeline rendering.

type TimelineGenerator

type TimelineGenerator = profiler.TimelineGenerator

TimelineGenerator generates timeline visualizations.

type TimingSnapshot

type TimingSnapshot = profiler.TimingSnapshot

TimingSnapshot is a point-in-time timing capture.

type TimingStats

type TimingStats = profiler.TimingStats

TimingStats contains timing statistics.

type TimingTracker

type TimingTracker = profiler.TimingTracker

TimingTracker tracks operation timing statistics.

Jump to

Keyboard shortcuts

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