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
- Variables
- func RegisterHandlers(mux *http.ServeMux, prof *Profiler)
- type AggregatedAllocation
- type AggregatedCounter
- type AggregatedData
- type AggregatedTiming
- type Alert
- type AlertHandler
- type AllocationStats
- type Baseline
- type BenchmarkProfiler
- type BenchmarkStats
- type BottleneckDetector
- type BottleneckInfo
- type BottleneckThresholds
- type BottleneckType
- type CPUProfileData
- type CPUProfiler
- type CallNode
- type Category
- type Component
- type ComponentMetrics
- type ComponentSortField
- type ComponentTracker
- type CompositeHook
- type Config
- type CounterStats
- type CounterTracker
- type DataAggregator
- type DevToolsIntegration
- type EventType
- type ExportFormat
- type Exporter
- type FPSCalculator
- type FlameGraphGenerator
- type FrameInfo
- type HTTPHandler
- type HookAdapter
- type HotFunction
- type ImpactLevel
- type Instrumentor
- type KeyBinding
- type LeakDetector
- type LeakInfo
- type LeakThresholds
- type MemProfileData
- type MemoryProfiler
- type MemoryTracker
- type MetricCollector
- type MetricsSnapshot
- type MetricsUpdateCallback
- type Option
- type Pattern
- type PatternAnalyzer
- type PerformanceMetrics
- type Priority
- type ProfileData
- type Profiler
- type Recommendation
- type RecommendationEngine
- type RecommendationRule
- type RegressionInfo
- type RenderConfig
- type RenderProfiler
- type Report
- type ReportGenerator
- type Severity
- type StackAnalyzer
- type Summary
- type ThresholdConfig
- type ThresholdMonitor
- type TimedEvent
- type TimelineData
- type TimelineGenerator
- type TimingSnapshot
- type TimingStats
- type TimingTracker
Constants ¶
const ( EnvEnabled = profiler.EnvEnabled EnvSamplingRate = profiler.EnvSamplingRate EnvMaxSamples = profiler.EnvMaxSamples )
Environment variable names for configuration.
const ( DefaultSamplingRate = profiler.DefaultSamplingRate DefaultMaxSamples = profiler.DefaultMaxSamples DefaultUpdateInterval = profiler.DefaultUpdateInterval DefaultFPSWindowSize = profiler.DefaultFPSWindowSize )
Default configuration values.
const ( DefaultFlameGraphWidth = profiler.DefaultFlameGraphWidth DefaultTimelineWidth = profiler.DefaultTimelineWidth )
Default dimensions.
const (
DefaultMaxCPUProfileDuration = profiler.DefaultMaxCPUProfileDuration
)
Default limits.
Variables ¶
var ( ErrAlreadyStarted = profiler.ErrAlreadyStarted ErrCPUProfileActive = profiler.ErrCPUProfileActive ErrInvalidDuration = profiler.ErrInvalidDuration ErrEmptyPanelName = profiler.ErrEmptyPanelName ErrNilBenchmark = profiler.ErrNilBenchmark )
Common errors.
var ApplyOptions = profiler.ApplyOptions
ApplyOptions applies options to a configuration.
var ConfigFromEnv = profiler.ConfigFromEnv
ConfigFromEnv loads configuration from environment variables.
var DefaultBottleneckThresholds = profiler.DefaultBottleneckThresholds
DefaultBottleneckThresholds returns default bottleneck thresholds.
var DefaultConfig = profiler.DefaultConfig
DefaultConfig returns the default configuration.
var DefaultLeakThresholds = profiler.DefaultLeakThresholds
DefaultLeakThresholds returns default leak detection thresholds.
var DefaultRenderConfig = profiler.DefaultRenderConfig
DefaultRenderConfig returns the default render configuration.
var LoadBaseline = profiler.LoadBaseline
LoadBaseline loads a baseline from a file.
var New = profiler.New
New creates a new Profiler with the given options.
var NewBottleneckDetector = profiler.NewBottleneckDetector
NewBottleneckDetector creates a new bottleneck detector.
var NewBottleneckDetectorWithThresholds = profiler.NewBottleneckDetectorWithThresholds
NewBottleneckDetectorWithThresholds creates a detector with custom thresholds.
var NewCPUProfiler = profiler.NewCPUProfiler
NewCPUProfiler creates a new CPU profiler.
var NewComponentTracker = profiler.NewComponentTracker
NewComponentTracker creates a new component tracker.
var NewCompositeHook = profiler.NewCompositeHook
NewCompositeHook creates a new composite hook that forwards to multiple hooks.
var NewDataAggregator = profiler.NewDataAggregator
NewDataAggregator creates a new data aggregator.
var NewDevToolsIntegration = profiler.NewDevToolsIntegration
NewDevToolsIntegration creates a new DevTools integration.
var NewExporter = profiler.NewExporter
NewExporter creates a new exporter.
var NewFPSCalculator = profiler.NewFPSCalculator
NewFPSCalculator creates a new FPS calculator.
var NewFPSCalculatorWithWindowSize = profiler.NewFPSCalculatorWithWindowSize
NewFPSCalculatorWithWindowSize creates an FPS calculator with custom window.
var NewFlameGraphGenerator = profiler.NewFlameGraphGenerator
NewFlameGraphGenerator creates a new flame graph generator.
var NewFlameGraphGeneratorWithDimensions = profiler.NewFlameGraphGeneratorWithDimensions
NewFlameGraphGeneratorWithDimensions creates a generator with custom dimensions.
var NewHTTPHandler = profiler.NewHTTPHandler
NewHTTPHandler creates a new HTTP handler for the profiler.
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)
var NewInstrumentor = profiler.NewInstrumentor
NewInstrumentor creates a new instrumentor.
var NewLeakDetector = profiler.NewLeakDetector
NewLeakDetector creates a new leak detector.
var NewLeakDetectorWithThresholds = profiler.NewLeakDetectorWithThresholds
NewLeakDetectorWithThresholds creates a leak detector with custom thresholds.
var NewMemoryProfiler = profiler.NewMemoryProfiler
NewMemoryProfiler creates a new memory profiler.
var NewMemoryTracker = profiler.NewMemoryTracker
NewMemoryTracker creates a new memory tracker.
var NewMetricCollector = profiler.NewMetricCollector
NewMetricCollector creates a new metric collector.
var NewPatternAnalyzer = profiler.NewPatternAnalyzer
NewPatternAnalyzer creates a new pattern analyzer.
var NewPatternAnalyzerWithPatterns = profiler.NewPatternAnalyzerWithPatterns
NewPatternAnalyzerWithPatterns creates an analyzer with custom patterns.
var NewRecommendationEngine = profiler.NewRecommendationEngine
NewRecommendationEngine creates a new recommendation engine.
var NewRecommendationEngineWithRules = profiler.NewRecommendationEngineWithRules
NewRecommendationEngineWithRules creates an engine with custom rules.
var NewRenderProfiler = profiler.NewRenderProfiler
NewRenderProfiler creates a new render profiler.
var NewRenderProfilerWithConfig = profiler.NewRenderProfilerWithConfig
NewRenderProfilerWithConfig creates a render profiler with custom config.
var NewReportGenerator = profiler.NewReportGenerator
NewReportGenerator creates a new report generator.
var NewStackAnalyzer = profiler.NewStackAnalyzer
NewStackAnalyzer creates a new stack analyzer.
var NewThresholdMonitor = profiler.NewThresholdMonitor
NewThresholdMonitor creates a new threshold monitor.
var NewThresholdMonitorWithConfig = profiler.NewThresholdMonitorWithConfig
NewThresholdMonitorWithConfig creates a monitor with custom config.
var NewTimelineGenerator = profiler.NewTimelineGenerator
NewTimelineGenerator creates a new timeline generator.
var NewTimelineGeneratorWithDimensions = profiler.NewTimelineGeneratorWithDimensions
NewTimelineGeneratorWithDimensions creates a generator with custom dimensions.
var NewTimingTracker = profiler.NewTimingTracker
NewTimingTracker creates a new timing tracker.
var NewTimingTrackerWithMaxSamples = profiler.NewTimingTrackerWithMaxSamples
NewTimingTrackerWithMaxSamples creates a timing tracker with custom max samples.
var ServeCPUProfile = profiler.ServeCPUProfile
ServeCPUProfile is an HTTP handler for CPU profiles.
var ServeHeapProfile = profiler.ServeHeapProfile
ServeHeapProfile is an HTTP handler for heap profiles.
var WithEnabled = profiler.WithEnabled
WithEnabled enables or disables the profiler.
var WithMaxSamples = profiler.WithMaxSamples
WithMaxSamples sets the maximum number of samples to store.
var WithMinimalMetrics = profiler.WithMinimalMetrics
WithMinimalMetrics enables minimal metrics mode for production.
var WithSamplingRate = profiler.WithSamplingRate
WithSamplingRate sets the sampling rate (0.0-1.0).
Functions ¶
func RegisterHandlers ¶
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 AlertHandler ¶
type AlertHandler = profiler.AlertHandler
AlertHandler handles threshold violation alerts.
type AllocationStats ¶
type AllocationStats = profiler.AllocationStats
AllocationStats contains allocation statistics.
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 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 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 ExportFormat ¶
type ExportFormat = profiler.ExportFormat
ExportFormat specifies the export format.
type FPSCalculator ¶
type FPSCalculator = profiler.FPSCalculator
FPSCalculator calculates frames per second.
type FlameGraphGenerator ¶
type FlameGraphGenerator = profiler.FlameGraphGenerator
FlameGraphGenerator generates flame graph visualizations.
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 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 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 PatternAnalyzer ¶
type PatternAnalyzer = profiler.PatternAnalyzer
PatternAnalyzer analyzes performance patterns.
type PerformanceMetrics ¶
type PerformanceMetrics = profiler.PerformanceMetrics
PerformanceMetrics contains overall performance data.
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 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 StackAnalyzer ¶
type StackAnalyzer = profiler.StackAnalyzer
StackAnalyzer analyzes call stacks.
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 TimingTracker ¶
type TimingTracker = profiler.TimingTracker
TimingTracker tracks operation timing statistics.