Table of Contents

Class PerformanceTracker

Namespace
SharpConsoleUI.Performance
Assembly
SharpConsoleUI.dll

Tracks and reports performance metrics for the console window system. Consolidates frame timing, FPS calculation, and dirty region tracking. Extracted from ConsoleWindowSystem and RenderCoordinator as part of Phase 1.3 refactoring.

public class PerformanceTracker
Inheritance
PerformanceTracker
Inherited Members

Constructors

PerformanceTracker(Func<ConsoleWindowSystemOptions>, Action<ConsoleWindowSystemOptions>, ILogService?, Action?)

Initializes a new instance of the PerformanceTracker class.

public PerformanceTracker(Func<ConsoleWindowSystemOptions> getOptions, Action<ConsoleWindowSystemOptions> setOptions, ILogService? logService = null, Action? onStatusCacheInvalidate = null)

Parameters

getOptions Func<ConsoleWindowSystemOptions>

Callback to get current options.

setOptions Action<ConsoleWindowSystemOptions>

Callback to update options.

logService ILogService

Optional logging service.

onStatusCacheInvalidate Action

Optional callback to invalidate status cache when metrics change.

Properties

CurrentDirtyChars

Gets the displayed dirty character count (held for visibility).

public int CurrentDirtyChars { get; }

Property Value

int

CurrentDirtyCount

Gets the current number of dirty windows.

public int CurrentDirtyCount { get; }

Property Value

int

CurrentFPS

Gets the current frames per second (FPS).

public double CurrentFPS { get; }

Property Value

double

CurrentFrameTimeMs

Gets the most recent frame time in milliseconds.

public double CurrentFrameTimeMs { get; }

Property Value

double

CurrentWindowCount

Gets the current window count.

public int CurrentWindowCount { get; }

Property Value

int

IsFrameRateLimitingEnabled

Gets whether frame rate limiting is currently enabled.

public bool IsFrameRateLimitingEnabled { get; }

Property Value

bool

IsPerformanceMetricsEnabled

Gets whether performance metrics are currently enabled.

public bool IsPerformanceMetricsEnabled { get; }

Property Value

bool

MinFrameTime

Gets the minimum frame time in milliseconds based on target FPS.

public double MinFrameTime { get; }

Property Value

double

TargetFPS

Gets the current target frames per second.

public int TargetFPS { get; }

Property Value

int

Methods

BeginFrame()

Records frame timing and calculates elapsed time since last frame. Call this at the start of each frame.

public bool BeginFrame()

Returns

bool

True if metrics display should be updated this frame.

FormatMetrics()

Formats performance metrics as Spectre markup string for display. Returns empty string if no frame time has been recorded yet.

public string FormatMetrics()

Returns

string

Formatted metrics string with frame time, FPS, window count, dirty count, and dirty chars.

SetDirtyChars(int)

Sets the number of dirty characters rendered in this frame. Call this after rendering windows but before rendering status bars. Implements hold logic to keep the value visible for a minimum duration.

public void SetDirtyChars(int dirtyChars)

Parameters

dirtyChars int

Number of characters changed this frame.

SetFrameRateLimiting(bool)

Enables or disables frame rate limiting.

public void SetFrameRateLimiting(bool enabled)

Parameters

enabled bool

True to enable frame rate limiting (cap at TargetFPS), false to render as fast as possible.

SetPerformanceMetrics(bool)

Enables or disables performance metrics display in the top status bar.

public void SetPerformanceMetrics(bool enabled)

Parameters

enabled bool

True to show performance metrics, false to hide them.

SetTargetFPS(int)

Sets the target frames per second for rendering.

public void SetTargetFPS(int fps)

Parameters

fps int

Target FPS (must be greater than 0). Common values: 15, 30, 60, 120, 144.

UpdateMetrics(int, int)

Updates metrics snapshot with current window state. Call this after BeginFrame and before rendering.

public void UpdateMetrics(int windowCount, int dirtyCount)

Parameters

windowCount int

Total number of windows.

dirtyCount int

Number of dirty windows needing redraw.