use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use super::types::{ExportFormat, ProfilingMode};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MobileProfilerConfig {
pub enabled: bool,
pub mode: ProfilingMode,
pub sampling: SamplingConfig,
pub memory_profiling: MemoryProfilingConfig,
pub cpu_profiling: CpuProfilingConfig,
pub gpu_profiling: GpuProfilingConfig,
pub network_profiling: NetworkProfilingConfig,
pub real_time_monitoring: RealTimeConfig,
pub export_config: ExportConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SamplingConfig {
pub interval_ms: u64,
pub max_samples: usize,
pub adaptive_sampling: bool,
pub high_freq_threshold_ms: u64,
pub low_freq_threshold_ms: u64,
pub burst_sampling: bool,
pub burst_duration_ms: u64,
pub thermal_sampling_interval_ms: u64,
pub memory_sampling_interval_ms: u64,
pub cpu_sampling_interval_ms: u64,
pub battery_sampling_interval_ms: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryProfilingConfig {
pub enabled: bool,
pub track_allocations: bool,
pub track_deallocations: bool,
pub leak_detection: bool,
pub pressure_monitoring: bool,
pub heap_analysis: bool,
pub stack_trace_depth: usize,
pub allocation_threshold_bytes: usize,
pub gc_monitoring: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CpuProfilingConfig {
pub enabled: bool,
pub per_thread_tracking: bool,
pub thermal_monitoring: bool,
pub frequency_monitoring: bool,
pub core_utilization: bool,
pub power_estimation: bool,
pub sampling_rate_hz: u32,
pub cache_performance: bool,
pub instruction_profiling: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GpuProfilingConfig {
pub enabled: bool,
pub memory_tracking: bool,
pub utilization_monitoring: bool,
pub shader_tracking: bool,
pub thermal_monitoring: bool,
pub power_tracking: bool,
pub frequency_monitoring: bool,
pub memory_bandwidth: bool,
pub command_queue_monitoring: bool,
pub sampling_interval_ms: u64,
pub enable_gpu_metrics: bool,
pub enable_memory_tracking: bool,
pub enable_performance_counters: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkProfilingConfig {
pub enabled: bool,
pub bandwidth_tracking: bool,
pub latency_monitoring: bool,
pub connection_monitoring: bool,
pub request_analysis: bool,
pub error_tracking: bool,
pub protocol_analysis: bool,
pub dns_monitoring: bool,
pub ssl_monitoring: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RealTimeConfig {
pub enabled: bool,
pub update_interval_ms: u64,
pub performance_alerts: bool,
pub alert_thresholds: AlertThresholds,
pub max_history_points: usize,
pub live_streaming: bool,
pub websocket_port: u16,
pub buffer_size: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AlertThresholds {
pub memory_threshold_percent: f32,
pub cpu_threshold_percent: f32,
pub gpu_threshold_percent: f32,
pub temperature_threshold_c: f32,
pub latency_threshold_ms: f32,
pub battery_threshold_percent: f32,
pub network_error_threshold_percent: f32,
pub frame_rate_threshold_fps: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExportConfig {
pub auto_export: bool,
pub format: ExportFormat,
pub export_directory: String,
pub include_raw_data: bool,
pub include_visualizations: bool,
pub compression_level: u8,
pub max_file_size_mb: u32,
pub export_interval_sec: u64,
pub include_system_info: bool,
pub custom_metadata: HashMap<String, String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ThermalConfig {
pub enabled: bool,
pub sampling_interval_ms: u64,
pub critical_temp_c: f32,
pub warning_temp_c: f32,
pub throttling_detection: bool,
pub monitored_sensors: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatteryConfig {
pub enabled: bool,
pub sampling_interval_ms: u64,
pub low_battery_threshold: f32,
pub critical_battery_threshold: f32,
pub monitor_charging: bool,
pub power_estimation: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct PlatformConfig {
pub ios_config: Option<IosConfig>,
pub android_config: Option<AndroidConfig>,
pub generic_config: GenericConfig,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IosConfig {
pub metal_monitoring: bool,
pub coreml_tracking: bool,
pub instruments_integration: bool,
pub xcode_profiling: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AndroidConfig {
pub systrace_integration: bool,
pub gpu_vendor_tools: bool,
pub android_profiler: bool,
pub method_tracing: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GenericConfig {
pub cross_platform_features: bool,
pub generic_counters: bool,
pub standard_optimizations: bool,
}
impl Default for MobileProfilerConfig {
fn default() -> Self {
Self {
enabled: true,
mode: ProfilingMode::Development,
sampling: SamplingConfig::default(),
memory_profiling: MemoryProfilingConfig::default(),
cpu_profiling: CpuProfilingConfig::default(),
gpu_profiling: GpuProfilingConfig::default(),
network_profiling: NetworkProfilingConfig::default(),
real_time_monitoring: RealTimeConfig::default(),
export_config: ExportConfig::default(),
}
}
}
impl Default for SamplingConfig {
fn default() -> Self {
Self {
interval_ms: 100, max_samples: 10000,
adaptive_sampling: true,
high_freq_threshold_ms: 50,
low_freq_threshold_ms: 1000,
burst_sampling: true,
burst_duration_ms: 500,
thermal_sampling_interval_ms: 1000, memory_sampling_interval_ms: 500, cpu_sampling_interval_ms: 200, battery_sampling_interval_ms: 5000, }
}
}
impl Default for MemoryProfilingConfig {
fn default() -> Self {
Self {
enabled: true,
track_allocations: true,
track_deallocations: true,
leak_detection: true,
pressure_monitoring: true,
heap_analysis: false, stack_trace_depth: 10,
allocation_threshold_bytes: 1024, gc_monitoring: true,
}
}
}
impl Default for CpuProfilingConfig {
fn default() -> Self {
Self {
enabled: true,
per_thread_tracking: false, thermal_monitoring: true,
frequency_monitoring: true,
core_utilization: true,
power_estimation: true,
sampling_rate_hz: 10,
cache_performance: false,
instruction_profiling: false,
}
}
}
impl Default for GpuProfilingConfig {
fn default() -> Self {
Self {
enabled: true,
memory_tracking: true,
utilization_monitoring: true,
shader_tracking: false, thermal_monitoring: true,
power_tracking: true,
frequency_monitoring: true,
memory_bandwidth: false,
command_queue_monitoring: false,
sampling_interval_ms: 200, enable_gpu_metrics: true,
enable_memory_tracking: true,
enable_performance_counters: true,
}
}
}
impl Default for NetworkProfilingConfig {
fn default() -> Self {
Self {
enabled: true,
bandwidth_tracking: true,
latency_monitoring: true,
connection_monitoring: true,
request_analysis: false, error_tracking: true,
protocol_analysis: false,
dns_monitoring: true,
ssl_monitoring: false,
}
}
}
impl Default for RealTimeConfig {
fn default() -> Self {
Self {
enabled: true,
update_interval_ms: 1000, performance_alerts: true,
alert_thresholds: AlertThresholds::default(),
max_history_points: 300, live_streaming: false,
websocket_port: 8080,
buffer_size: 1024,
}
}
}
impl Default for AlertThresholds {
fn default() -> Self {
Self {
memory_threshold_percent: 80.0,
cpu_threshold_percent: 80.0,
gpu_threshold_percent: 80.0,
temperature_threshold_c: 70.0,
latency_threshold_ms: 100.0,
battery_threshold_percent: 20.0,
network_error_threshold_percent: 5.0,
frame_rate_threshold_fps: 30.0,
}
}
}
impl Default for ExportConfig {
fn default() -> Self {
Self {
auto_export: false,
format: ExportFormat::JSON,
export_directory: "/tmp/profiling_data".to_string(),
include_raw_data: true,
include_visualizations: false,
compression_level: 6,
max_file_size_mb: 100,
export_interval_sec: 300, include_system_info: true,
custom_metadata: HashMap::new(),
}
}
}
impl Default for ThermalConfig {
fn default() -> Self {
Self {
enabled: true,
sampling_interval_ms: 1000,
critical_temp_c: 85.0,
warning_temp_c: 70.0,
throttling_detection: true,
monitored_sensors: vec!["cpu".to_string(), "gpu".to_string()],
}
}
}
impl Default for BatteryConfig {
fn default() -> Self {
Self {
enabled: true,
sampling_interval_ms: 5000, low_battery_threshold: 20.0,
critical_battery_threshold: 10.0,
monitor_charging: true,
power_estimation: true,
}
}
}
impl Default for GenericConfig {
fn default() -> Self {
Self {
cross_platform_features: true,
generic_counters: true,
standard_optimizations: true,
}
}
}