File size: 1,173 Bytes
d5bfab8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#[derive(Clone, Debug)]
pub enum MetricEvent {
    Funnel { 
        terms10: u64,
        terms20: u64,
        terms30: u64,
        terms40: u64,
        false_positives: u64,
    },
    Cache { 
        hit: u64,
        miss_program_oeis: u64,
        miss_program_without_id: u64,
    },
    Genome {
        cannot_load: u64,
        cannot_parse: u64,
        too_short: u64,
        no_output: u64,
        no_mutation: u64,
        compute_error: u64,
    },
    DependencyManager {
        read_success: u64,
        read_error: u64,
    },
    General {
        number_of_iterations: u64,
        prevent_flooding: u64,
        reject_self_dependency: u64,
        candidate_program: u64,
    }
}

pub trait Recorder: RecorderClone {
    fn record(&self, event: &MetricEvent);
}

pub trait RecorderClone {
    fn clone_box(&self) -> Box<dyn Recorder + Send>;
}

impl<T> RecorderClone for T
where
    T: 'static + Recorder + Clone + Send,
{
    fn clone_box(&self) -> Box<dyn Recorder + Send> {
        Box::new(self.clone())
    }
}

impl Clone for Box<dyn Recorder + Send> {
    fn clone(&self) -> Box<dyn Recorder + Send> { 
        self.clone_box() 
    }
}