Report compute budget usage (#12931)
This commit is contained in:
parent
48283161c3
commit
b510474dcb
|
@ -194,6 +194,11 @@ pub fn process_instruction(
|
||||||
struct ThisInstructionMeter {
|
struct ThisInstructionMeter {
|
||||||
compute_meter: Rc<RefCell<dyn ComputeMeter>>,
|
compute_meter: Rc<RefCell<dyn ComputeMeter>>,
|
||||||
}
|
}
|
||||||
|
impl ThisInstructionMeter {
|
||||||
|
fn new(compute_meter: Rc<RefCell<dyn ComputeMeter>>) -> Self {
|
||||||
|
Self { compute_meter }
|
||||||
|
}
|
||||||
|
}
|
||||||
impl InstructionMeter for ThisInstructionMeter {
|
impl InstructionMeter for ThisInstructionMeter {
|
||||||
fn consume(&mut self, amount: u64) {
|
fn consume(&mut self, amount: u64) {
|
||||||
// 1 to 1 instruction to compute unit mapping
|
// 1 to 1 instruction to compute unit mapping
|
||||||
|
@ -245,13 +250,22 @@ impl Executor for BPFExecutor {
|
||||||
};
|
};
|
||||||
|
|
||||||
log!(logger, "Call BPF program {}", program.unsigned_key());
|
log!(logger, "Call BPF program {}", program.unsigned_key());
|
||||||
let instruction_meter = ThisInstructionMeter { compute_meter };
|
let instruction_meter = ThisInstructionMeter::new(compute_meter.clone());
|
||||||
match vm.execute_program_metered(
|
let before = compute_meter.borrow().get_remaining();
|
||||||
|
let result = vm.execute_program_metered(
|
||||||
parameter_bytes.as_slice(),
|
parameter_bytes.as_slice(),
|
||||||
&[],
|
&[],
|
||||||
&[heap_region],
|
&[heap_region],
|
||||||
instruction_meter,
|
instruction_meter,
|
||||||
) {
|
);
|
||||||
|
let after = compute_meter.borrow().get_remaining();
|
||||||
|
log!(
|
||||||
|
logger,
|
||||||
|
"BPF program consumed {} of {} units",
|
||||||
|
before - after,
|
||||||
|
before
|
||||||
|
);
|
||||||
|
match result {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if status != SUCCESS {
|
if status != SUCCESS {
|
||||||
let error: InstructionError = status.into();
|
let error: InstructionError = status.into();
|
||||||
|
|
Loading…
Reference in New Issue