Raxol.Terminal.Graphics.PerformanceMonitor (Raxol v2.0.1)
View SourceComprehensive performance monitoring system for terminal graphics operations.
This module provides real-time monitoring and analysis of:
- Graphics operation latency and throughput
- GPU utilization and memory usage
- Rendering pipeline performance
- Cache hit rates and efficiency
- Resource allocation patterns
- Performance regression detection
Features
Real-time Monitoring
- Sub-millisecond operation timing
- GPU memory usage tracking
- Rendering pipeline bottleneck detection
- Cache performance analysis
- Throughput measurement (operations/second)
Performance Analysis
- Statistical analysis (percentiles, averages, variance)
- Performance trend analysis
- Anomaly detection for performance regressions
- Comparative analysis across different graphics operations
- Resource utilization optimization suggestions
Reporting and Alerting
- Real-time performance dashboards
- Performance alert thresholds
- Historical performance data
- Export capabilities for analysis tools
- Integration with external monitoring systems
Usage
# Start performance monitoring
{:ok, monitor} = PerformanceMonitor.start_link(%{
sampling_rate: 100, # samples per second
retention_period: 3600, # 1 hour
alert_thresholds: %{
latency_p99: 100, # 100ms
gpu_memory_usage: 0.8 # 80%
}
})
# Monitor a graphics operation
PerformanceMonitor.start_operation(:image_scaling, metadata)
# ... perform operation ...
PerformanceMonitor.end_operation(:image_scaling, result)
# Get performance metrics
metrics = PerformanceMonitor.get_metrics()
Summary
Functions
Returns a specification to start this module under a supervisor.
Configures performance alerts.
Ends monitoring of a graphics operation.
Generates a performance report for the specified time period.
Gets current performance metrics and statistics.
Gets detailed performance history for analysis.
Records a custom metric for analysis.
Resets all performance statistics and history.
Starts monitoring a graphics operation.
Types
@type alert_config() :: %{ threshold: float(), comparison: :greater_than | :less_than | :equals, consecutive_violations: non_neg_integer(), callback: function() | nil }
@type operation_id() :: String.t()
@type operation_metrics() :: %{ type: operation_type(), start_time: timestamp(), end_time: timestamp(), duration: non_neg_integer(), cpu_usage: float(), gpu_usage: float(), memory_used: non_neg_integer(), cache_hits: non_neg_integer(), cache_misses: non_neg_integer(), metadata: map() }
@type operation_type() :: atom()
@type timestamp() :: non_neg_integer()
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec configure_alert(atom(), alert_config()) :: :ok | {:error, term()}
Configures performance alerts.
Examples
PerformanceMonitor.configure_alert(:high_latency, %{
threshold: 100.0, # 100ms
comparison: :greater_than,
consecutive_violations: 3,
callback: fn metrics -> Log.warning("High latency detected") end
})
@spec end_operation(operation_id(), map()) :: :ok | {:error, term()}
Ends monitoring of a graphics operation.
Parameters
operation_id- ID returned from start_operation/2result- Operation result (success/failure and additional data)
Generates a performance report for the specified time period.
@spec get_metrics() :: performance_stats()
Gets current performance metrics and statistics.
@spec get_performance_history(map()) :: [operation_metrics()]
Gets detailed performance history for analysis.
Parameters
options- Filtering and formatting options:operation_types- List of operation types to include:time_range- {start_time, end_time} in microseconds:limit- Maximum number of operations to return
Records a custom metric for analysis.
Examples
PerformanceMonitor.record_metric(:gpu_memory_usage, 75.5, %{
timestamp: System.system_time(:microsecond),
unit: :percentage
})
@spec reset_statistics() :: :ok
Resets all performance statistics and history.
@spec start_operation(operation_type(), map()) :: {:ok, operation_id()} | {:error, term()}
Starts monitoring a graphics operation.
Parameters
operation_type- Type of operation (e.g., :image_scaling, :rendering)metadata- Additional operation metadata
Returns
{:ok, operation_id}- Successfully started monitoring{:error, reason}- Failed to start monitoring
Examples
{:ok, op_id} = PerformanceMonitor.start_operation(:image_processing, %{
image_size: 1024 * 1024,
format: :png,
operation: :scale
})