Skip to content

Commit

Permalink
refactor: refactoring the code of get revm metric (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymousGiga authored Oct 18, 2023
1 parent e26e1b0 commit 7f17753
Show file tree
Hide file tree
Showing 26 changed files with 131 additions and 146 deletions.
49 changes: 44 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ incremental = false
revm = { git = "https://github.com/megaeth-labs/revm", branch = "andy/debug/performance-dashboard" }
revm-primitives = { git = "https://github.com/megaeth-labs/revm", branch = "andy/debug/performance-dashboard" }

# revm = { path = "/home/andy/Source/work/revm/crates/revm"}
# revm-primitives = { path = "/home/andy/Source/work/revm/crates/primitives" }

[workspace.dependencies]
## reth
Expand Down
16 changes: 7 additions & 9 deletions bin/reth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ boyer-moore-magiclen = "0.2.16"

# performance-dashboard
revm-utils = { git = "https://github.com/megaeth-labs/revm", branch = "andy/debug/performance-dashboard", optional = true }
# revm-utils = { path = "/home/andy/Source/work/revm/crates/utils", optional = true }

parking_lot = { version = "0.12", optional = true }

Expand All @@ -141,15 +140,14 @@ open_performance_dashboard = [
"revm-utils",
"parking_lot",
]
open_revm_metrics_record = [
"reth-revm/open_revm_metrics_record",
"reth-revm-inspectors/open_revm_metrics_record",
"reth-rpc-builder/open_revm_metrics_record",
"reth-basic-payload-builder/open_revm_metrics_record",
"reth-provider/open_revm_metrics_record",
"reth-stages/open_revm_metrics_record",
enable_opcode_metrics = [
"reth-revm/enable_opcode_metrics",
"reth-revm-inspectors/enable_opcode_metrics",
"reth-rpc-builder/enable_opcode_metrics",
"reth-basic-payload-builder/enable_opcode_metrics",
"reth-provider/enable_opcode_metrics",
"reth-stages/enable_opcode_metrics",
]
open_revm_instruction_log = ["reth-revm/open_revm_instruction_log"]
finish_after_execution_stage = ["reth-stages/finish_after_execution_stage"]
enable_execution_duration_record = [
"reth-stages/enable_execution_duration_record",
Expand Down
3 changes: 1 addition & 2 deletions bin/reth/src/performance_metrics/metric_recoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ impl CounterFn for Handle {
}
"sync.execution.execute_inner_time" => {
let mut guard = self.storage.execute_inner_time.lock();
*guard =
(*guard).checked_add(value).expect("counter execute_inner_time overflow");
*guard = (*guard).checked_add(value).expect("counter execute_inner_time overflow");
}
"sync.execution.read_block_info_time" => {
let mut guard = self.storage.read_block_info_time.lock();
Expand Down
6 changes: 3 additions & 3 deletions crates/payload/basic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ metrics.workspace = true
tracing.workspace = true

[features]
open_revm_metrics_record = [
"revm/open_revm_metrics_record",
"reth-revm/open_revm_metrics_record",
enable_opcode_metrics = [
"revm/enable_opcode_metrics",
"reth-revm/enable_opcode_metrics",
]
6 changes: 3 additions & 3 deletions crates/payload/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,14 +707,14 @@ where
cfg: initialized_cfg.clone(),
block: initialized_block_env.clone(),
tx: tx_env_with_recovered(&tx),
// #[cfg(feature = "open_revm_metrics_record")]// Error: why this?
// #[cfg(feature = "enable_opcode_metrics")]// Error: why this?
cpu_frequency: 0f64,
};

let mut evm = revm::EVM::with_env(env);
evm.database(&mut db);

#[cfg(not(feature = "open_revm_metrics_record"))]
#[cfg(not(feature = "enable_opcode_metrics"))]
let ResultAndState { result, state } = match evm.transact() {
Ok(res) => res,
Err(err) => {
Expand All @@ -739,7 +739,7 @@ where
}
};

#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
let ResultAndState { result, state, .. } = match evm.transact() {
Ok(res) => res,
Err(err) => {
Expand Down
10 changes: 4 additions & 6 deletions crates/revm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ reth-consensus-common = { path = "../consensus/common" }
# revm
revm.workspace = true
revm-utils = { git = "https://github.com/megaeth-labs/revm", branch = "andy/debug/performance-dashboard" }
# revm-utils = { path = "/home/andy/Source/work/revm/crates/utils" }

# common
tracing.workspace = true
Expand All @@ -30,8 +29,7 @@ reth-rlp.workspace = true
once_cell = "1.17.0"

[features]
open_revm_metrics_record = [
"revm/open_revm_metrics_record",
"reth-provider/open_revm_metrics_record",
]
open_revm_instruction_log = ["revm/open_revm_instruction_log"]
enable_opcode_metrics = [
"revm/enable_opcode_metrics",
"reth-provider/enable_opcode_metrics",
]
3 changes: 1 addition & 2 deletions crates/revm/revm-inspectors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ tokio = { version = "1", features = ["sync"], optional = true }
[features]
default = ["js-tracer"]
js-tracer = ["boa_engine", "boa_gc", "tokio","thiserror", "serde_json"]
open_revm_metrics_record = ["revm/open_revm_metrics_record"]
open_revm_instruction_log = ["revm/open_revm_instruction_log"]
enable_opcode_metrics = ["revm/enable_opcode_metrics"]
4 changes: 2 additions & 2 deletions crates/revm/revm-inspectors/src/tracing/builder/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ impl ParityTraceBuilder {
where
DB: DatabaseRef,
{
#[cfg(not(feature = "open_revm_metrics_record"))]
#[cfg(not(feature = "enable_opcode_metrics"))]
let ResultAndState { result, state } = res;

#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
let ResultAndState { result, state, .. } = res;

let breadth_first_addresses = if trace_types.contains(&TraceType::VmTrace) {
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/revm-inspectors/src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ impl JsInspector {

/// Calls the result function and returns the result.
pub fn result(&mut self, res: ResultAndState, env: &Env) -> Result<JsValue, JsInspectorError> {
#[cfg(not(feature = "open_revm_metrics_record"))]
#[cfg(not(feature = "enable_opcode_metrics"))]
let ResultAndState { result, state } = res;
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
let ResultAndState { result, state, .. } = res;
let db = EvmDb::new(state, self.to_db_service.clone());

Expand Down
2 changes: 1 addition & 1 deletion crates/revm/revm-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ reth-primitives.workspace = true
revm.workspace = true

[features]
open_revm_metrics_record = ["revm/open_revm_metrics_record",]
enable_opcode_metrics = ["revm/enable_opcode_metrics",]
26 changes: 11 additions & 15 deletions crates/revm/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use revm::{
},
EVM,
};
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
use revm_utils::types::RevmMetricRecord;
use std::{
collections::{BTreeMap, HashMap},
Expand All @@ -38,7 +38,7 @@ where
evm: EVM<SubState<DB>>,
stack: InspectorStack,
/// Used for record duration of instruction.
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
pub revm_metric_record: RevmMetricRecord,
}

Expand All @@ -54,7 +54,7 @@ where
chain_spec,
evm,
stack: InspectorStack::new(InspectorStackConfig::default()),
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
// revm_metric_records: HashMap::new(),
revm_metric_record: RevmMetricRecord::default(),
}
Expand All @@ -74,7 +74,7 @@ where
chain_spec,
evm,
stack: InspectorStack::new(InspectorStackConfig::default()),
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
// revm_metric_records: HashMap::new(),
revm_metric_record: RevmMetricRecord::default(),
}
Expand Down Expand Up @@ -117,7 +117,7 @@ where
header,
total_difficulty,
);
// #[cfg(feature = "open_revm_metrics_record")]// Error: why this?
// #[cfg(feature = "enable_opcode_metrics")]// Error: why this?
self.evm.env.cpu_frequency = revm_utils::time::get_cpu_frequency().unwrap_or_default();
}

Expand Down Expand Up @@ -259,14 +259,14 @@ where
.into())
}
// Execute transaction.
#[cfg(not(feature = "open_revm_metrics_record"))]
#[cfg(not(feature = "enable_opcode_metrics"))]
let ResultAndState { result, state } = self.transact(transaction, sender)?;

#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
let ResultAndState { result, state, mut revm_metric_record } =
self.transact(transaction, sender)?;

#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
{
if revm_metric_record.not_empty() {
self.revm_metric_record.update(&mut revm_metric_record);
Expand Down Expand Up @@ -306,15 +306,11 @@ where
);
}

#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
{
// println!("");
// println!("block number: {:?}, =============================== ", block.number);
// println!("revm result: {:?}", self.revm_metric_record);
// println!(
// "cache_db size is {:?} bytes",
// self.evm.db.as_ref().expect("db is empty").size()
// );
// println!("====================================================");
// println!("");
}
Expand Down Expand Up @@ -393,13 +389,13 @@ where
}

/// Handle revm metric records.
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
fn get_revm_metric_record(&self) -> RevmMetricRecord {
self.revm_metric_record.clone()
}

/// Handle revm metric records.
#[cfg(feature = "open_revm_metrics_record")]
#[cfg(feature = "enable_opcode_metrics")]
fn get_revm_metric_cachedb_size(&self) -> usize {
self.evm.db.as_ref().expect("db is empty").size()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
serde_json.workspace = true

[features]
open_revm_metrics_record = [
"reth-rpc/open_revm_metrics_record",
enable_opcode_metrics = [
"reth-rpc/enable_opcode_metrics",
]
8 changes: 4 additions & 4 deletions crates/rpc/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ tempfile = "3.5.0"
reth-interfaces = { workspace = true, features = ["test-utils"] }

[features]
open_revm_metrics_record = [
"revm/open_revm_metrics_record",
"revm-primitives/open_revm_metrics_record",
"reth-revm/open_revm_metrics_record",
enable_opcode_metrics = [
"revm/enable_opcode_metrics",
"revm-primitives/enable_opcode_metrics",
"reth-revm/enable_opcode_metrics",
]
Loading

0 comments on commit 7f17753

Please sign in to comment.