From c54db4f757d5c672b8f3e57005ba46dd559ff709 Mon Sep 17 00:00:00 2001 From: Bjerg Date: Fri, 24 Feb 2023 18:36:49 +0100 Subject: [PATCH] feat: format table sizes (#1543) --- Cargo.lock | 7 +++++++ bin/reth/Cargo.toml | 3 ++- bin/reth/src/db/mod.rs | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92d4c133f6..c763713b8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2529,6 +2529,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +[[package]] +name = "human_bytes" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39b528196c838e8b3da8b665e08c30958a6f2ede91d79f2ffcd0d4664b9c64eb" + [[package]] name = "humantime" version = "2.1.0" @@ -4349,6 +4355,7 @@ dependencies = [ "eyre", "fdlimit", "futures", + "human_bytes", "jsonrpsee", "metrics", "metrics-exporter-prometheus", diff --git a/bin/reth/Cargo.toml b/bin/reth/Cargo.toml index 4e32f4e5a6..fea91f9e8b 100644 --- a/bin/reth/Cargo.toml +++ b/bin/reth/Cargo.toml @@ -63,4 +63,5 @@ backon = "0.4" comfy-table = "6.1.4" crossterm = "0.25.0" tui = "0.19.0" -jsonrpsee = { version = "0.16", features = ["server"] } \ No newline at end of file +jsonrpsee = { version = "0.16", features = ["server"] } +human_bytes = "0.4.1" \ No newline at end of file diff --git a/bin/reth/src/db/mod.rs b/bin/reth/src/db/mod.rs index 4e215ef22e..6a9ccd48f4 100644 --- a/bin/reth/src/db/mod.rs +++ b/bin/reth/src/db/mod.rs @@ -3,6 +3,7 @@ use crate::dirs::{DbPath, PlatformPath}; use clap::{Parser, Subcommand}; use comfy_table::{Cell, Row, Table as ComfyTable}; use eyre::{Result, WrapErr}; +use human_bytes::human_bytes; use reth_db::{ cursor::{DbCursorRO, Walker}, database::Database, @@ -91,7 +92,7 @@ impl Command { "Branch Pages", "Leaf Pages", "Overflow Pages", - "Total Size (KB)", + "Total Size", ]); tool.db.view(|tx| { @@ -120,7 +121,7 @@ impl Command { .add_cell(Cell::new(branch_pages)) .add_cell(Cell::new(leaf_pages)) .add_cell(Cell::new(overflow_pages)) - .add_cell(Cell::new(table_size / 1024)); + .add_cell(Cell::new(human_bytes(table_size as f64))); stats_table.add_row(row); } Ok::<(), eyre::Report>(())