Add execute metrics
This commit is contained in:
@ -1,9 +1,14 @@
|
||||
use {
|
||||
crate::{
|
||||
accounts_data_meter::AccountsDataMeter, ic_logger_msg, ic_msg,
|
||||
instruction_recorder::InstructionRecorder, log_collector::LogCollector,
|
||||
native_loader::NativeLoader, pre_account::PreAccount, timings::ExecuteDetailsTimings,
|
||||
accounts_data_meter::AccountsDataMeter,
|
||||
ic_logger_msg, ic_msg,
|
||||
instruction_recorder::InstructionRecorder,
|
||||
log_collector::LogCollector,
|
||||
native_loader::NativeLoader,
|
||||
pre_account::PreAccount,
|
||||
timings::{ExecuteDetailsTimings, ExecuteTimings},
|
||||
},
|
||||
solana_measure::measure::Measure,
|
||||
solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount},
|
||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||
@ -603,6 +608,7 @@ impl<'a> InvokeContext<'a> {
|
||||
&instruction_accounts,
|
||||
&program_indices,
|
||||
&mut compute_units_consumed,
|
||||
&mut ExecuteTimings::default(),
|
||||
)?;
|
||||
|
||||
// Verify the called program has not misbehaved
|
||||
@ -773,6 +779,7 @@ impl<'a> InvokeContext<'a> {
|
||||
instruction_accounts: &[InstructionAccount],
|
||||
program_indices: &[usize],
|
||||
compute_units_consumed: &mut u64,
|
||||
timings: &mut ExecuteTimings,
|
||||
) -> Result<(), InstructionError> {
|
||||
*compute_units_consumed = 0;
|
||||
let program_id = program_indices
|
||||
@ -790,7 +797,16 @@ impl<'a> InvokeContext<'a> {
|
||||
}
|
||||
} else {
|
||||
// Verify the calling program hasn't misbehaved
|
||||
self.verify_and_update(instruction_accounts, true)?;
|
||||
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());
|
||||
verify_caller_result?;
|
||||
|
||||
// Record instruction
|
||||
if let Some(instruction_recorder) = &self.instruction_recorder {
|
||||
@ -805,6 +821,7 @@ impl<'a> InvokeContext<'a> {
|
||||
.map(|instruction_account| instruction_account.index_in_transaction as u8)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
instruction_recorder
|
||||
.borrow_mut()
|
||||
.record_compiled_instruction(compiled_instruction);
|
||||
@ -814,19 +831,40 @@ impl<'a> InvokeContext<'a> {
|
||||
let result = self
|
||||
.push(instruction_accounts, program_indices, instruction_data)
|
||||
.and_then(|_| {
|
||||
let mut process_executable_chain_time =
|
||||
Measure::start("process_executable_chain_time");
|
||||
self.return_data = (program_id, Vec::new());
|
||||
let pre_remaining_units = self.compute_meter.borrow().get_remaining();
|
||||
let execution_result = self.process_executable_chain(instruction_data);
|
||||
let post_remaining_units = self.compute_meter.borrow().get_remaining();
|
||||
*compute_units_consumed = pre_remaining_units.saturating_sub(post_remaining_units);
|
||||
execution_result?;
|
||||
process_executable_chain_time.stop();
|
||||
|
||||
// Verify the called program has not misbehaved
|
||||
if is_lowest_invocation_level {
|
||||
self.verify(instruction_accounts, program_indices)
|
||||
} else {
|
||||
self.verify_and_update(instruction_accounts, false)
|
||||
}
|
||||
let mut verify_callee_time = Measure::start("verify_callee_time");
|
||||
let result = execution_result.and_then(|_| {
|
||||
if is_lowest_invocation_level {
|
||||
self.verify(instruction_accounts, program_indices)
|
||||
} else {
|
||||
self.verify_and_update(instruction_accounts, false)
|
||||
}
|
||||
});
|
||||
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());
|
||||
|
||||
result
|
||||
});
|
||||
|
||||
// Pop the invoke_stack to restore previous state
|
||||
@ -1526,6 +1564,7 @@ mod tests {
|
||||
&inner_instruction_accounts,
|
||||
&program_indices,
|
||||
&mut compute_units_consumed,
|
||||
&mut ExecuteTimings::default(),
|
||||
);
|
||||
|
||||
// Because the instruction had compute cost > 0, then regardless of the execution result,
|
||||
@ -1639,6 +1678,7 @@ mod tests {
|
||||
&instruction_accounts,
|
||||
&[2],
|
||||
&mut 0,
|
||||
&mut ExecuteTimings::default(),
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
@ -1656,6 +1696,7 @@ mod tests {
|
||||
&instruction_accounts,
|
||||
&[2],
|
||||
&mut 0,
|
||||
&mut ExecuteTimings::default(),
|
||||
);
|
||||
|
||||
assert!(result.is_ok());
|
||||
@ -1673,6 +1714,7 @@ mod tests {
|
||||
&instruction_accounts,
|
||||
&[2],
|
||||
&mut 0,
|
||||
&mut ExecuteTimings::default(),
|
||||
);
|
||||
|
||||
assert!(result.is_err());
|
||||
|
@ -46,6 +46,7 @@ pub struct ExecuteTimings {
|
||||
pub num_execute_batches: u64,
|
||||
pub collect_logs_us: u64,
|
||||
pub details: ExecuteDetailsTimings,
|
||||
pub execute_accessories: ExecuteAccessoryTimings,
|
||||
}
|
||||
|
||||
impl ExecuteTimings {
|
||||
@ -65,6 +66,51 @@ impl ExecuteTimings {
|
||||
.saturating_add(other.num_execute_batches);
|
||||
self.collect_logs_us = self.collect_logs_us.saturating_add(other.collect_logs_us);
|
||||
self.details.accumulate(&other.details);
|
||||
self.execute_accessories
|
||||
.accumulate(&other.execute_accessories);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct ExecuteAccessoryTimings {
|
||||
pub feature_set_clone_us: u64,
|
||||
pub compute_budget_process_transaction_us: u64,
|
||||
pub get_executors_us: u64,
|
||||
pub process_message_us: u64,
|
||||
pub update_executors_us: u64,
|
||||
pub process_instructions_us: u64,
|
||||
pub process_instruction_verify_caller_us: u64,
|
||||
pub process_instruction_process_executable_chain_us: u64,
|
||||
pub process_instruction_verify_callee_us: u64,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +120,7 @@ pub struct ExecuteDetailsTimings {
|
||||
pub create_vm_us: u64,
|
||||
pub execute_us: u64,
|
||||
pub deserialize_us: u64,
|
||||
pub get_or_create_executor_us: u64,
|
||||
pub changed_account_count: u64,
|
||||
pub total_account_count: u64,
|
||||
pub total_data_size: usize,
|
||||
@ -86,6 +133,9 @@ impl ExecuteDetailsTimings {
|
||||
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);
|
||||
|
Reference in New Issue
Block a user