Skip to content

Commit de94c4e

Browse files
Add set_root bank drop logging (solana-labs#21144) (solana-labs#21194)
(cherry picked from commit 706b60b) Co-authored-by: carllin <[email protected]>
1 parent 74684a1 commit de94c4e

File tree

1 file changed

+70
-17
lines changed

1 file changed

+70
-17
lines changed

runtime/src/bank_forks.rs

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ pub struct SnapshotConfig {
4545
pub maximum_snapshots_to_retain: usize,
4646
}
4747

48+
struct SetRootTimings {
49+
total_banks: i64,
50+
total_squash_cache_ms: i64,
51+
total_squash_accounts_ms: i64,
52+
total_snapshot_ms: i64,
53+
tx_count: i64,
54+
prune_non_rooted_ms: i64,
55+
drop_parent_banks_ms: i64,
56+
}
57+
4858
pub struct BankForks {
4959
banks: HashMap<Slot, Arc<Bank>>,
5060
descendants: HashMap<Slot, HashSet<Slot>>,
@@ -198,15 +208,14 @@ impl BankForks {
198208
self[self.highest_slot()].clone()
199209
}
200210

201-
pub fn set_root(
211+
fn do_set_root_return_metrics(
202212
&mut self,
203213
root: Slot,
204214
accounts_background_request_sender: &AbsRequestSender,
205215
highest_confirmed_root: Option<Slot>,
206-
) {
216+
) -> SetRootTimings {
207217
let old_epoch = self.root_bank().epoch();
208218
self.root = root;
209-
let set_root_start = Instant::now();
210219
let root_bank = self
211220
.banks
212221
.get(&root)
@@ -215,9 +224,9 @@ impl BankForks {
215224
if old_epoch != new_epoch {
216225
info!(
217226
"Root entering
218-
epoch: {},
219-
next_epoch_start_slot: {},
220-
epoch_stakes: {:#?}",
227+
epoch: {},
228+
next_epoch_start_slot: {},
229+
epoch_stakes: {:#?}",
221230
new_epoch,
222231
root_bank
223232
.epoch_schedule()
@@ -249,8 +258,8 @@ impl BankForks {
249258
{
250259
self.last_accounts_hash_slot = bank_slot;
251260
let squash_timing = bank.squash();
252-
total_squash_accounts_ms += squash_timing.squash_accounts_ms;
253-
total_squash_cache_ms += squash_timing.squash_cache_ms;
261+
total_squash_accounts_ms += squash_timing.squash_accounts_ms as i64;
262+
total_squash_cache_ms += squash_timing.squash_cache_ms as i64;
254263
is_root_bank_squashed = bank_slot == root;
255264

256265
let mut snapshot_time = Measure::start("squash::snapshot_time");
@@ -275,20 +284,47 @@ impl BankForks {
275284
}
276285
}
277286
snapshot_time.stop();
278-
total_snapshot_ms += snapshot_time.as_ms();
287+
total_snapshot_ms += snapshot_time.as_ms() as i64;
279288
break;
280289
}
281290
}
282291
if !is_root_bank_squashed {
283292
let squash_timing = root_bank.squash();
284-
total_squash_accounts_ms += squash_timing.squash_accounts_ms;
285-
total_squash_cache_ms += squash_timing.squash_cache_ms;
293+
total_squash_accounts_ms += squash_timing.squash_accounts_ms as i64;
294+
total_squash_cache_ms += squash_timing.squash_cache_ms as i64;
286295
}
287296
let new_tx_count = root_bank.transaction_count();
288297
let mut prune_time = Measure::start("set_root::prune");
289298
self.prune_non_rooted(root, highest_confirmed_root);
290299
prune_time.stop();
291300

301+
let mut drop_parent_banks_time = Measure::start("set_root::drop_banks");
302+
drop(parents);
303+
drop_parent_banks_time.stop();
304+
305+
SetRootTimings {
306+
total_banks: total_banks as i64,
307+
total_squash_cache_ms,
308+
total_squash_accounts_ms,
309+
total_snapshot_ms,
310+
tx_count: (new_tx_count - root_tx_count) as i64,
311+
prune_non_rooted_ms: prune_time.as_ms() as i64,
312+
drop_parent_banks_ms: drop_parent_banks_time.as_ms() as i64,
313+
}
314+
}
315+
316+
pub fn set_root(
317+
&mut self,
318+
root: Slot,
319+
accounts_background_request_sender: &AbsRequestSender,
320+
highest_confirmed_root: Option<Slot>,
321+
) {
322+
let set_root_start = Instant::now();
323+
let set_root_metrics = self.do_set_root_return_metrics(
324+
root,
325+
accounts_background_request_sender,
326+
highest_confirmed_root,
327+
);
292328
datapoint_info!(
293329
"bank-forks_set_root",
294330
(
@@ -297,12 +333,29 @@ impl BankForks {
297333
i64
298334
),
299335
("slot", root, i64),
300-
("total_banks", total_banks, i64),
301-
("total_squash_cache_ms", total_squash_cache_ms, i64),
302-
("total_squash_accounts_ms", total_squash_accounts_ms, i64),
303-
("total_snapshot_ms", total_snapshot_ms, i64),
304-
("tx_count", (new_tx_count - root_tx_count) as usize, i64),
305-
("prune_non_rooted_ms", prune_time.as_ms(), i64),
336+
("total_banks", set_root_metrics.total_banks, i64),
337+
(
338+
"total_squash_cache_ms",
339+
set_root_metrics.total_squash_cache_ms,
340+
i64
341+
),
342+
(
343+
"total_squash_accounts_ms",
344+
set_root_metrics.total_squash_accounts_ms,
345+
i64
346+
),
347+
("total_snapshot_ms", set_root_metrics.total_snapshot_ms, i64),
348+
("tx_count", set_root_metrics.tx_count, i64),
349+
(
350+
"prune_non_rooted_ms",
351+
set_root_metrics.prune_non_rooted_ms,
352+
i64
353+
),
354+
(
355+
"drop_parent_banks_ms",
356+
set_root_metrics.drop_parent_banks_ms,
357+
i64
358+
),
306359
);
307360
}
308361

0 commit comments

Comments
 (0)