Skip to content

Commit

Permalink
Add total accounts stats to ledger-tool accounts (#21187)
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo authored Nov 8, 2021
1 parent 5827cf4 commit 6f3c27f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ledger-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ solana-core = { path = "../core", version = "=1.9.0" }
solana-entry = { path = "../entry", version = "=1.9.0" }
solana-ledger = { path = "../ledger", version = "=1.9.0" }
solana-logger = { path = "../logger", version = "=1.9.0" }
solana-measure = { path = "../measure", version = "=1.9.0" }
solana-runtime = { path = "../runtime", version = "=1.9.0" }
solana-sdk = { path = "../sdk", version = "=1.9.0" }
solana-stake-program = { path = "../programs/stake", version = "=1.9.0" }
Expand Down
36 changes: 29 additions & 7 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ use solana_ledger::{
blockstore_processor::ProcessOptions,
shred::Shred,
};
use solana_measure::measure::Measure;
use solana_runtime::{
accounts_db::AccountsDbConfig,
accounts_index::AccountsIndexConfig,
bank::{Bank, RewardCalculationEvent},
bank::{Bank, RewardCalculationEvent, TotalAccountsStats},
bank_forks::BankForks,
cost_model::CostModel,
cost_tracker::CostTracker,
Expand Down Expand Up @@ -1413,7 +1414,7 @@ fn main() {
)
).subcommand(
SubCommand::with_name("accounts")
.about("Print account contents after processing in the ledger")
.about("Print account stats and contents after processing the ledger")
.arg(&no_snapshot_arg)
.arg(&account_paths_arg)
.arg(&halt_at_slot_arg)
Expand Down Expand Up @@ -2495,6 +2496,7 @@ fn main() {
});

let bank = bank_forks.working_bank();
let mut measure = Measure::start("getting accounts");
let accounts: BTreeMap<_, _> = bank
.get_all_accounts_with_modified_slots()
.unwrap()
Expand All @@ -2504,13 +2506,29 @@ fn main() {
})
.map(|(pubkey, account, slot)| (pubkey, (account, slot)))
.collect();
measure.stop();
info!("{}", measure);

let print_account_contents = !arg_matches.is_present("no_account_contents");
if print_account_contents {
println!("Getting accounts contents...");
let print_account_data = !arg_matches.is_present("no_account_data");
for (pubkey, (account, slot)) in accounts.into_iter() {
let data_len = account.data().len();
let print_account_data = !arg_matches.is_present("no_account_data");
let rent_collector = bank.rent_collector();
let mut total_accounts_stats = TotalAccountsStats::default();
let mut measure = Measure::start("processing accounts");
for (pubkey, (account, slot)) in accounts.into_iter() {
let data_len = account.data().len();
total_accounts_stats.num_accounts += 1;
total_accounts_stats.data_len += data_len;
if account.executable() {
total_accounts_stats.num_executable_accounts += 1;
total_accounts_stats.executable_data_len += data_len;
}
if !rent_collector.should_collect_rent(&pubkey, &account, false)
|| rent_collector.get_rent_due(&account).1
{
total_accounts_stats.num_rent_exempt_accounts += 1;
}

if print_account_contents {
println!("{}:", pubkey);
println!(" - balance: {} SOL", lamports_to_sol(account.lamports()));
println!(" - owner: '{}'", account.owner());
Expand All @@ -2523,6 +2541,10 @@ fn main() {
println!(" - data_len: {}", data_len);
}
}
measure.stop();
info!("{}", measure);

println!("{:#?}", total_accounts_stats);
}
("capitalization", Some(arg_matches)) => {
let dev_halt_at_slot = value_t!(arg_matches, "halt_at_slot", Slot).ok();
Expand Down

0 comments on commit 6f3c27f

Please sign in to comment.