add total metrics to ll and lu

This commit is contained in:
Alex 2021-11-04 10:46:16 +01:00
parent 927a369036
commit 2d033eabc4
No known key found for this signature in database
GPG key ID: EDABF9711E244EB1

View file

@ -101,14 +101,19 @@ fn do_command(line: &str, state: &mut State) -> Result<()> {
["ll"] => { ["ll"] => {
let mut names = state.db.tree_names(); let mut names = state.db.tree_names();
names.sort(); names.sort();
let mut total = 0;
for name in names { for name in names {
let nent = state.db.open_tree(&name)?.len(); let nent = state.db.open_tree(&name)?.len();
total += nent;
println!("{:8} {}", nent, try_string(&name)); println!("{:8} {}", nent, try_string(&name));
} }
println!("{:8} TOTAL", total);
} }
["lu"] => { ["lu"] => {
let mut names = state.db.tree_names(); let mut names = state.db.tree_names();
names.sort(); names.sort();
let mut total_nent = 0;
let mut total_size = 0;
for name in names { for name in names {
let tree = state.db.open_tree(&name)?; let tree = state.db.open_tree(&name)?;
let nent = tree.len(); let nent = tree.len();
@ -117,6 +122,8 @@ fn do_command(line: &str, state: &mut State) -> Result<()> {
let (k, v) = ent?; let (k, v) = ent?;
size += k.len() + v.len(); size += k.len() + v.len();
} }
total_nent += nent;
total_size += size;
println!( println!(
"{:8} {:>12} {}", "{:8} {:>12} {}",
nent, nent,
@ -124,6 +131,9 @@ fn do_command(line: &str, state: &mut State) -> Result<()> {
try_string(&name) try_string(&name)
); );
} }
println!("{:8} {:>12} TOTAL",
total_nent,
total_size.file_size(file_size_opts::CONVENTIONAL).unwrap());
} }
["cd", treename] => { ["cd", treename] => {
if state if state