Sort per-program and print a summary of all slots in the range (#25267)
This commit is contained in:
parent
6e5612dd55
commit
cdac141417
|
@ -187,6 +187,7 @@ fn output_slot(
|
||||||
allow_dead_slots: bool,
|
allow_dead_slots: bool,
|
||||||
method: &LedgerOutputMethod,
|
method: &LedgerOutputMethod,
|
||||||
verbose_level: u64,
|
verbose_level: u64,
|
||||||
|
all_program_ids: &mut HashMap<Pubkey, u64>,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
if blockstore.is_dead(slot) {
|
if blockstore.is_dead(slot) {
|
||||||
if allow_dead_slots {
|
if allow_dead_slots {
|
||||||
|
@ -267,7 +268,11 @@ fn output_slot(
|
||||||
" Transactions: {}, hashes: {}, block_hash: {}",
|
" Transactions: {}, hashes: {}, block_hash: {}",
|
||||||
transactions, num_hashes, blockhash,
|
transactions, num_hashes, blockhash,
|
||||||
);
|
);
|
||||||
println!(" Programs: {:?}", program_ids);
|
for (pubkey, count) in program_ids.iter() {
|
||||||
|
*all_program_ids.entry(*pubkey).or_insert(0) += count;
|
||||||
|
}
|
||||||
|
println!(" Programs:");
|
||||||
|
output_sorted_program_ids(program_ids);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -298,6 +303,7 @@ fn output_ledger(
|
||||||
|
|
||||||
let num_slots = num_slots.unwrap_or(Slot::MAX);
|
let num_slots = num_slots.unwrap_or(Slot::MAX);
|
||||||
let mut num_printed = 0;
|
let mut num_printed = 0;
|
||||||
|
let mut all_program_ids = HashMap::new();
|
||||||
for (slot, slot_meta) in slot_iterator {
|
for (slot, slot_meta) in slot_iterator {
|
||||||
if only_rooted && !blockstore.is_root(slot) {
|
if only_rooted && !blockstore.is_root(slot) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -316,7 +322,14 @@ fn output_ledger(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(err) = output_slot(&blockstore, slot, allow_dead_slots, &method, verbose_level) {
|
if let Err(err) = output_slot(
|
||||||
|
&blockstore,
|
||||||
|
slot,
|
||||||
|
allow_dead_slots,
|
||||||
|
&method,
|
||||||
|
verbose_level,
|
||||||
|
&mut all_program_ids,
|
||||||
|
) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
}
|
}
|
||||||
num_printed += 1;
|
num_printed += 1;
|
||||||
|
@ -327,6 +340,18 @@ fn output_ledger(
|
||||||
|
|
||||||
if method == LedgerOutputMethod::Json {
|
if method == LedgerOutputMethod::Json {
|
||||||
stdout().write_all(b"\n]}\n").expect("close array");
|
stdout().write_all(b"\n]}\n").expect("close array");
|
||||||
|
} else {
|
||||||
|
println!("Summary of Programs:");
|
||||||
|
output_sorted_program_ids(all_program_ids);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn output_sorted_program_ids(program_ids: HashMap<Pubkey, u64>) {
|
||||||
|
let mut program_ids_array: Vec<_> = program_ids.into_iter().collect();
|
||||||
|
// Sort descending by count of program id
|
||||||
|
program_ids_array.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
for (program_id, count) in program_ids_array.iter() {
|
||||||
|
println!("{:<44}: {}", program_id.to_string(), count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1965,6 +1990,7 @@ fn main() {
|
||||||
allow_dead_slots,
|
allow_dead_slots,
|
||||||
&LedgerOutputMethod::Print,
|
&LedgerOutputMethod::Print,
|
||||||
verbose_level,
|
verbose_level,
|
||||||
|
&mut HashMap::new(),
|
||||||
) {
|
) {
|
||||||
eprintln!("{}", err);
|
eprintln!("{}", err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ fn nominal() {
|
||||||
let genesis_config = create_genesis_config(100).genesis_config;
|
let genesis_config = create_genesis_config(100).genesis_config;
|
||||||
let ticks_per_slot = genesis_config.ticks_per_slot;
|
let ticks_per_slot = genesis_config.ticks_per_slot;
|
||||||
let meta_lines = 2;
|
let meta_lines = 2;
|
||||||
|
let summary_lines = 1;
|
||||||
|
|
||||||
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
let (ledger_path, _blockhash) = create_new_tmp_ledger!(&genesis_config);
|
||||||
let ticks = ticks_per_slot as usize;
|
let ticks = ticks_per_slot as usize;
|
||||||
|
@ -45,5 +46,8 @@ fn nominal() {
|
||||||
// Print everything
|
// Print everything
|
||||||
let output = run_ledger_tool(&["-l", ledger_path, "print", "-vvv"]);
|
let output = run_ledger_tool(&["-l", ledger_path, "print", "-vvv"]);
|
||||||
assert!(output.status.success());
|
assert!(output.status.success());
|
||||||
assert_eq!(count_newlines(&output.stdout), ticks + meta_lines);
|
assert_eq!(
|
||||||
|
count_newlines(&output.stdout),
|
||||||
|
ticks + meta_lines + summary_lines
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue