Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: reduce trace output #7148

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/evm/core/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn decode_console_logs(logs: &[Log]) -> Vec<String> {
///
/// This function returns [None] if it is not a DSTest log or the result of a Hardhat
/// `console.log`.
#[instrument(level = "debug", skip_all, fields(topics=?log.data.topics(), data=%log.data.data), ret)]
pub fn decode_console_log(log: &Log) -> Option<String> {
Console::ConsoleEvents::decode_log(log, false).ok().map(|decoded| decoded.to_string())
}
Expand Down
9 changes: 7 additions & 2 deletions crates/evm/traces/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ impl CallTraceDecoder {
pub fn push_function(&mut self, function: Function) {
match self.functions.entry(function.selector()) {
Entry::Occupied(entry) => {
// This shouldn't happen that often
// This shouldn't happen that often.
if entry.get().contains(&function) {
return;
}
debug!(target: "evm::traces", selector=%entry.key(), new=%function.signature(), "duplicate function selector");
trace!(target: "evm::traces", selector=%entry.key(), new=%function.signature(), "duplicate function selector");
entry.into_mut().push(function);
}
Entry::Vacant(entry) => {
Expand Down Expand Up @@ -241,6 +241,11 @@ impl CallTraceDecoder {
}

fn collect_identities(&mut self, identities: Vec<AddressIdentity<'_>>) {
// Skip logging if there are no identities.
if identities.is_empty() {
return;
}

trace!(target: "evm::traces", len=identities.len(), "collecting address identities");
for AddressIdentity { address, label, contract, abi, artifact_id: _ } in identities {
let _span = trace_span!(target: "evm::traces", "identity", ?contract, ?label).entered();
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl CoverageArgs {
}

/// Builds the coverage report.
#[instrument(name = "prepare coverage", skip_all)]
#[instrument(name = "prepare", skip_all)]
fn prepare(&self, config: &Config, output: ProjectCompileOutput) -> Result<CoverageReport> {
let project_paths = config.project_paths();

Expand Down
13 changes: 11 additions & 2 deletions crates/forge/src/multi_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
use alloy_json_abi::{Function, JsonAbi};
use alloy_primitives::{Address, Bytes, U256};
use eyre::{OptionExt, Result};
use foundry_common::{ContractsByArtifact, TestFunctionExt};
use foundry_common::{get_contract_name, ContractsByArtifact, TestFunctionExt};
use foundry_compilers::{contracts::ArtifactContracts, Artifact, ArtifactId, ProjectCompileOutput};
use foundry_evm::{
backend::Backend,
Expand Down Expand Up @@ -202,7 +202,6 @@ impl MultiContractRunner {
})
}

#[instrument(skip_all, fields(name = %name))]
#[allow(clippy::too_many_arguments)]
fn run_tests(
&self,
Expand All @@ -214,6 +213,16 @@ impl MultiContractRunner {
filter: &dyn TestFilter,
test_options: TestOptions,
) -> SuiteResult {
let span = info_span!("run_tests");
if !span.is_disabled() {
if enabled!(tracing::Level::TRACE) {
span.record("contract", name);
} else {
span.record("contract", get_contract_name(name));
}
}
let _guard = span.enter();

let runner = ContractRunner::new(
name,
executor,
Expand Down
27 changes: 24 additions & 3 deletions crates/forge/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,18 @@ impl<'a> ContractRunner<'a> {
///
/// State modifications are not committed to the evm database but discarded after the call,
/// similar to `eth_call`.
#[instrument(name = "test", skip_all, fields(name = %func.signature(), %should_fail))]
pub fn run_test(&self, func: &Function, should_fail: bool, setup: TestSetup) -> TestResult {
let span = info_span!("test", %should_fail);
if !span.is_disabled() {
let sig = &func.signature()[..];
if enabled!(tracing::Level::TRACE) {
span.record("sig", &sig);
} else {
span.record("sig", sig.split('(').next().unwrap());
}
}
let _guard = span.enter();

let TestSetup {
address, mut logs, mut traces, mut labeled_addresses, mut coverage, ..
} = setup;
Expand Down Expand Up @@ -426,7 +436,7 @@ impl<'a> ContractRunner<'a> {
}
}

#[instrument(name = "invariant-test", skip_all)]
#[instrument(name = "invariant_test", skip_all)]
pub fn run_invariant_test(
&self,
runner: TestRunner,
Expand Down Expand Up @@ -555,7 +565,7 @@ impl<'a> ContractRunner<'a> {
}
}

#[instrument(name = "fuzz-test", skip_all, fields(name = %func.signature(), %should_fail))]
#[instrument(name = "fuzz_test", skip_all, fields(name = %func.signature(), %should_fail))]
pub fn run_fuzz_test(
&self,
func: &Function,
Expand All @@ -564,6 +574,17 @@ impl<'a> ContractRunner<'a> {
setup: TestSetup,
fuzz_config: FuzzConfig,
) -> TestResult {
let span = info_span!("fuzz_test", %should_fail);
if !span.is_disabled() {
let sig = &func.signature()[..];
if enabled!(tracing::Level::TRACE) {
span.record("test", &sig);
} else {
span.record("test", sig.split('(').next().unwrap());
}
}
let _guard = span.enter();

let TestSetup {
address, mut logs, mut traces, mut labeled_addresses, mut coverage, ..
} = setup;
Expand Down
Loading