Raxol.Core.Performance.Monitor (Raxol v0.2.0)
View SourcePerformance monitoring system for Raxol applications.
This module provides tools for:
- Frame rate monitoring
- Memory usage tracking
- UI jank detection
- Performance metrics collection
- Performance visualization
Usage
# Start monitoring
{:ok, monitor} = Monitor.start_link()
# Record frame timing
Monitor.record_frame(monitor, 16) # 16ms frame time
# Check for jank
if Monitor.detect_jank?(monitor) do
Logger.warning("UI jank detected")
end
# Get performance metrics
metrics = Monitor.get_metrics(monitor)
Summary
Functions
Returns a specification to start this module under a supervisor.
Checks if jank was detected in the last frame.
Gets current performance metrics.
Records a frame's timing.
Starts a new performance monitor.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Checks if jank was detected in the last frame.
Parameters
monitor
- The monitor process
Returns
true
if jank was detectedfalse
otherwise
Examples
iex> Monitor.detect_jank?(monitor)
false
Gets current performance metrics.
Parameters
monitor
- The monitor process
Returns
Map containing performance metrics:
:fps
- Current frames per second:avg_frame_time
- Average frame time in milliseconds:jank_count
- Number of janky frames in the sample window:memory_usage
- Current memory usage in bytes:gc_stats
- Garbage collection statistics
Examples
iex> Monitor.get_metrics(monitor)
%{
fps: 60,
avg_frame_time: 16.5,
jank_count: 2,
memory_usage: 1234567,
gc_stats: %{...}
}
Records a frame's timing.
Parameters
monitor
- The monitor processframe_time
- Time taken to render the frame in milliseconds
Examples
iex> Monitor.record_frame(monitor, 16)
:ok
Starts a new performance monitor.
Options
:jank_threshold
- Time in milliseconds above which a frame is considered janky (default: 16):sample_size
- Number of frames to keep in the rolling window (default: 60):memory_check_interval
- How often to check memory usage in milliseconds (default: 5000)
Examples
iex> {:ok, monitor} = Monitor.start_link()
{:ok, #PID<0.123.0>}
iex> {:ok, monitor} = Monitor.start_link(jank_threshold: 20)
{:ok, #PID<0.124.0>}