Files
foxhunt/ml/src/stress_testing/performance_analyzer.rs
jgrusewski 3f688359f6 🤖 Wave 33-2: 12 Parallel Agents - Massive Cleanup Complete
**Progress: 57 → 9 test errors (84% reduction)**
**Warning Reduction: 253 → ~100 (60% reduction)**

## Agent Results Summary (12/12 completed)

### Agent 1-5: Error Fixes (42 errors eliminated)
 Agent 1: Fixed 23 type mismatches in ml/src/features.rs
 Agent 2: Fixed 2 type conversions in ml/src/bridge.rs
 Agent 3: Fixed inference test return type
 Agent 4: Added Decimal imports (1 file)
 Agent 5: Fixed 15 compliance module imports

### Agent 6-11: Code Quality (92 improvements)
 Agent 6: Fixed 3 private method access issues
 Agent 7: Removed 12 unused imports
 Agent 8: Added Debug to 80 structs
 Agent 9: Fixed 3 snake_case warnings
 Agent 10: Fixed 2 unused variables
 Agent 11: Fixed 5 remaining ML errors

### Agent 12: Comprehensive Verification
 Created detailed verification report
 Analyzed 246 test files, 4,355 test functions
 Identified 9 remaining error types

## Current Status
-  Production code: Compiles cleanly (0 errors)
- ⚠️  Test code: 9 unique errors remain (down from 57)
- 📊 Warnings: ~100 (down from 253, target: <20)
- 📁 Test infrastructure: 4,355 tests across 246 files

## Remaining Errors (9 types)
1. 2× E0603 OrderStatus is private
2. 2× E0433 undeclared Decimal
3. 1× E0603 OrderSide is private
4. 1× E0433 undeclared TestConfig
5. 1× E0433 undeclared MockMarketDataProvider
6. 1× E0425 generate_test_id not found
7. 1× E0277 ? operator on non-Try type
8. 1× E0061 wrong argument count

## Next: Wave 33-3
- Fix remaining 9 error types
- Reduce warnings to <20
- Run full test suite
- Achieve 95% coverage target

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-01 21:48:25 +02:00

146 lines
3.7 KiB
Rust

//! Performance analysis for ML stress testing
use anyhow::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::time::{Duration, SystemTime};
use super::{PhaseResult, RequirementsCheck, StressTestConfig};
/// Latency statistics
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct LatencyStats {
pub mean: f64,
pub min: u64,
pub max: u64,
pub p50: u64,
pub p95: u64,
pub p99: u64,
pub count: u64,
}
/// Comprehensive stress test report
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StressTestReport {
pub config: StressTestConfig,
pub total_duration: Duration,
pub phase_results: Vec<PhaseResult>,
pub total_predictions: u64,
pub total_errors: u64,
pub error_rate: f64,
pub latency_stats: LatencyStats,
pub requirements_met: RequirementsCheck,
pub throughput_achieved: f64,
pub recommendations: Vec<String>,
}
/// Performance analyzer for stress testing
#[derive(Debug, Clone)]
pub struct PerformanceAnalyzer {
start_time: Option<SystemTime>,
measurements: Vec<PerformanceMeasurement>,
}
#[derive(Debug, Clone)]
struct PerformanceMeasurement {
timestamp: SystemTime,
metric_name: String,
value: f64,
labels: HashMap<String, String>,
}
impl PerformanceAnalyzer {
pub fn new() -> Self {
Self {
start_time: None,
measurements: Vec::new(),
}
}
pub async fn start_monitoring(&self) -> Result<()> {
// Implementation would start background monitoring
// For now, this is a placeholder
Ok(())
}
pub fn record_measurement(
&mut self,
metric_name: &str,
value: f64,
labels: HashMap<String, String>,
) {
self.measurements.push(PerformanceMeasurement {
timestamp: SystemTime::now(),
metric_name: metric_name.to_string(),
value,
labels,
});
}
pub fn generate_summary(&self) -> PerformanceSummary {
let mut latencies = Vec::new();
let mut errors = 0;
let mut total_requests = 0;
for measurement in &self.measurements {
match measurement.metric_name.as_str() {
"latency" => latencies.push(measurement.value as u64),
"error" => errors += 1,
"request" => total_requests += 1,
_ => {},
}
}
let latency_stats = if latencies.is_empty() {
LatencyStats::default()
} else {
self.calculate_latency_stats(&latencies)
};
let error_rate = if total_requests > 0 {
errors as f64 / total_requests as f64
} else {
0.0
};
PerformanceSummary {
latency_stats,
error_rate,
total_requests: total_requests as u64,
total_errors: errors as u64,
}
}
fn calculate_latency_stats(&self, latencies: &[u64]) -> LatencyStats {
let mut sorted = latencies.to_vec();
sorted.sort_unstable();
let len = sorted.len();
let mean = sorted.iter().sum::<u64>() as f64 / len as f64;
LatencyStats {
mean,
min: sorted[0],
max: sorted[len - 1],
p50: sorted[len * 50 / 100],
p95: sorted[len * 95 / 100],
p99: sorted[len * 99 / 100],
count: len as u64,
}
}
}
#[derive(Debug, Clone)]
pub struct PerformanceSummary {
pub latency_stats: LatencyStats,
pub error_rate: f64,
pub total_requests: u64,
pub total_errors: u64,
}
impl Default for PerformanceAnalyzer {
fn default() -> Self {
Self::new()
}
}