Skip to content

Commit

Permalink
Save execution time in call info
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Dec 4, 2024
1 parent bfc5b6b commit ba98788
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub struct CallInfo {
pub charged_resources: ChargedResources,

// Additional information gathered during execution.
pub time: std::time::Duration,
pub storage_read_values: Vec<Felt>,
pub accessed_storage_keys: HashSet<StorageKey>,
pub read_class_hash_values: Vec<ClassHash>,
Expand Down
6 changes: 6 additions & 0 deletions crates/blockifier/src/execution/entry_point_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub fn execute_entry_point_call(
state: &mut dyn State,
context: &mut EntryPointExecutionContext,
) -> EntryPointExecutionResult<CallInfo> {
let pre_time = std::time::Instant::now();

// Fetch the class hash from `call`.
let class_hash = call.class_hash.ok_or(EntryPointExecutionError::InternalError(
"Class hash must not be None when executing an entry point.".into(),
Expand Down Expand Up @@ -99,12 +101,14 @@ pub fn execute_entry_point_call(
bytecode_length,
)?;

let time = pre_time.elapsed();
Ok(finalize_execution(
runner,
syscall_handler,
n_total_args,
program_extra_data_length,
tracked_resource,
time,
)?)
}

Expand Down Expand Up @@ -392,6 +396,7 @@ pub fn finalize_execution(
n_total_args: usize,
program_extra_data_length: usize,
tracked_resource: TrackedResource,
time: std::time::Duration,
) -> Result<CallInfo, PostExecutionError> {
// Close memory holes in segments (OS code touches those memory cells, we simulate it).
let program_start_ptr = runner
Expand Down Expand Up @@ -454,6 +459,7 @@ pub fn finalize_execution(
accessed_storage_keys: syscall_handler_base.accessed_keys,
read_class_hash_values: syscall_handler_base.read_class_hash_values,
accessed_contract_addresses: syscall_handler_base.accessed_contract_addresses,
time,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub fn execute_entry_point_call(
state: &mut dyn State,
context: &mut EntryPointExecutionContext,
) -> EntryPointExecutionResult<CallInfo> {
let pre_time = std::time::Instant::now();

let entry_point = compiled_class.get_entry_point(&call)?;

let mut syscall_handler: NativeSyscallHandler<'_> =
Expand Down Expand Up @@ -54,12 +56,14 @@ pub fn execute_entry_point_call(
return Err(EntryPointExecutionError::NativeUnrecoverableError(Box::new(error)));
}

create_callinfo(call_result, syscall_handler)
let time = pre_time.elapsed();
create_callinfo(call_result, syscall_handler, time)
}

fn create_callinfo(
call_result: ContractExecutionResult,
syscall_handler: NativeSyscallHandler<'_>,
time: std::time::Duration,
) -> Result<CallInfo, EntryPointExecutionError> {
let remaining_gas = call_result.remaining_gas;

Expand Down Expand Up @@ -99,5 +103,6 @@ fn create_callinfo(
accessed_contract_addresses: syscall_handler.base.accessed_contract_addresses,
read_class_hash_values: syscall_handler.base.read_class_hash_values,
tracked_resource: TrackedResource::SierraGas,
time,
})
}

0 comments on commit ba98788

Please sign in to comment.