1use super::*;
4
5#[derive(Debug, Clone)]
7pub struct BottleneckAnalysis {
8 pub bottlenecks: Vec<Bottleneck>,
10 pub resource_utilization: ResourceUtilizationAnalysis,
12 pub dependency_analysis: DependencyAnalysis,
14 pub optimization_opportunities: Vec<OptimizationOpportunity>,
16}
17
18#[derive(Debug, Clone)]
20pub struct Bottleneck {
21 pub bottleneck_type: BottleneckType,
23 pub location: String,
25 pub severity: f64,
27 pub resource: String,
29 pub mitigation_strategies: Vec<String>,
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum BottleneckType {
36 CPU,
37 Memory,
38 IO,
39 Network,
40 Algorithm,
41 Synchronization,
42 Custom { description: String },
43}
44
45#[derive(Debug, Clone)]
47pub struct ResourceUtilizationAnalysis {
48 pub cpu_breakdown: CpuUtilizationBreakdown,
50 pub memory_breakdown: MemoryUtilizationBreakdown,
52 pub io_breakdown: IoUtilizationBreakdown,
54 pub network_breakdown: NetworkUtilizationBreakdown,
56}
57
58#[derive(Debug, Clone)]
60pub struct CpuUtilizationBreakdown {
61 pub user_time: f64,
63 pub system_time: f64,
65 pub idle_time: f64,
67 pub wait_time: f64,
69 pub per_core_utilization: Vec<f64>,
71 pub context_switches: f64,
73}
74
75impl Default for CpuUtilizationBreakdown {
76 fn default() -> Self {
77 Self {
78 user_time: 45.0,
79 system_time: 15.0,
80 idle_time: 35.0,
81 wait_time: 5.0,
82 per_core_utilization: vec![45.0, 48.0, 42.0, 50.0],
83 context_switches: 1500.0,
84 }
85 }
86}
87
88#[derive(Debug, Clone)]
90pub struct MemoryUtilizationBreakdown {
91 pub used_memory: f64,
93 pub cached_memory: f64,
95 pub buffer_memory: f64,
97 pub available_memory: f64,
99 pub allocation_rate: f64,
101 pub gc_overhead: f64,
103}
104
105impl Default for MemoryUtilizationBreakdown {
106 fn default() -> Self {
107 Self {
108 used_memory: 65.0,
109 cached_memory: 20.0,
110 buffer_memory: 5.0,
111 available_memory: 10.0,
112 allocation_rate: 1024.0,
113 gc_overhead: 2.0,
114 }
115 }
116}
117
118#[derive(Debug, Clone)]
120pub struct IoUtilizationBreakdown {
121 pub read_ops: f64,
123 pub write_ops: f64,
125 pub read_throughput: f64,
127 pub write_throughput: f64,
129 pub io_wait_time: f64,
131 pub queue_depth: f64,
133}
134
135impl Default for IoUtilizationBreakdown {
136 fn default() -> Self {
137 Self {
138 read_ops: 500.0,
139 write_ops: 200.0,
140 read_throughput: 100.0,
141 write_throughput: 50.0,
142 io_wait_time: 2.5,
143 queue_depth: 4.0,
144 }
145 }
146}
147
148#[derive(Debug, Clone)]
150pub struct NetworkUtilizationBreakdown {
151 pub incoming_bandwidth: f64,
153 pub outgoing_bandwidth: f64,
155 pub packet_rate: f64,
157 pub latency: f64,
159 pub packet_loss: f64,
161 pub connection_count: usize,
163}
164
165impl Default for NetworkUtilizationBreakdown {
166 fn default() -> Self {
167 Self {
168 incoming_bandwidth: 150.0,
169 outgoing_bandwidth: 75.0,
170 packet_rate: 5000.0,
171 latency: 1.2,
172 packet_loss: 0.01,
173 connection_count: 25,
174 }
175 }
176}
177
178#[derive(Debug, Clone)]
180pub struct DependencyAnalysis {
181 pub critical_path: Vec<String>,
183 pub dependency_graph: DependencyGraph,
185 pub parallelization_opportunities: Vec<ParallelizationOpportunity>,
187 pub serialization_bottlenecks: Vec<String>,
189}
190
191#[derive(Debug, Clone)]
193pub struct DependencyGraph {
194 pub nodes: Vec<DependencyNode>,
196 pub edges: Vec<DependencyEdge>,
198 pub properties: GraphProperties,
200}
201
202#[derive(Debug, Clone)]
204pub struct DependencyNode {
205 pub id: String,
207 pub operation: String,
209 pub execution_time: Duration,
211 pub resource_requirements: HashMap<String, f64>,
213}
214
215#[derive(Debug, Clone)]
217pub struct DependencyEdge {
218 pub source: String,
220 pub target: String,
222 pub dependency_type: DependencyType,
224 pub data_size: usize,
226}
227
228#[derive(Debug, Clone, PartialEq, Eq)]
230pub enum DependencyType {
231 DataDependency,
232 ControlDependency,
233 ResourceDependency,
234 SynchronizationDependency,
235}
236
237#[derive(Debug, Clone)]
239pub struct GraphProperties {
240 pub node_count: usize,
242 pub edge_count: usize,
244 pub density: f64,
246 pub avg_path_length: f64,
248 pub clustering_coefficient: f64,
250}
251
252impl Default for GraphProperties {
253 fn default() -> Self {
254 Self {
255 node_count: 0,
256 edge_count: 0,
257 density: 0.0,
258 avg_path_length: 0.0,
259 clustering_coefficient: 0.0,
260 }
261 }
262}
263
264#[derive(Debug, Clone)]
266pub struct ParallelizationOpportunity {
267 pub operations: Vec<String>,
269 pub potential_speedup: f64,
271 pub strategy: ParallelizationStrategy,
273 pub complexity: ComplexityLevel,
275}
276
277#[derive(Debug, Clone, PartialEq, Eq)]
279pub enum ParallelizationStrategy {
280 TaskParallelism,
281 DataParallelism,
282 PipelineParallelism,
283 HybridParallelism,
284}
285
286#[derive(Debug, Clone, PartialEq, Eq)]
288pub enum ComplexityLevel {
289 Low,
290 Medium,
291 High,
292 VeryHigh,
293}
294
295#[derive(Debug, Clone)]
297pub struct OptimizationOpportunity {
298 pub optimization_type: OptimizationType,
300 pub description: String,
302 pub potential_improvement: f64,
304 pub implementation_effort: EffortLevel,
306 pub risk_level: RiskLevel,
308}
309
310#[derive(Debug, Clone, PartialEq, Eq)]
312pub enum OptimizationType {
313 AlgorithmOptimization,
314 DataStructureOptimization,
315 MemoryOptimization,
316 CacheOptimization,
317 ParallelizationOptimization,
318 CompilerOptimization,
319 HardwareOptimization,
320}
321
322#[derive(Debug, Clone, PartialEq, Eq)]
324pub enum EffortLevel {
325 Minimal,
326 Low,
327 Medium,
328 High,
329 Extensive,
330}
331
332#[derive(Debug, Clone, PartialEq, Eq)]
334pub enum RiskLevel {
335 VeryLow,
336 Low,
337 Medium,
338 High,
339 VeryHigh,
340}
341
342#[derive(Debug, Clone)]
344pub struct ComparativeAnalysis {
345 pub baseline_comparison: BaselineComparison,
347 pub algorithm_comparisons: Vec<AlgorithmComparison>,
349 pub regression_analysis: RegressionAnalysis,
351 pub ab_test_results: Vec<ABTestResult>,
353}
354
355#[derive(Debug, Clone)]
357pub struct BaselineComparison {
358 pub current_performance: HashMap<String, f64>,
360 pub baseline_performance: HashMap<String, f64>,
362 pub performance_changes: HashMap<String, f64>,
364 pub statistical_significance: HashMap<String, bool>,
366}
367
368#[derive(Debug, Clone)]
370pub struct AlgorithmComparison {
371 pub algorithms: Vec<String>,
373 pub performance_comparison: HashMap<String, Vec<f64>>,
375 pub statistical_tests: Vec<HypothesisTestResult>,
377 pub recommendation: String,
379}
380
381#[derive(Debug, Clone)]
383pub struct RegressionAnalysis {
384 pub regression_detected: bool,
386 pub regression_severity: f64,
388 pub affected_metrics: Vec<String>,
390 pub potential_causes: Vec<String>,
392 pub timeline_analysis: TimelineAnalysis,
394}
395
396#[derive(Debug, Clone)]
398pub struct TimelineAnalysis {
399 pub key_events: Vec<TimelineEvent>,
401 pub correlations: Vec<PerformanceCorrelation>,
403 pub change_points: Vec<ChangePoint>,
405}
406
407#[derive(Debug, Clone)]
409pub struct TimelineEvent {
410 pub timestamp: Instant,
412 pub description: String,
414 pub event_type: EventType,
416 pub impact: f64,
418}
419
420#[derive(Debug, Clone, PartialEq, Eq)]
422pub enum EventType {
423 CodeChange,
424 ConfigurationChange,
425 HardwareChange,
426 EnvironmentChange,
427 DataChange,
428 External,
429}
430
431#[derive(Debug, Clone)]
433pub struct PerformanceCorrelation {
434 pub metric1: String,
436 pub metric2: String,
438 pub correlation: f64,
440 pub p_value: f64,
442 pub correlation_type: CorrelationType,
444}
445
446#[derive(Debug, Clone, PartialEq, Eq)]
448pub enum CorrelationType {
449 Positive,
450 Negative,
451 NonLinear,
452 Spurious,
453}
454
455#[derive(Debug, Clone)]
457pub struct ChangePoint {
458 pub timestamp: Instant,
460 pub metric: String,
462 pub magnitude: f64,
464 pub confidence: f64,
466 pub change_type: ChangeType,
468}
469
470#[derive(Debug, Clone, PartialEq, Eq)]
472pub enum ChangeType {
473 LevelShift,
474 TrendChange,
475 VarianceChange,
476 DistributionChange,
477}
478
479#[derive(Debug, Clone)]
481pub struct ABTestResult {
482 pub test_name: String,
484 pub variant_a: TestVariantResult,
486 pub variant_b: TestVariantResult,
488 pub statistical_significance: bool,
490 pub effect_size: f64,
492 pub confidence_interval: (f64, f64),
494 pub recommendation: String,
496}
497
498#[derive(Debug, Clone)]
500pub struct TestVariantResult {
501 pub sample_size: usize,
503 pub metrics: HashMap<String, f64>,
505 pub std_devs: HashMap<String, f64>,
507 pub confidence_intervals: HashMap<String, (f64, f64)>,
509}