feat: add opcount tracer (#2111)

This commit is contained in:
Matthias Seitz
2023-04-05 07:04:50 +02:00
committed by GitHub
parent 59dabcdac0
commit 1913536e81
2 changed files with 39 additions and 0 deletions

View File

@ -18,11 +18,13 @@ mod arena;
mod builder;
mod config;
mod fourbyte;
mod opcount;
mod types;
mod utils;
pub use builder::{geth::GethTraceBuilder, parity::ParityTraceBuilder};
pub use config::TracingInspectorConfig;
pub use fourbyte::FourByteInspector;
pub use opcount::OpcodeCountInspector;
/// An inspector that collects call traces.
///

View File

@ -0,0 +1,37 @@
//! Opcount tracing inspector that simply counts all opcodes.
//!
//! See also <https://geth.ethereum.org/docs/developers/evm-tracing/built-in-tracers>
use revm::{
interpreter::{InstructionResult, Interpreter},
Database, EVMData, Inspector,
};
/// An inspector that counts all opcodes.
#[derive(Debug, Clone, Copy, Default)]
pub struct OpcodeCountInspector {
/// opcode counter
count: usize,
}
impl OpcodeCountInspector {
/// Returns the opcode counter
pub fn count(&self) -> usize {
self.count
}
}
impl<DB> Inspector<DB> for OpcodeCountInspector
where
DB: Database,
{
fn step(
&mut self,
_interp: &mut Interpreter,
_data: &mut EVMData<'_, DB>,
_is_static: bool,
) -> InstructionResult {
self.count += 1;
InstructionResult::Continue
}
}