Add vm execution time reporting to rbpf-cli (#18650)

This commit is contained in:
Dmitri Makarov 2021-07-13 19:00:56 -07:00 committed by GitHub
parent c90af3cd63
commit 278a6917f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

1
Cargo.lock generated
View File

@ -3542,6 +3542,7 @@ dependencies = [
"solana-logger 1.8.0",
"solana-sdk",
"solana_rbpf",
"time 0.2.25",
]
[[package]]

View File

@ -16,3 +16,4 @@ solana-bpf-loader-program = { path = "../programs/bpf_loader", version = "=1.8.0
solana-logger = { path = "../logger", version = "=1.8.0" }
solana-sdk = { path = "../sdk", version = "=1.8.0" }
solana_rbpf = "=0.2.13"
time = "0.2.25"

View File

@ -19,6 +19,7 @@ use solana_sdk::{
pubkey::Pubkey,
};
use std::{cell::RefCell, fs::File, io::Read, io::Seek, io::SeekFrom, path::Path};
use time::Instant;
#[derive(Serialize, Deserialize, Debug)]
struct Account {
@ -227,11 +228,13 @@ native machine code before execting it in the virtual machine.",
let id = bpf_loader::id();
let mut vm = create_vm(&id, executable.as_ref(), &mut mem, &mut invoke_context).unwrap();
let start_time = Instant::now();
let result = if matches.value_of("use").unwrap() == "interpreter" {
vm.execute_program_interpreted(&mut instruction_meter)
} else {
vm.execute_program_jit(&mut instruction_meter)
};
let duration = Instant::now() - start_time;
if logger.log.borrow().len() > 0 {
println!("Program output:");
for s in logger.log.borrow_mut().iter() {
@ -241,6 +244,7 @@ native machine code before execting it in the virtual machine.",
}
println!("Result: {:?}", result);
println!("Instruction Count: {}", vm.get_total_instruction_count());
println!("Execution time: {} us", duration.whole_microseconds());
if matches.is_present("trace") {
println!("Trace is saved in trace.out");
let mut file = File::create("trace.out").unwrap();