diff --git a/crates/revm/revm-inspectors/src/tracing/mod.rs b/crates/revm/revm-inspectors/src/tracing/mod.rs index 8cda4a8002..b5a3415dd4 100644 --- a/crates/revm/revm-inspectors/src/tracing/mod.rs +++ b/crates/revm/revm-inspectors/src/tracing/mod.rs @@ -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. /// diff --git a/crates/revm/revm-inspectors/src/tracing/opcount.rs b/crates/revm/revm-inspectors/src/tracing/opcount.rs new file mode 100644 index 0000000000..c131547477 --- /dev/null +++ b/crates/revm/revm-inspectors/src/tracing/opcount.rs @@ -0,0 +1,37 @@ +//! Opcount tracing inspector that simply counts all opcodes. +//! +//! See also + +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 Inspector 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 + } +}