Use saturating_add_assign macro
This commit is contained in:
parent
deb9344e49
commit
72fc6096a0
|
@ -24,6 +24,7 @@ use {
|
|||
native_loader,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
saturating_add_assign,
|
||||
sysvar::Sysvar,
|
||||
transaction_context::{InstructionAccount, TransactionAccount, TransactionContext},
|
||||
},
|
||||
|
@ -800,12 +801,12 @@ impl<'a> InvokeContext<'a> {
|
|||
let mut verify_caller_time = Measure::start("verify_caller_time");
|
||||
let verify_caller_result = self.verify_and_update(instruction_accounts, true);
|
||||
verify_caller_time.stop();
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_caller_us = timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_caller_us
|
||||
.saturating_add(verify_caller_time.as_us());
|
||||
saturating_add_assign!(
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_caller_us,
|
||||
verify_caller_time.as_us()
|
||||
);
|
||||
verify_caller_result?;
|
||||
|
||||
// Record instruction
|
||||
|
@ -851,18 +852,18 @@ impl<'a> InvokeContext<'a> {
|
|||
});
|
||||
verify_callee_time.stop();
|
||||
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_process_executable_chain_us = timings
|
||||
.execute_accessories
|
||||
.process_instruction_process_executable_chain_us
|
||||
.saturating_add(process_executable_chain_time.as_us());
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_callee_us = timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_callee_us
|
||||
.saturating_add(verify_callee_time.as_us());
|
||||
saturating_add_assign!(
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_process_executable_chain_us,
|
||||
process_executable_chain_time.as_us()
|
||||
);
|
||||
saturating_add_assign!(
|
||||
timings
|
||||
.execute_accessories
|
||||
.process_instruction_verify_callee_us,
|
||||
verify_callee_time.as_us()
|
||||
);
|
||||
|
||||
result
|
||||
});
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use {solana_sdk::pubkey::Pubkey, std::collections::HashMap};
|
||||
use {
|
||||
solana_sdk::{pubkey::Pubkey, saturating_add_assign},
|
||||
std::collections::HashMap,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug, PartialEq)]
|
||||
pub struct ProgramTiming {
|
||||
|
@ -15,23 +18,19 @@ impl ProgramTiming {
|
|||
for tx_error_compute_consumed in self.errored_txs_compute_consumed.drain(..) {
|
||||
let compute_units_update =
|
||||
std::cmp::max(current_estimated_program_cost, tx_error_compute_consumed);
|
||||
self.accumulated_units = self.accumulated_units.saturating_add(compute_units_update);
|
||||
self.count = self.count.saturating_add(1);
|
||||
saturating_add_assign!(self.accumulated_units, compute_units_update);
|
||||
saturating_add_assign!(self.count, 1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn accumulate_program_timings(&mut self, other: &ProgramTiming) {
|
||||
self.accumulated_us = self.accumulated_us.saturating_add(other.accumulated_us);
|
||||
self.accumulated_units = self
|
||||
.accumulated_units
|
||||
.saturating_add(other.accumulated_units);
|
||||
self.count = self.count.saturating_add(other.count);
|
||||
saturating_add_assign!(self.accumulated_us, other.accumulated_us);
|
||||
saturating_add_assign!(self.accumulated_units, other.accumulated_units);
|
||||
saturating_add_assign!(self.count, other.count);
|
||||
// Clones the entire vector, maybe not great...
|
||||
self.errored_txs_compute_consumed
|
||||
.extend(other.errored_txs_compute_consumed.clone());
|
||||
self.total_errored_units = self
|
||||
.total_errored_units
|
||||
.saturating_add(other.total_errored_units);
|
||||
saturating_add_assign!(self.total_errored_units, other.total_errored_units);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,20 +50,14 @@ pub struct ExecuteTimings {
|
|||
|
||||
impl ExecuteTimings {
|
||||
pub fn accumulate(&mut self, other: &ExecuteTimings) {
|
||||
self.check_us = self.check_us.saturating_add(other.check_us);
|
||||
self.load_us = self.load_us.saturating_add(other.load_us);
|
||||
self.execute_us = self.execute_us.saturating_add(other.execute_us);
|
||||
self.store_us = self.store_us.saturating_add(other.store_us);
|
||||
self.update_stakes_cache_us = self
|
||||
.update_stakes_cache_us
|
||||
.saturating_add(other.update_stakes_cache_us);
|
||||
self.total_batches_len = self
|
||||
.total_batches_len
|
||||
.saturating_add(other.total_batches_len);
|
||||
self.num_execute_batches = self
|
||||
.num_execute_batches
|
||||
.saturating_add(other.num_execute_batches);
|
||||
self.collect_logs_us = self.collect_logs_us.saturating_add(other.collect_logs_us);
|
||||
saturating_add_assign!(self.check_us, other.check_us);
|
||||
saturating_add_assign!(self.load_us, other.load_us);
|
||||
saturating_add_assign!(self.execute_us, other.execute_us);
|
||||
saturating_add_assign!(self.store_us, other.store_us);
|
||||
saturating_add_assign!(self.update_stakes_cache_us, other.update_stakes_cache_us);
|
||||
saturating_add_assign!(self.total_batches_len, other.total_batches_len);
|
||||
saturating_add_assign!(self.num_execute_batches, other.num_execute_batches);
|
||||
saturating_add_assign!(self.collect_logs_us, other.collect_logs_us);
|
||||
self.details.accumulate(&other.details);
|
||||
self.execute_accessories
|
||||
.accumulate(&other.execute_accessories);
|
||||
|
@ -86,31 +79,30 @@ pub struct ExecuteAccessoryTimings {
|
|||
|
||||
impl ExecuteAccessoryTimings {
|
||||
pub fn accumulate(&mut self, other: &ExecuteAccessoryTimings) {
|
||||
self.compute_budget_process_transaction_us = self
|
||||
.feature_set_clone_us
|
||||
.saturating_add(other.feature_set_clone_us);
|
||||
self.compute_budget_process_transaction_us = self
|
||||
.compute_budget_process_transaction_us
|
||||
.saturating_add(other.compute_budget_process_transaction_us);
|
||||
self.get_executors_us = self.get_executors_us.saturating_add(other.get_executors_us);
|
||||
self.process_message_us = self
|
||||
.process_message_us
|
||||
.saturating_add(other.process_message_us);
|
||||
self.update_executors_us = self
|
||||
.update_executors_us
|
||||
.saturating_add(other.update_executors_us);
|
||||
self.process_instructions_us = self
|
||||
.process_instructions_us
|
||||
.saturating_add(other.process_instructions_us);
|
||||
self.process_instruction_verify_caller_us = self
|
||||
.process_instruction_verify_caller_us
|
||||
.saturating_add(other.process_instruction_verify_caller_us);
|
||||
self.process_instruction_process_executable_chain_us = self
|
||||
.process_instruction_process_executable_chain_us
|
||||
.saturating_add(other.process_instruction_process_executable_chain_us);
|
||||
self.process_instruction_verify_callee_us = self
|
||||
.process_instruction_verify_callee_us
|
||||
.saturating_add(other.process_instruction_verify_callee_us);
|
||||
saturating_add_assign!(
|
||||
self.compute_budget_process_transaction_us,
|
||||
other.feature_set_clone_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.compute_budget_process_transaction_us,
|
||||
other.compute_budget_process_transaction_us
|
||||
);
|
||||
saturating_add_assign!(self.get_executors_us, other.get_executors_us);
|
||||
saturating_add_assign!(self.process_message_us, other.process_message_us);
|
||||
saturating_add_assign!(self.update_executors_us, other.update_executors_us);
|
||||
saturating_add_assign!(self.process_instructions_us, other.process_instructions_us);
|
||||
saturating_add_assign!(
|
||||
self.process_instruction_verify_caller_us,
|
||||
other.process_instruction_verify_caller_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.process_instruction_process_executable_chain_us,
|
||||
other.process_instruction_process_executable_chain_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.process_instruction_verify_callee_us,
|
||||
other.process_instruction_verify_callee_us
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,35 +125,34 @@ pub struct ExecuteDetailsTimings {
|
|||
}
|
||||
impl ExecuteDetailsTimings {
|
||||
pub fn accumulate(&mut self, other: &ExecuteDetailsTimings) {
|
||||
self.serialize_us = self.serialize_us.saturating_add(other.serialize_us);
|
||||
self.create_vm_us = self.create_vm_us.saturating_add(other.create_vm_us);
|
||||
self.execute_us = self.execute_us.saturating_add(other.execute_us);
|
||||
self.deserialize_us = self.deserialize_us.saturating_add(other.deserialize_us);
|
||||
self.get_or_create_executor_us = self
|
||||
.get_or_create_executor_us
|
||||
.saturating_add(other.get_or_create_executor_us);
|
||||
self.changed_account_count = self
|
||||
.changed_account_count
|
||||
.saturating_add(other.changed_account_count);
|
||||
self.total_account_count = self
|
||||
.total_account_count
|
||||
.saturating_add(other.total_account_count);
|
||||
self.total_data_size = self.total_data_size.saturating_add(other.total_data_size);
|
||||
self.data_size_changed = self
|
||||
.data_size_changed
|
||||
.saturating_add(other.data_size_changed);
|
||||
self.create_executor_register_syscalls_us = self
|
||||
.create_executor_register_syscalls_us
|
||||
.saturating_add(other.create_executor_register_syscalls_us);
|
||||
self.create_executor_load_elf_us = self
|
||||
.create_executor_load_elf_us
|
||||
.saturating_add(other.create_executor_load_elf_us);
|
||||
self.create_executor_verify_code_us = self
|
||||
.create_executor_verify_code_us
|
||||
.saturating_add(other.create_executor_verify_code_us);
|
||||
self.create_executor_jit_compile_us = self
|
||||
.create_executor_jit_compile_us
|
||||
.saturating_add(other.create_executor_jit_compile_us);
|
||||
saturating_add_assign!(self.serialize_us, other.serialize_us);
|
||||
saturating_add_assign!(self.create_vm_us, other.create_vm_us);
|
||||
saturating_add_assign!(self.execute_us, other.execute_us);
|
||||
saturating_add_assign!(self.deserialize_us, other.deserialize_us);
|
||||
saturating_add_assign!(
|
||||
self.get_or_create_executor_us,
|
||||
other.get_or_create_executor_us
|
||||
);
|
||||
saturating_add_assign!(self.changed_account_count, other.changed_account_count);
|
||||
saturating_add_assign!(self.total_account_count, other.total_account_count);
|
||||
saturating_add_assign!(self.total_data_size, other.total_data_size);
|
||||
saturating_add_assign!(self.data_size_changed, other.data_size_changed);
|
||||
saturating_add_assign!(
|
||||
self.create_executor_register_syscalls_us,
|
||||
other.create_executor_register_syscalls_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.create_executor_load_elf_us,
|
||||
other.create_executor_load_elf_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.create_executor_verify_code_us,
|
||||
other.create_executor_verify_code_us
|
||||
);
|
||||
saturating_add_assign!(
|
||||
self.create_executor_jit_compile_us,
|
||||
other.create_executor_jit_compile_us
|
||||
);
|
||||
for (id, other) in &other.per_program_timings {
|
||||
let program_timing = self.per_program_timings.entry(*id).or_default();
|
||||
program_timing.accumulate_program_timings(other);
|
||||
|
|
|
@ -51,6 +51,7 @@ use {
|
|||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
saturating_add_assign,
|
||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||
},
|
||||
std::{cell::RefCell, fmt::Debug, pin::Pin, rc::Rc, sync::Arc},
|
||||
|
@ -335,7 +336,10 @@ fn process_instruction_common(
|
|||
}
|
||||
};
|
||||
get_or_create_executor_time.stop();
|
||||
invoke_context.timings.get_or_create_executor_us += get_or_create_executor_time.as_us();
|
||||
saturating_add_assign!(
|
||||
invoke_context.timings.get_or_create_executor_us,
|
||||
get_or_create_executor_time.as_us()
|
||||
);
|
||||
|
||||
executor.execute(
|
||||
next_first_instruction_account,
|
||||
|
|
|
@ -115,7 +115,7 @@ use {
|
|||
precompiles::get_precompiles,
|
||||
program_utils::limited_deserialize,
|
||||
pubkey::Pubkey,
|
||||
secp256k1_program,
|
||||
saturating_add_assign, secp256k1_program,
|
||||
signature::{Keypair, Signature},
|
||||
slot_hashes::SlotHashes,
|
||||
slot_history::SlotHistory,
|
||||
|
@ -3561,7 +3561,10 @@ impl Bank {
|
|||
&loaded_transaction.program_indices,
|
||||
);
|
||||
get_executors_time.stop();
|
||||
timings.execute_accessories.get_executors_us += get_executors_time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings.execute_accessories.get_executors_us,
|
||||
get_executors_time.as_us()
|
||||
);
|
||||
|
||||
let mut transaction_accounts = Vec::new();
|
||||
std::mem::swap(&mut loaded_transaction.accounts, &mut transaction_accounts);
|
||||
|
@ -3605,12 +3608,18 @@ impl Bank {
|
|||
self.load_accounts_data_len(),
|
||||
);
|
||||
process_message_time.stop();
|
||||
timings.execute_accessories.process_message_us += process_message_time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings.execute_accessories.process_message_us,
|
||||
process_message_time.as_us()
|
||||
);
|
||||
|
||||
let mut update_executors_time = Measure::start("update_executors_time");
|
||||
self.update_executors(process_result.is_ok(), executors);
|
||||
update_executors_time.stop();
|
||||
timings.execute_accessories.update_executors_us += update_executors_time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings.execute_accessories.update_executors_us,
|
||||
update_executors_time.as_us()
|
||||
);
|
||||
|
||||
let status = process_result
|
||||
.map(|info| {
|
||||
|
@ -3712,8 +3721,10 @@ impl Bank {
|
|||
let mut feature_set_clone_time = Measure::start("feature_set_clone");
|
||||
let feature_set = self.feature_set.clone();
|
||||
feature_set_clone_time.stop();
|
||||
timings.execute_accessories.feature_set_clone_us +=
|
||||
feature_set_clone_time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings.execute_accessories.feature_set_clone_us,
|
||||
feature_set_clone_time.as_us()
|
||||
);
|
||||
|
||||
signature_count += u64::from(tx.message().header().num_required_signatures);
|
||||
|
||||
|
@ -3724,10 +3735,12 @@ impl Bank {
|
|||
let process_transaction_result =
|
||||
compute_budget.process_transaction(tx, feature_set);
|
||||
compute_budget_process_transaction_time.stop();
|
||||
timings
|
||||
.execute_accessories
|
||||
.compute_budget_process_transaction_us +=
|
||||
compute_budget_process_transaction_time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings
|
||||
.execute_accessories
|
||||
.compute_budget_process_transaction_us,
|
||||
compute_budget_process_transaction_time.as_us()
|
||||
);
|
||||
if let Err(err) = process_transaction_result {
|
||||
return TransactionExecutionResult::NotExecuted(err);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ use {
|
|||
precompiles::is_precompile,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
saturating_add_assign,
|
||||
sysvar::instructions,
|
||||
transaction::TransactionError,
|
||||
transaction_context::{InstructionAccount, TransactionContext},
|
||||
|
@ -144,7 +145,10 @@ impl MessageProcessor {
|
|||
result.is_err(),
|
||||
);
|
||||
timings.details.accumulate(&invoke_context.timings);
|
||||
timings.execute_accessories.process_instructions_us += time.as_us();
|
||||
saturating_add_assign!(
|
||||
timings.execute_accessories.process_instructions_us,
|
||||
time.as_us()
|
||||
);
|
||||
result
|
||||
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue