Skip to main content

tenflowers_core/eager_execution/
reporting.rs

1//! Performance reporting types for eager execution
2
3use std::time::Duration;
4
5/// Cache statistics
6#[derive(Debug, Clone)]
7pub struct CacheStatistics {
8    pub total_entries: usize,
9    pub total_hits: usize,
10    pub hit_rate: f64,
11    pub avg_execution_time: Duration,
12}
13
14/// Eager execution performance report
15#[derive(Debug, Clone)]
16pub struct EagerPerformanceReport {
17    pub total_operations: usize,
18    pub operations_meeting_target: usize,
19    pub success_rate: f64,
20    pub avg_overhead: Duration,
21    pub min_overhead: Duration,
22    pub max_overhead: Duration,
23    pub cache_statistics: CacheStatistics,
24    pub cache_hit_rate: f64,
25    pub target_overhead: Duration,
26    pub recommendations: Vec<String>,
27}
28
29impl Default for EagerPerformanceReport {
30    fn default() -> Self {
31        Self {
32            total_operations: 0,
33            operations_meeting_target: 0,
34            success_rate: 0.0,
35            avg_overhead: Duration::ZERO,
36            min_overhead: Duration::ZERO,
37            max_overhead: Duration::ZERO,
38            cache_statistics: CacheStatistics {
39                total_entries: 0,
40                total_hits: 0,
41                hit_rate: 0.0,
42                avg_execution_time: Duration::ZERO,
43            },
44            cache_hit_rate: 0.0,
45            target_overhead: Duration::from_millis(1),
46            recommendations: Vec::new(),
47        }
48    }
49}
50
51impl EagerPerformanceReport {
52    /// Print a formatted performance report
53    pub fn print_report(&self) {
54        println!("Eager Execution Performance Report");
55        println!("=====================================");
56        println!();
57        println!("Overall Performance:");
58        println!("  Total operations: {}", self.total_operations);
59        println!(
60            "  Operations meeting target: {}/{}",
61            self.operations_meeting_target, self.total_operations
62        );
63        println!("  Success rate: {:.1}%", self.success_rate * 100.0);
64        println!();
65
66        println!("Overhead Analysis:");
67        println!("  Target overhead: {:?}", self.target_overhead);
68        println!("  Average overhead: {:?}", self.avg_overhead);
69        println!("  Minimum overhead: {:?}", self.min_overhead);
70        println!("  Maximum overhead: {:?}", self.max_overhead);
71
72        let target_met = self.avg_overhead <= self.target_overhead;
73        if target_met {
74            println!("  Average overhead meets target!");
75        } else {
76            let gap = self.avg_overhead.as_nanos() - self.target_overhead.as_nanos();
77            println!("  Average overhead exceeds target by {gap}ns");
78        }
79        println!();
80
81        println!("Cache Performance:");
82        println!("  Cache entries: {}", self.cache_statistics.total_entries);
83        println!("  Cache hit rate: {:.1}%", self.cache_hit_rate * 100.0);
84        println!(
85            "  Average execution time: {:?}",
86            self.cache_statistics.avg_execution_time
87        );
88        println!();
89
90        if !self.recommendations.is_empty() {
91            println!("Recommendations:");
92            for (i, rec) in self.recommendations.iter().enumerate() {
93                println!("  {}. {}", i + 1, rec);
94            }
95        }
96
97        println!("=====================================");
98    }
99}