use super::config::{DeviceType, PowerMode, PrecisionMode, ThermalCondition};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::{Duration, SystemTime};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestSuiteResults {
pub timestamp: SystemTime,
pub duration: Duration,
pub benchmark_results: Vec<BenchmarkResult>,
pub battery_results: Vec<BatteryTestResult>,
pub stress_results: Vec<StressTestResult>,
pub memory_results: Vec<MemoryTestResult>,
pub success_rate: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BenchmarkResult {
pub config_id: String,
pub input_shape: Vec<usize>,
pub precision_mode: PrecisionMode,
pub power_mode: PowerMode,
pub thermal_condition: ThermalCondition,
pub avg_latency_ms: f32,
pub p95_latency_ms: f32,
pub p99_latency_ms: f32,
pub throughput_fps: f32,
pub memory_usage_mb: usize,
pub accuracy_metrics: AccuracyMetrics,
pub power_stats: PowerConsumptionStats,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatteryTestResult {
pub duration: Duration,
pub initial_battery_level: f32,
pub final_battery_level: f32,
pub energy_consumed_mwh: f32,
pub avg_power_consumption_mw: f32,
pub peak_power_consumption_mw: f32,
pub total_inferences: usize,
pub energy_per_inference_mj: f32,
pub battery_drain_rate_percent_per_hour: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StressTestResult {
pub duration: Duration,
pub stress_type: StressType,
pub success_rate: f32,
pub avg_latency_ms: f32,
pub memory_pressure_level: f32,
pub cpu_utilization: f32,
pub gpu_utilization: f32,
pub thermal_throttling_events: usize,
pub memory_allocation_failures: usize,
pub error_rate: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryTestResult {
pub duration: Duration,
pub test_type: MemoryTestType,
pub peak_memory_usage_mb: usize,
pub avg_memory_usage_mb: usize,
pub memory_leaks_detected: usize,
pub memory_stats: MemoryUsageStats,
pub gc_stats: Option<HashMap<String, f32>>,
pub allocation_success_rate: f32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum StressType {
CPU,
Memory,
Thermal,
Battery,
Network,
Storage,
Combined,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum MemoryTestType {
LeakDetection,
PressureTesting,
AllocationStress,
FragmentationAnalysis,
GCPerformance,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MemoryUsageStats {
pub total_allocated_mb: usize,
pub peak_allocated_mb: usize,
pub fragmentation_percent: f32,
pub large_allocations: usize,
pub small_allocations: usize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PowerConsumptionStats {
pub cpu_power_mw: f32,
pub gpu_power_mw: f32,
pub memory_power_mw: f32,
pub total_power_mw: f32,
pub efficiency_score: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AccuracyMetrics {
pub top1_accuracy: f32,
pub top5_accuracy: f32,
pub f1_score: f32,
pub precision: f32,
pub recall: f32,
pub mean_average_precision: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmSessionResult {
pub session_id: String,
pub start_time: SystemTime,
pub duration: Duration,
pub device_results: Vec<DeviceTestResult>,
pub aggregated_results: AggregatedTestResults,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceTestResult {
pub device_id: String,
pub device_info: DeviceInfo,
pub test_results: TestSuiteResults,
pub execution_metrics: DeviceExecutionMetrics,
pub artifacts: Vec<TestArtifact>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceInfo {
pub device_name: String,
pub os_name: String,
pub os_version: String,
pub device_type: DeviceType,
pub hardware_model: String,
pub cpu_architecture: String,
pub ram_mb: usize,
pub storage_gb: usize,
pub screen_resolution: (u32, u32),
pub sensors: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceExecutionMetrics {
pub execution_time: Duration,
pub setup_time: Duration,
pub cleanup_time: Duration,
pub network_time: Duration,
pub availability_time: Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestArtifact {
pub id: String,
pub artifact_type: ArtifactType,
pub location: String,
pub size_bytes: usize,
pub created_at: SystemTime,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ArtifactType {
Video,
Screenshot,
DeviceLog,
AppLog,
PerformanceProfile,
NetworkTrace,
CrashReport,
TestReport,
RawData,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AggregatedTestResults {
pub device_count: usize,
pub overall_success_rate: f32,
pub metrics: AggregatedMetrics,
pub cross_device_analysis: CrossDeviceAnalysis,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AggregatedMetrics {
pub avg_latency_ms: f32,
pub latency_std_dev: f32,
pub avg_throughput_fps: f32,
pub avg_memory_usage_mb: f32,
pub avg_power_consumption_mw: f32,
pub statistical_summary: StatisticalSummary,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CrossDeviceAnalysis {
pub performance_variance: f32,
pub best_device: String,
pub worst_device: String,
pub compatibility_rate: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatisticalSummary {
pub mean: f32,
pub median: f32,
pub std_deviation: f32,
pub min: f32,
pub max: f32,
pub percentiles: HashMap<String, f32>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeviceFarmSessionMetadata {
pub configuration: String,
pub requested_devices: usize,
pub allocated_devices: usize,
pub failed_allocations: usize,
pub total_cost: Option<f32>,
pub resource_utilization: ResourceUtilization,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResourceUtilization {
pub device_utilization: f32,
pub network_usage_mb: f32,
pub storage_usage_mb: f32,
pub compute_time_minutes: f32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionSummary {
pub total_tests: usize,
pub successful_tests: usize,
pub failed_tests: usize,
pub skipped_tests: usize,
pub avg_execution_time: Duration,
pub performance_highlights: Vec<String>,
pub issues: Vec<String>,
pub recommendations: Vec<String>,
}
impl BenchmarkResult {
pub fn performance_score(&self) -> f32 {
let latency_score = 1.0 - (self.avg_latency_ms / 1000.0).min(1.0);
let throughput_score = (self.throughput_fps / 100.0).min(1.0);
let memory_score = 1.0 - (self.memory_usage_mb as f32 / 1024.0).min(1.0);
let accuracy_score = self.accuracy_metrics.top1_accuracy / 100.0;
let power_score = self.power_stats.efficiency_score;
(latency_score * 0.25
+ throughput_score * 0.25
+ memory_score * 0.2
+ accuracy_score * 0.2
+ power_score * 0.1)
.max(0.0)
.min(1.0)
}
pub fn meets_targets(
&self,
target_latency_ms: f32,
target_throughput_fps: f32,
target_accuracy: f32,
) -> bool {
self.avg_latency_ms <= target_latency_ms
&& self.throughput_fps >= target_throughput_fps
&& self.accuracy_metrics.top1_accuracy >= target_accuracy
}
}