Skip to main content

liminal/durability/
counting_names.rs

1//! Every counter of a [`StoreCounts`] by name, in the one order its
2//! [`fmt::Display`] prints them in, so two runs compare line by line.
3
4use std::fmt;
5
6use super::StoreCounts;
7
8impl StoreCounts {
9    /// Every counter with its name, in the one fixed order [`fmt::Display`]
10    /// prints them in.
11    #[must_use]
12    pub const fn named(&self) -> [(&'static str, u64); 22] {
13        [
14            ("append_calls", self.append_calls),
15            ("append_rows", self.append_rows),
16            ("append_bytes", self.append_bytes),
17            ("append_all_calls", self.append_all_calls),
18            ("append_all_rows", self.append_all_rows),
19            ("append_all_bytes", self.append_all_bytes),
20            ("read_from_calls", self.read_from_calls),
21            ("read_from_rows", self.read_from_rows),
22            ("read_at_calls", self.read_at_calls),
23            ("read_at_rows", self.read_at_rows),
24            ("cas_calls", self.cas_calls),
25            ("read_value_calls", self.read_value_calls),
26            (
27                "read_stream_next_seq_calls",
28                self.read_stream_next_seq_calls,
29            ),
30            ("scan_page_calls", self.scan_page_calls),
31            ("scan_page_rows", self.scan_page_rows),
32            ("flushes", self.flushes),
33            ("truncate_calls", self.truncate_calls),
34            ("truncate_rows", self.truncate_rows),
35            ("apply_routed_batch_calls", self.apply_routed_batch_calls),
36            ("apply_routed_batch_items", self.apply_routed_batch_items),
37            ("get_routed_calls", self.get_routed_calls),
38            ("get_routed_rows", self.get_routed_rows),
39        ]
40    }
41}
42
43/// One counter per line, `name value`, in the order of [`StoreCounts::named`],
44/// so two runs compare line by line.
45impl fmt::Display for StoreCounts {
46    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
47        for (name, value) in self.named() {
48            writeln!(formatter, "{name} {value}")?;
49        }
50        Ok(())
51    }
52}