Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
adding row for total db size in db stats command (paradigmxyz#3777)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
2 people authored and merklefruit committed Jul 27, 2023
1 parent b1c5b68 commit a457cb8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bin/reth/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl Command {
let mut tables =
Tables::ALL.iter().map(|table| table.name()).collect::<Vec<_>>();
tables.sort();
let mut total_size = 0;
for table in tables {
let table_db =
tx.inner.open_db(Some(table)).wrap_err("Could not open db.")?;
Expand All @@ -123,6 +124,7 @@ impl Command {
let num_pages = leaf_pages + branch_pages + overflow_pages;
let table_size = page_size * num_pages;

total_size += table_size;
let mut row = Row::new();
row.add_cell(Cell::new(table))
.add_cell(Cell::new(stats.entries()))
Expand All @@ -132,6 +134,24 @@ impl Command {
.add_cell(Cell::new(human_bytes(table_size as f64)));
stats_table.add_row(row);
}

let max_widths = stats_table.column_max_content_widths();

let mut seperator = Row::new();
for width in max_widths {
seperator.add_cell(Cell::new("-".repeat(width as usize)));
}
stats_table.add_row(seperator);

let mut row = Row::new();
row.add_cell(Cell::new("Total DB size"))
.add_cell(Cell::new(""))
.add_cell(Cell::new(""))
.add_cell(Cell::new(""))
.add_cell(Cell::new(""))
.add_cell(Cell::new(human_bytes(total_size as f64)));
stats_table.add_row(row);

Ok::<(), eyre::Report>(())
})??;

Expand Down

0 comments on commit a457cb8

Please sign in to comment.