1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use {
    solana_sdk::clock::{Epoch, Slot},
    std::sync::atomic::{AtomicU64, Ordering::Relaxed},
};

pub(crate) struct NewEpochTimings {
    pub(crate) thread_pool_time_us: u64,
    pub(crate) apply_feature_activations_time_us: u64,
    pub(crate) activate_epoch_time_us: u64,
    pub(crate) update_epoch_stakes_time_us: u64,
    pub(crate) update_rewards_with_thread_pool_time_us: u64,
}

#[derive(Debug, Default)]
pub(crate) struct RewardsMetrics {
    pub(crate) load_vote_and_stake_accounts_us: AtomicU64,
    pub(crate) calculate_points_us: AtomicU64,
    pub(crate) redeem_rewards_us: u64,
    pub(crate) store_stake_accounts_us: AtomicU64,
    pub(crate) store_vote_accounts_us: AtomicU64,
    pub(crate) invalid_cached_vote_accounts: usize,
    pub(crate) invalid_cached_stake_accounts: usize,
    pub(crate) invalid_cached_stake_accounts_rent_epoch: usize,
    pub(crate) vote_accounts_cache_miss_count: usize,
}

pub(crate) struct NewBankTimings {
    pub(crate) bank_rc_creation_time_us: u64,
    pub(crate) total_elapsed_time_us: u64,
    pub(crate) status_cache_time_us: u64,
    pub(crate) fee_components_time_us: u64,
    pub(crate) blockhash_queue_time_us: u64,
    pub(crate) stakes_cache_time_us: u64,
    pub(crate) epoch_stakes_time_us: u64,
    pub(crate) builtin_programs_time_us: u64,
    pub(crate) rewards_pool_pubkeys_time_us: u64,
    pub(crate) executor_cache_time_us: u64,
    pub(crate) transaction_debug_keys_time_us: u64,
    pub(crate) transaction_log_collector_config_time_us: u64,
    pub(crate) feature_set_time_us: u64,
    pub(crate) ancestors_time_us: u64,
    pub(crate) update_epoch_time_us: u64,
    pub(crate) update_sysvars_time_us: u64,
    pub(crate) fill_sysvar_cache_time_us: u64,
}

pub(crate) fn report_new_epoch_metrics(
    epoch: Epoch,
    slot: Slot,
    parent_slot: Slot,
    timings: NewEpochTimings,
    metrics: RewardsMetrics,
) {
    datapoint_info!(
        "bank-new_from_parent-new_epoch_timings",
        ("epoch", epoch, i64),
        ("slot", slot, i64),
        ("parent_slot", parent_slot, i64),
        ("thread_pool_creation_us", timings.thread_pool_time_us, i64),
        (
            "apply_feature_activations",
            timings.apply_feature_activations_time_us,
            i64
        ),
        ("activate_epoch_us", timings.activate_epoch_time_us, i64),
        (
            "update_epoch_stakes_us",
            timings.update_epoch_stakes_time_us,
            i64
        ),
        (
            "update_rewards_with_thread_pool_us",
            timings.update_rewards_with_thread_pool_time_us,
            i64
        ),
        (
            "load_vote_and_stake_accounts_us",
            metrics.load_vote_and_stake_accounts_us.load(Relaxed),
            i64
        ),
        (
            "calculate_points_us",
            metrics.calculate_points_us.load(Relaxed),
            i64
        ),
        ("redeem_rewards_us", metrics.redeem_rewards_us, i64),
        (
            "store_stake_accounts_us",
            metrics.store_stake_accounts_us.load(Relaxed),
            i64
        ),
        (
            "store_vote_accounts_us",
            metrics.store_vote_accounts_us.load(Relaxed),
            i64
        ),
        (
            "invalid_cached_vote_accounts",
            metrics.invalid_cached_vote_accounts,
            i64
        ),
        (
            "invalid_cached_stake_accounts",
            metrics.invalid_cached_stake_accounts,
            i64
        ),
        (
            "invalid_cached_stake_accounts_rent_epoch",
            metrics.invalid_cached_stake_accounts_rent_epoch,
            i64
        ),
        (
            "vote_accounts_cache_miss_count",
            metrics.vote_accounts_cache_miss_count,
            i64
        ),
    );
}

pub(crate) fn report_new_bank_metrics(
    slot: Slot,
    parent_slot: Slot,
    block_height: u64,
    timings: NewBankTimings,
) {
    datapoint_info!(
        "bank-new_from_parent-heights",
        ("slot", slot, i64),
        ("block_height", block_height, i64),
        ("parent_slot", parent_slot, i64),
        ("bank_rc_creation_us", timings.bank_rc_creation_time_us, i64),
        ("total_elapsed_us", timings.total_elapsed_time_us, i64),
        ("status_cache_us", timings.status_cache_time_us, i64),
        ("fee_components_us", timings.fee_components_time_us, i64),
        ("blockhash_queue_us", timings.blockhash_queue_time_us, i64),
        ("stakes_cache_us", timings.stakes_cache_time_us, i64),
        ("epoch_stakes_time_us", timings.epoch_stakes_time_us, i64),
        ("builtin_programs_us", timings.builtin_programs_time_us, i64),
        (
            "rewards_pool_pubkeys_us",
            timings.rewards_pool_pubkeys_time_us,
            i64
        ),
        ("executor_cache_us", timings.executor_cache_time_us, i64),
        (
            "transaction_debug_keys_us",
            timings.transaction_debug_keys_time_us,
            i64
        ),
        (
            "transaction_log_collector_config_us",
            timings.transaction_log_collector_config_time_us,
            i64
        ),
        ("feature_set_us", timings.feature_set_time_us, i64),
        ("ancestors_us", timings.ancestors_time_us, i64),
        ("update_epoch_us", timings.update_epoch_time_us, i64),
        ("update_sysvars_us", timings.update_sysvars_time_us, i64),
        (
            "fill_sysvar_cache_us",
            timings.fill_sysvar_cache_time_us,
            i64
        ),
    );
}