Raxol.Core.Performance.MetricsCollector (Raxol v0.2.0)
View SourceCollects and calculates performance metrics.
This module tracks:
- Frame rate (FPS)
- Frame timing statistics
- Memory usage
- Garbage collection statistics
Usage
# Create a new collector
collector = MetricsCollector.new()
# Record a frame
collector = MetricsCollector.record_frame(collector, 16)
# Get current FPS
fps = MetricsCollector.get_fps(collector)
# Update memory metrics
collector = MetricsCollector.update_memory_usage(collector)
Summary
Functions
Gets the average frame time.
Gets the current frames per second.
Gets garbage collection statistics.
Gets the memory usage trend.
Creates a new metrics collector.
Records a frame's timing.
Updates memory usage metrics.
Functions
Gets the average frame time.
Parameters
collector
- The metrics collector
Returns
Average frame time in milliseconds.
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.record_frame(collector, 16)
iex> MetricsCollector.get_avg_frame_time(collector)
16.0
Gets the current frames per second.
Parameters
collector
- The metrics collector
Returns
Current FPS as a float.
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.record_frame(collector, 16)
iex> MetricsCollector.get_fps(collector)
62.5
Gets garbage collection statistics.
Parameters
collector
- The metrics collector
Returns
Map containing GC statistics:
:number_of_gcs
- Total number of garbage collections:words_reclaimed
- Total words reclaimed:heap_size
- Current heap size:heap_limit
- Maximum heap size
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.update_memory_usage(collector)
iex> gc_stats = MetricsCollector.get_gc_stats(collector)
iex> Map.has_key?(gc_stats, :number_of_gcs)
true
Gets the memory usage trend.
Parameters
collector
- The metrics collector
Returns
Memory usage trend as a percentage change.
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.update_memory_usage(collector)
iex> collector = MetricsCollector.update_memory_usage(collector)
iex> MetricsCollector.get_memory_trend(collector)
0.0
Creates a new metrics collector.
Returns
A new metrics collector struct.
Examples
iex> MetricsCollector.new()
%MetricsCollector{
frame_times: [],
memory_usage: 0,
gc_stats: %{},
last_gc_time: 0
}
Records a frame's timing.
Parameters
collector
- The metrics collectorframe_time
- Time taken to render the frame in milliseconds
Returns
Updated metrics collector.
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.record_frame(collector, 16)
iex> length(collector.frame_times)
1
Updates memory usage metrics.
Parameters
collector
- The metrics collector
Returns
Updated metrics collector with current memory usage and GC stats.
Examples
iex> collector = MetricsCollector.new()
iex> collector = MetricsCollector.update_memory_usage(collector)
iex> collector.memory_usage > 0
true