Skip to content

Commit

Permalink
Remove key_size() method from ledger-tool analyze_storage()
Browse files Browse the repository at this point in the history
We iterate through key-value pairs anyways, so just get the key size
from there.
  • Loading branch information
steviez committed Nov 17, 2023
1 parent ae2bea0 commit 4dc7f09
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,25 +743,31 @@ fn analyze_column<
db: &Database,
name: &str,
) {
let mut key_len: u64 = 0;
let mut key_tot: u64 = 0;
let mut val_hist = histogram::Histogram::new();
let mut val_tot: u64 = 0;
let mut row_hist = histogram::Histogram::new();
let a = C::key_size() as u64;
for (_x, y) in db.iter::<C>(blockstore_db::IteratorMode::Start).unwrap() {
let b = y.len() as u64;
key_tot += a;
val_hist.increment(b).unwrap();
val_tot += b;
row_hist.increment(a + b).unwrap();
for (key, val) in db.iter::<C>(blockstore_db::IteratorMode::Start).unwrap() {
// Key length is fixed, only need to calculate it once
if key_len == 0 {
key_len = C::key(key).len() as u64;
}
let val_len = val.len() as u64;

key_tot += key_len;
val_hist.increment(val_len).unwrap();
val_tot += val_len;

row_hist.increment(key_len + val_len).unwrap();
}

let json_result = if val_hist.entries() > 0 {
json!({
"column":name,
"entries":val_hist.entries(),
"key_stats":{
"max":a,
"max":key_len,
"total_bytes":key_tot,
},
"val_stats":{
Expand Down Expand Up @@ -790,7 +796,7 @@ fn analyze_column<
"column":name,
"entries":val_hist.entries(),
"key_stats":{
"max":a,
"max":key_len,
"total_bytes":0,
},
"val_stats":{
Expand Down

0 comments on commit 4dc7f09

Please sign in to comment.