composables

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 composables provides reusable reactive logic for the profiler example.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBytes

func FormatBytes(bytes uint64) string

FormatBytes formats bytes into a human-readable string.

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration into a human-readable string.

Types

type ProfilerComposable

type ProfilerComposable struct {
	// Profiler is the underlying profiler instance
	Profiler *profiler.Profiler

	// IsRunning indicates if profiling is active
	IsRunning *bubbly.Ref[bool]

	// Metrics holds the current profiler metrics
	Metrics *bubbly.Ref[*ProfilerMetrics]

	// StartTime is when profiling started
	StartTime *bubbly.Ref[time.Time]

	// Duration is computed from StartTime
	Duration *bubbly.Computed[interface{}]

	// LastExport holds the last export filename (empty if none)
	LastExport *bubbly.Ref[string]

	// Start begins profiling
	Start func()

	// Stop ends profiling
	Stop func()

	// Toggle switches profiling state
	Toggle func()

	// Reset clears all metrics
	Reset func()

	// ExportReport saves the report to a file
	ExportReport func(filename string) error

	// RefreshMetrics updates the metrics from the profiler
	RefreshMetrics func()
	// contains filtered or unexported fields
}

ProfilerComposable encapsulates profiler logic with reactive state. This follows the Vue-like composable pattern for reusable logic.

func UseProfiler

func UseProfiler(ctx *bubbly.Context) *ProfilerComposable

UseProfiler creates a reusable profiler composable with reactive state. This demonstrates the composable pattern - reusable logic that can be shared across components, similar to Vue's Composition API.

Example:

profilerComp := composables.UseProfiler(ctx)
profilerComp.Start()
// ... later
profilerComp.RefreshMetrics()
metrics := profilerComp.Metrics.GetTyped()

type ProfilerMetrics

type ProfilerMetrics struct {
	FPS             float64
	FrameTime       time.Duration
	MemoryUsage     uint64
	GoroutineCount  int
	RenderCount     int
	BottleneckCount int
	SampleCount     int
}

ProfilerMetrics holds the current profiler metrics for display.

Jump to

Keyboard shortcuts

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