Skip to content

Commit

Permalink
loaded-programs: Use Measure::end_as_us() (#81)
Browse files Browse the repository at this point in the history
It is a bit nicer API, compared to the `stop()/as_us()` pair.  Does not require the value to be `mut`.
  • Loading branch information
ilya-bobyr authored Apr 2, 2024
1 parent 2643ae8 commit 8cb7000
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 2 additions & 3 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl<'a> InvokeContext<'a> {
timings: &mut ExecuteTimings,
) -> Result<(), InstructionError> {
let instruction_context = self.transaction_context.get_current_instruction_context()?;
let mut process_executable_chain_time = Measure::start("process_executable_chain_time");
let process_executable_chain_time = Measure::start("process_executable_chain_time");

let builtin_id = {
let borrowed_root_account = instruction_context
Expand Down Expand Up @@ -539,13 +539,12 @@ impl<'a> InvokeContext<'a> {
return Err(InstructionError::BuiltinProgramsMustConsumeComputeUnits);
}

process_executable_chain_time.stop();
saturating_add_assign!(
timings
.execute_accessories
.process_instructions
.process_executable_chain_us,
process_executable_chain_time.as_us()
process_executable_chain_time.end_as_us()
);
result
}
Expand Down
15 changes: 6 additions & 9 deletions program-runtime/src/loaded_programs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,27 +335,24 @@ impl LoadedProgram {
metrics: &mut LoadProgramMetrics,
reloading: bool,
) -> Result<Self, Box<dyn std::error::Error>> {
let mut load_elf_time = Measure::start("load_elf_time");
let load_elf_time = Measure::start("load_elf_time");
// The following unused_mut exception is needed for architectures that do not
// support JIT compilation.
#[allow(unused_mut)]
let mut executable = Executable::load(elf_bytes, program_runtime_environment.clone())?;
load_elf_time.stop();
metrics.load_elf_us = load_elf_time.as_us();
metrics.load_elf_us = load_elf_time.end_as_us();

if !reloading {
let mut verify_code_time = Measure::start("verify_code_time");
let verify_code_time = Measure::start("verify_code_time");
executable.verify::<RequisiteVerifier>()?;
verify_code_time.stop();
metrics.verify_code_us = verify_code_time.as_us();
metrics.verify_code_us = verify_code_time.end_as_us();
}

#[cfg(all(not(target_os = "windows"), target_arch = "x86_64"))]
{
let mut jit_compile_time = Measure::start("jit_compile_time");
let jit_compile_time = Measure::start("jit_compile_time");
executable.jit_compile()?;
jit_compile_time.stop();
metrics.jit_compile_us = jit_compile_time.as_us();
metrics.jit_compile_us = jit_compile_time.end_as_us();
}

let program = if bpf_loader_deprecated::check_id(loader_key) {
Expand Down
8 changes: 4 additions & 4 deletions program-runtime/src/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl MessageProcessor {
invoke_context.transaction_context.pop()
})
} else {
let mut time = Measure::start("execute_instruction");
let time = Measure::start("execute_instruction");
let mut compute_units_consumed = 0;
let result = invoke_context.process_instruction(
&instruction.data,
Expand All @@ -115,12 +115,12 @@ impl MessageProcessor {
&mut compute_units_consumed,
timings,
);
time.stop();
let time = time.end_as_us();
*accumulated_consumed_units =
accumulated_consumed_units.saturating_add(compute_units_consumed);
timings.details.accumulate_program(
program_id,
time.as_us(),
time,
compute_units_consumed,
result.is_err(),
);
Expand All @@ -130,7 +130,7 @@ impl MessageProcessor {
};
saturating_add_assign!(
timings.execute_accessories.process_instructions.total_us,
time.as_us()
time
);
result
};
Expand Down

0 comments on commit 8cb7000

Please sign in to comment.