lsm_tree/vlog/gc/
report.rs1use std::path::PathBuf;
6
7#[derive(Debug)]
9#[allow(clippy::module_name_repetitions)]
10pub struct GcReport {
11 pub path: PathBuf,
13
14 pub blob_file_count: usize,
16
17 pub stale_blob_file_count: usize,
19
20 pub total_bytes: u64,
22
23 pub stale_bytes: u64,
25
26 pub total_blobs: u64,
28
29 pub stale_blobs: u64,
31}
32
33impl std::fmt::Display for GcReport {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 writeln!(f, "--- GC report for vLog @ {} ---", self.path.display())?;
36 writeln!(f, "# files : {}", self.blob_file_count)?;
37 writeln!(f, "# stale : {}", self.stale_blob_file_count)?;
38 writeln!(f, "Total bytes: {}", self.total_bytes)?;
39 writeln!(f, "Stale bytes: {}", self.stale_bytes)?;
40 writeln!(f, "Total blobs: {}", self.total_blobs)?;
41 writeln!(f, "Stale blobs: {}", self.stale_blobs)?;
42 writeln!(f, "Stale ratio: {}", self.stale_ratio())?;
43 writeln!(f, "Space amp : {}", self.space_amp())?;
44 writeln!(f, "--- GC report done ---")?;
45 Ok(())
46 }
47}
48
49impl GcReport {
50 #[must_use]
52 pub fn space_amp(&self) -> f32 {
53 if self.total_bytes == 0 {
54 return 0.0;
55 }
56
57 let alive_bytes = self.total_bytes - self.stale_bytes;
58 if alive_bytes == 0 {
59 return 0.0;
60 }
61
62 self.total_bytes as f32 / alive_bytes as f32
63 }
64
65 #[must_use]
67 pub fn stale_ratio(&self) -> f32 {
68 if self.total_bytes == 0 {
69 return 0.0;
70 }
71
72 if self.stale_bytes == 0 {
73 return 0.0;
74 }
75
76 self.stale_bytes as f32 / self.total_bytes as f32
77 }
78}