Add step information to the benchmark report

This commit is contained in:
Omar Abdulla
2025-10-22 14:48:16 +03:00
parent d4019f39a4
commit a5853f86b7
3 changed files with 62 additions and 8 deletions
@@ -1,4 +1,9 @@
use std::{collections::HashMap, pin::Pin, sync::Arc}; use std::{
collections::HashMap,
pin::Pin,
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use alloy::primitives::{BlockNumber, TxHash}; use alloy::primitives::{BlockNumber, TxHash};
use anyhow::Result; use anyhow::Result;
@@ -6,7 +11,7 @@ use futures::{Stream, StreamExt};
use revive_dt_common::types::PlatformIdentifier; use revive_dt_common::types::PlatformIdentifier;
use revive_dt_format::steps::StepPath; use revive_dt_format::steps::StepPath;
use revive_dt_node_interaction::MinedBlockInformation; use revive_dt_node_interaction::MinedBlockInformation;
use revive_dt_report::ExecutionSpecificReporter; use revive_dt_report::{ExecutionSpecificReporter, TransactionInformation};
use tokio::sync::{ use tokio::sync::{
RwLock, RwLock,
mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}, mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel},
@@ -69,7 +74,7 @@ impl Watcher {
// watch for them in the blocks. The watcher will keep watching for blocks until it sees // watch for them in the blocks. The watcher will keep watching for blocks until it sees
// that all of the transactions that it was watching for has been seen in the mined blocks. // that all of the transactions that it was watching for has been seen in the mined blocks.
let watch_for_transaction_hashes = let watch_for_transaction_hashes =
Arc::new(RwLock::new(HashMap::<TxHash, StepPath>::new())); Arc::new(RwLock::new(HashMap::<TxHash, (StepPath, SystemTime)>::new()));
// A boolean that keeps track of whether all of the transactions were submitted or if more // A boolean that keeps track of whether all of the transactions were submitted or if more
// txs are expected to come through the receive side of the channel. We do not want to rely // txs are expected to come through the receive side of the channel. We do not want to rely
@@ -96,7 +101,7 @@ impl Watcher {
watch_for_transaction_hashes watch_for_transaction_hashes
.write() .write()
.await .await
.insert(transaction_hash, step_path); .insert(transaction_hash, (step_path, SystemTime::now()));
} }
WatcherEvent::AllTransactionsSubmitted => { WatcherEvent::AllTransactionsSubmitted => {
*all_transactions_submitted.write().await = true; *all_transactions_submitted.write().await = true;
@@ -108,6 +113,7 @@ impl Watcher {
} }
} }
}; };
let reporter = self.reporter.clone();
let block_information_watching_task = { let block_information_watching_task = {
let watch_for_transaction_hashes = watch_for_transaction_hashes.clone(); let watch_for_transaction_hashes = watch_for_transaction_hashes.clone();
let all_transactions_submitted = all_transactions_submitted.clone(); let all_transactions_submitted = all_transactions_submitted.clone();
@@ -146,7 +152,26 @@ impl Watcher {
let mut watch_for_transaction_hashes = let mut watch_for_transaction_hashes =
watch_for_transaction_hashes.write().await; watch_for_transaction_hashes.write().await;
for tx_hash in block.ethereum_block_information.transaction_hashes.iter() { for tx_hash in block.ethereum_block_information.transaction_hashes.iter() {
watch_for_transaction_hashes.remove(tx_hash); let Some((step_path, submission_time)) =
watch_for_transaction_hashes.remove(tx_hash)
else {
continue;
};
let transaction_information = TransactionInformation {
transaction_hash: *tx_hash,
submission_timestamp: submission_time
.duration_since(UNIX_EPOCH)
.expect("Can't fail")
.as_secs() as _,
block_timestamp: block.ethereum_block_information.block_timestamp,
block_number: block.ethereum_block_information.block_number,
};
reporter
.report_step_transaction_information_event(
step_path,
transaction_information,
)
.expect("Can't fail")
} }
// region:TEMPORARY // region:TEMPORARY
+17 -2
View File
@@ -107,6 +107,10 @@ impl ReportAggregator {
self.handle_completion(*event); self.handle_completion(*event);
break; break;
} }
/* Benchmarks Events */
RunnerEvent::StepTransactionInformation(event) => {
self.handle_step_transaction_information(*event)
}
} }
} }
debug!("Report aggregation completed"); debug!("Report aggregation completed");
@@ -385,6 +389,17 @@ impl ReportAggregator {
self.runner_rx.close(); self.runner_rx.close();
} }
fn handle_step_transaction_information(&mut self, event: StepTransactionInformationEvent) {
self.test_case_report(&event.execution_specifier.test_specifier)
.steps
.entry(event.step_path)
.or_default()
.transactions
.entry(event.execution_specifier.platform_identifier)
.or_default()
.push(event.transaction_information);
}
fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut ExecutionReport { fn test_case_report(&mut self, specifier: &TestSpecifier) -> &mut ExecutionReport {
self.report self.report
.execution_information .execution_information
@@ -466,6 +481,7 @@ pub struct ExecutionReport {
pub metrics: Option<Metrics>, pub metrics: Option<Metrics>,
/// Information related to the execution on one of the platforms. /// Information related to the execution on one of the platforms.
pub platform_execution: PlatformKeyedInformation<Option<ExecutionInformation>>, pub platform_execution: PlatformKeyedInformation<Option<ExecutionInformation>>,
/// Information tracked for each step that was executed.
pub steps: BTreeMap<StepPath, StepReport>, pub steps: BTreeMap<StepPath, StepReport>,
} }
@@ -566,7 +582,7 @@ pub enum CompilationStatus {
} }
/// Information on each step in the execution. /// Information on each step in the execution.
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct StepReport { pub struct StepReport {
/// Information on the transactions submitted as part of this step. /// Information on the transactions submitted as part of this step.
transactions: PlatformKeyedInformation<Vec<TransactionInformation>>, transactions: PlatformKeyedInformation<Vec<TransactionInformation>>,
@@ -579,7 +595,6 @@ pub struct TransactionInformation {
pub submission_timestamp: u64, pub submission_timestamp: u64,
pub block_timestamp: u64, pub block_timestamp: u64,
pub block_number: BlockNumber, pub block_number: BlockNumber,
pub gas_used: u64,
} }
/// The metrics we collect for our benchmarks. /// The metrics we collect for our benchmarks.
+15 -1
View File
@@ -10,9 +10,11 @@ use revive_dt_common::types::PlatformIdentifier;
use revive_dt_compiler::{CompilerInput, CompilerOutput}; use revive_dt_compiler::{CompilerInput, CompilerOutput};
use revive_dt_format::metadata::ContractInstance; use revive_dt_format::metadata::ContractInstance;
use revive_dt_format::metadata::Metadata; use revive_dt_format::metadata::Metadata;
use revive_dt_format::steps::StepPath;
use semver::Version; use semver::Version;
use tokio::sync::{broadcast, oneshot}; use tokio::sync::{broadcast, oneshot};
use crate::TransactionInformation;
use crate::{ExecutionSpecifier, ReporterEvent, TestSpecifier, common::MetadataFilePath}; use crate::{ExecutionSpecifier, ReporterEvent, TestSpecifier, common::MetadataFilePath};
macro_rules! __report_gen_emit_test_specific { macro_rules! __report_gen_emit_test_specific {
@@ -609,7 +611,19 @@ define_event! {
address: Address address: Address
}, },
/// Reports the completion of the run. /// Reports the completion of the run.
Completion {} Completion {},
/* Benchmarks Events */
/// An event emitted with information on a transaction that was submitted for a certain step
/// of the execution.
StepTransactionInformation {
/// A specifier for the execution that's taking place.
execution_specifier: Arc<ExecutionSpecifier>,
/// The path of the step that this transaction belongs to.
step_path: StepPath,
/// Information about the transaction
transaction_information: TransactionInformation
}
} }
} }