openvm_native_compiler/constraints/halo2/
stats.rs

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
#[derive(Default, Clone)]
pub(crate) struct Halo2Stats {
    pub total_gate_cell: usize,
    pub total_fixed: usize,
    pub total_lookup_cell: usize,
}

impl Halo2Stats {
    #[allow(dead_code)]
    pub fn add_assign(&mut self, b: &Self) {
        self.total_gate_cell += b.total_gate_cell;
        self.total_fixed += b.total_fixed;
        self.total_lookup_cell += b.total_lookup_cell;
    }
}

#[cfg(feature = "bench-metrics")]
mod emit {
    use metrics::counter;

    use super::Halo2Stats;

    impl Halo2Stats {
        pub fn diff(&mut self, another: &Self) {
            *self = Self {
                total_gate_cell: self.total_gate_cell - another.total_gate_cell,
                total_fixed: self.total_fixed - another.total_fixed,
                total_lookup_cell: self.total_lookup_cell - another.total_lookup_cell,
            };
        }
        pub fn increment(&self, span_name: String) {
            let labels = [("cell_tracker_span", span_name)];
            counter!("simple_advice_cells", &labels).increment(self.total_gate_cell as u64);
            counter!("fixed_cells", &labels).increment(self.total_fixed as u64);
            counter!("lookup_advice_cells", &labels).increment(self.total_lookup_cell as u64);
        }
    }
}