From 339a42f86db5580117dfad91bbb37953a856d5ea Mon Sep 17 00:00:00 2001 From: Alfredo Garcia Date: Thu, 11 Apr 2024 07:41:52 -0300 Subject: [PATCH] change database logs to human readable forms (#8389) --- Cargo.lock | 7 +++++++ zebra-state/Cargo.toml | 1 + .../src/service/finalized_state/disk_db.rs | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2913102..95c80f5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1958,6 +1958,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "human_bytes" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91f255a4535024abf7640cb288260811fc14794f62b063652ed349f9a6c2348e" + [[package]] name = "humantime" version = "2.1.0" @@ -6091,6 +6097,7 @@ dependencies = [ "hex", "hex-literal", "howudoin", + "human_bytes", "humantime-serde", "indexmap 2.2.5", "insta", diff --git a/zebra-state/Cargo.toml b/zebra-state/Cargo.toml index ad63840e..e817d735 100644 --- a/zebra-state/Cargo.toml +++ b/zebra-state/Cargo.toml @@ -53,6 +53,7 @@ futures = "0.3.30" hex = "0.4.3" hex-literal = "0.4.1" humantime-serde = "1.1.1" +human_bytes = { version = "0.4.3", default-features = false } indexmap = "2.2.5" itertools = "0.12.1" lazy_static = "1.4.0" diff --git a/zebra-state/src/service/finalized_state/disk_db.rs b/zebra-state/src/service/finalized_state/disk_db.rs index cc391775..ac0da279 100644 --- a/zebra-state/src/service/finalized_state/disk_db.rs +++ b/zebra-state/src/service/finalized_state/disk_db.rs @@ -542,24 +542,29 @@ impl DiskDb { .unwrap_or(Some(0)); total_size_in_mem += mem_table_size.unwrap_or(0); - // TODO: Consider displaying the disk and memory sizes in a human-readable format - #8380. write!( column_families_log_string, - "{} (Disk: {} bytes, Memory: {} bytes)", + "{} (Disk: {}, Memory: {})", cf_name, - cf_disk_size, - mem_table_size.unwrap_or(0) + human_bytes::human_bytes(cf_disk_size as f64), + human_bytes::human_bytes(mem_table_size.unwrap_or(0) as f64) ) .unwrap(); } debug!("{}", column_families_log_string); - info!("Total Database Disk Size: {} bytes", total_size_on_disk); info!( - "Total Live Data Disk Size: {} bytes", - total_live_size_on_disk + "Total Database Disk Size: {}", + human_bytes::human_bytes(total_size_on_disk as f64) + ); + info!( + "Total Live Data Disk Size: {}", + human_bytes::human_bytes(total_live_size_on_disk as f64) + ); + info!( + "Total Database Memory Size: {}", + human_bytes::human_bytes(total_size_in_mem as f64) ); - info!("Total Database Memory Size: {} bytes", total_size_in_mem); } /// Returns a forward iterator over the items in `cf` in `range`.