openvm_native_compiler/constraints/halo2/
stats.rs
1#[derive(Default, Clone)]
2pub(crate) struct Halo2Stats {
3 pub total_gate_cell: usize,
4 pub total_fixed: usize,
5 pub total_lookup_cell: usize,
6}
7
8impl Halo2Stats {
9 #[allow(dead_code)]
10 pub fn add_assign(&mut self, b: &Self) {
11 self.total_gate_cell += b.total_gate_cell;
12 self.total_fixed += b.total_fixed;
13 self.total_lookup_cell += b.total_lookup_cell;
14 }
15}
16
17#[cfg(feature = "bench-metrics")]
18mod emit {
19 use metrics::counter;
20
21 use super::Halo2Stats;
22
23 impl Halo2Stats {
24 pub fn diff(&mut self, another: &Self) {
25 *self = Self {
26 total_gate_cell: self.total_gate_cell - another.total_gate_cell,
27 total_fixed: self.total_fixed - another.total_fixed,
28 total_lookup_cell: self.total_lookup_cell - another.total_lookup_cell,
29 };
30 }
31 pub fn increment(&self, span_name: String) {
32 let labels = [("cell_tracker_span", span_name)];
33 counter!("simple_advice_cells", &labels).increment(self.total_gate_cell as u64);
34 counter!("fixed_cells", &labels).increment(self.total_fixed as u64);
35 counter!("lookup_advice_cells", &labels).increment(self.total_lookup_cell as u64);
36 }
37 }
38}