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
getOptionsFunc<ConsoleWindowSystemOptions>Callback to get current options.
setOptionsAction<ConsoleWindowSystemOptions>Callback to update options.
logServiceILogServiceOptional logging service.
onStatusCacheInvalidateActionOptional 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
CurrentDirtyCount
Gets the current number of dirty windows.
public int CurrentDirtyCount { get; }
Property Value
CurrentFPS
Gets the current frames per second (FPS).
public double CurrentFPS { get; }
Property Value
CurrentFrameTimeMs
Gets the most recent frame time in milliseconds.
public double CurrentFrameTimeMs { get; }
Property Value
CurrentWindowCount
Gets the current window count.
public int CurrentWindowCount { get; }
Property Value
IsFrameRateLimitingEnabled
Gets whether frame rate limiting is currently enabled.
public bool IsFrameRateLimitingEnabled { get; }
Property Value
IsPerformanceMetricsEnabled
Gets whether performance metrics are currently enabled.
public bool IsPerformanceMetricsEnabled { get; }
Property Value
MinFrameTime
Gets the minimum frame time in milliseconds based on target FPS.
public double MinFrameTime { get; }
Property Value
TargetFPS
Gets the current target frames per second.
public int TargetFPS { get; }
Property Value
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
dirtyCharsintNumber of characters changed this frame.
SetFrameRateLimiting(bool)
Enables or disables frame rate limiting.
public void SetFrameRateLimiting(bool enabled)
Parameters
enabledboolTrue 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
enabledboolTrue to show performance metrics, false to hide them.
SetTargetFPS(int)
Sets the target frames per second for rendering.
public void SetTargetFPS(int fps)
Parameters
fpsintTarget 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)