Raxol.Core.Performance.MetricsCollector (Raxol v2.0.1)
View SourceEnhanced performance metrics collection system for Raxol.
This module tracks comprehensive performance metrics including:
- Frame rate (FPS) and frame timing statistics
- Memory usage and garbage collection statistics
- Event processing latency and throughput
- System resource utilization
- Performance trends and analysis
- Real-time telemetry integration
Usage
# Create a new collector
collector = MetricsCollector.new()
# Record a frame
collector = MetricsCollector.record_frame(collector, 16)
# Record event processing
collector = MetricsCollector.record_event_timing(collector, :keyboard, 1.5)
# Get current FPS
fps = MetricsCollector.get_fps(collector)
# Get comprehensive metrics
metrics = MetricsCollector.get_all_metrics(collector)
Summary
Functions
Gets comprehensive performance metrics.
Gets the average frame time.
Gets the current frames per second.
Gets garbage collection statistics.
Gets the memory usage trend.
Creates a new enhanced metrics collector.
Records event processing timing.
Records a frame's timing.
Records operation completion.
Resets all metrics to initial state.
Updates CPU usage samples.
Updates memory usage metrics.
Functions
Gets comprehensive performance metrics.
Parameters
collector- The metrics collector
Returns
Map containing all performance metrics including:
- Frame rate and timing statistics
- Memory usage and trends
- Event processing statistics
- CPU utilization
- Operation counters
- System uptime
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 enhanced metrics collector.
Options
:telemetry_enabled- Enable telemetry integration (default: true):history_size- Number of performance samples to keep (default: 100)
Returns
A new metrics collector struct with enhanced capabilities.
Examples
iex> MetricsCollector.new()
%MetricsCollector{
frame_times: [],
memory_usage: 0,
gc_stats: %{},
event_timings: %{},
operation_counters: %{},
telemetry_enabled: true
}
Records event processing timing.
Parameters
collector- The metrics collectorevent_type- Type of event (e.g., :keyboard, :mouse, :scroll)processing_time- Time taken to process the event in milliseconds
Returns
Updated metrics collector with event timing recorded.
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
Records operation completion.
Parameters
collector- The metrics collectoroperation_type- Type of operation completedduration- Duration of the operation in microseconds
Returns
Updated metrics collector with operation recorded.
Resets all metrics to initial state.
Parameters
collector- The metrics collector
Returns
Reset metrics collector.
Updates CPU usage samples.
Parameters
collector- The metrics collector
Returns
Updated metrics collector with current CPU sample.
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