kotoba_execution/execution/
metrics.rs1use std::time::{Duration, Instant};
4
5type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
7
8#[derive(Debug, Clone)]
10pub struct ExecutionMetrics {
11 pub start_time: Instant,
12 pub end_time: Option<Instant>,
13 pub rows_processed: usize,
14 pub bytes_processed: usize,
15 pub operations_count: usize,
16}
17
18impl ExecutionMetrics {
19 pub fn new() -> Self {
20 Self {
21 start_time: Instant::now(),
22 end_time: None,
23 rows_processed: 0,
24 bytes_processed: 0,
25 operations_count: 0,
26 }
27 }
28
29 pub fn finish(&mut self) {
30 self.end_time = Some(Instant::now());
31 }
32
33 pub fn duration(&self) -> Option<Duration> {
34 self.end_time.map(|end| end.duration_since(self.start_time))
35 }
36
37 pub fn record_row(&mut self, row_size: usize) {
38 self.rows_processed += 1;
39 self.bytes_processed += row_size;
40 }
41
42 pub fn record_operation(&mut self) {
43 self.operations_count += 1;
44 }
45}
46
47impl Default for ExecutionMetrics {
48 fn default() -> Self {
49 Self::new()
50 }
51}