Raxol.Core.Performance.Monitor (Raxol v0.5.0)

View Source

Performance 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
  Raxol.Core.Runtime.Log.warning_with_context("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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

detect_jank?(monitor)

Checks if jank was detected in the last frame.

Parameters

  • monitor - The monitor process

Returns

  • true if jank was detected
  • false otherwise

Examples

iex> Monitor.detect_jank?(monitor)
false

get_metrics(monitor)

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: %{...}
}

record_frame(monitor, frame_time)

Records a frame's timing.

Parameters

  • monitor - The monitor process
  • frame_time - Time taken to render the frame in milliseconds

Examples

iex> Monitor.record_frame(monitor, 16)
:ok

reset_metrics(monitor)

start_link(opts \\ [])

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>}