Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save execution time in call info #22

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = contract_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,
})
}
Loading