raft_log/raft_log/
stat.rs1use std::fmt;
2use std::fmt::Formatter;
3
4use crate::disp::display_option::DebugOption;
5use crate::num::format_pad9_u64;
6use crate::raft_log::state_machine::raft_log_state::RaftLogState;
7use crate::ChunkId;
8use crate::Types;
9
10#[derive(Debug, Clone)]
13pub struct Stat<T>
14where T: Types
15{
16 pub closed_chunks: Vec<ChunkStat<T>>,
18 pub open_chunk: ChunkStat<T>,
20 pub payload_cache_last_evictable: Option<T::LogId>,
22 pub payload_cache_item_count: u64,
24 pub payload_cache_max_item: u64,
26 pub payload_cache_size: u64,
28 pub payload_cache_capacity: u64,
30 pub payload_cache_miss: u64,
32 pub payload_cache_hit: u64,
34}
35
36impl<T> fmt::Display for Stat<T>
37where T: Types
38{
39 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
40 let lb = if f.alternate() { "\n" } else { "" };
41 let idt = if f.alternate() { " " } else { "" };
42 write!(
43 f,
44 "Stat{{{lb} closed_chunks: [{lb}{idt}{}{lb} ],{lb} open_chunk: {},{lb} payload_cache:{{\
45 evictable: ..{:?},\
46 item/max: {} / {},\
47 size/cap: {} / {},\
48 miss: {},\
49 hit: {}\
50 }}{lb}\
51 }}",
52 self.closed_chunks
53 .iter()
54 .map(|c| format!("{}", c))
55 .collect::<Vec<String>>()
56 .join(&format!(",{lb}{idt}")),
57 self.open_chunk,
58 DebugOption(self.payload_cache_last_evictable.as_ref()),
59 format_pad9_u64(self.payload_cache_item_count),
60 format_pad9_u64(self.payload_cache_max_item),
61 format_pad9_u64(self.payload_cache_size),
62 format_pad9_u64(self.payload_cache_capacity),
63 format_pad9_u64(self.payload_cache_miss),
64 format_pad9_u64(self.payload_cache_hit)
65 )
66 }
67}
68
69#[derive(Debug, Clone)]
71pub struct ChunkStat<T>
72where T: Types
73{
74 pub chunk_id: ChunkId,
76 pub records_count: u64,
78 pub global_start: u64,
80 pub global_end: u64,
82 pub size: u64,
84 pub log_state: RaftLogState<T>,
86}
87
88impl<T> fmt::Display for ChunkStat<T>
89where T: Types
90{
91 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
92 write!(
93 f,
94 "ChunkStat({}){{records: {}, [{}, {}), size: {}, log_state: {:?}}}",
95 self.chunk_id,
96 self.records_count,
97 format_pad9_u64(self.global_start),
98 format_pad9_u64(self.global_end),
99 format_pad9_u64(self.size),
100 self.log_state
101 )
102 }
103}