Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/mempool-logs-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jun 5, 2024
2 parents d477514 + 30e5724 commit 34738f0
Show file tree
Hide file tree
Showing 41 changed files with 2,012 additions and 1,383 deletions.
12 changes: 11 additions & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ disallowed-methods = [

disallowed-types = [
{ path = "std::fs::OpenOptions", reason = "use tycho_storage::FileDb instead" },
]
]

# https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_invalid_type
# until #[must_not_suspend] is stabilized https://github.com/rust-lang/rust/issues/83310
# as advised in (not merged) https://github.com/rust-lang/rust-clippy/pull/8434
[[await-holding-invalid-types]]
path = "tracing::span::Entered"
reason = "drop span guard before `.await` or place your code inside `span.in_scope(|| {..})`"
[[await-holding-invalid-types]]
path = "tracing::span::EnteredSpan"
reason = "drop span guard before `.await` or place your code inside `span.in_scope(|| {..})`"
25 changes: 25 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ tower = "0.4"
tower-http = "0.5"
tracing = "0.1"
tracing-appender = "0.2.3"
tracing-flame = "0.2"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-test = "0.2"
trait-variant = "0.1.2"
Expand Down
25 changes: 16 additions & 9 deletions consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ license.workspace = true
name = "consensus-node"
path = "examples/consensus_node.rs"

[[example]]
name = "engine"
path = "examples/engine/main.rs"

[dependencies]
ahash = { workspace = true }
anyhow = { workspace = true }
arc-swap = { workspace = true }
async-trait = { workspace = true }
bincode = { workspace = true }
bytes = { workspace = true, features = ["serde"] }
dashmap = { workspace = true }
everscale-crypto = { workspace = true }
futures-util = { workspace = true }
itertools = { workspace = true }
metrics = { workspace = true }
parking_lot = { workspace = true }
rand = { workspace = true, features = ["small_rng"] }
rand_pcg = { workspace = true }
Expand All @@ -31,25 +37,26 @@ tokio = { workspace = true, default-features = false }
tracing = { workspace = true }
weedb = { workspace = true }

# examples' dependencies
clap = { workspace = true }
hex = { workspace = true }
serde_json = { workspace = true }
tracing-appender = { workspace = true }

# local deps
tycho-network = { workspace = true }
tycho-storage = { workspace = true }
tycho-util = { workspace = true }

[dev-dependencies]
parking_lot = { workspace = true, features = ["deadlock_detection"] }
tokio = { workspace = true, default-features = false, features = ["rt-multi-thread", "macros"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tikv-jemallocator = { workspace = true, features = [
"unprefixed_malloc_on_supported_platforms",
"background_threads",
]}
] }
tokio = { workspace = true, default-features = false, features = ["rt-multi-thread", "macros"] }
tracing-flame = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }

# examples' dependencies
clap = { workspace = true, features = ["wrap_help"] }
hex = { workspace = true }
serde_json = { workspace = true }
tracing-appender = { workspace = true }

tycho-util = { workspace = true, features = ["test"] }

Expand Down
60 changes: 60 additions & 0 deletions consensus/examples/engine/logger.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#![allow(clippy::exit)]
#![allow(dead_code)]

use tracing_flame::FlameLayer;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;

pub fn spans(test_name: &str, filter: &str) {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::try_new(filter).expect("tracing directives"))
.with_thread_names(true)
.with_target(false)
.with_file(false)
.with_line_number(false)
.try_init()
.ok();

tracing::info!("{test_name}");

std::panic::set_hook(Box::new(|info| {
use std::io::Write;
let backtrace = std::backtrace::Backtrace::capture();

tracing::error!("{info}\n{backtrace}");
std::io::stderr().flush().ok();
std::io::stdout().flush().ok();
std::process::exit(1);
}));
}

pub fn flame(test_name: &str, filter: &str) {
let filter_layer = EnvFilter::try_new(filter).expect("tracing directives");
let fmt_layer = tracing_subscriber::fmt::layer().with_target(false);

std::fs::create_dir_all("./.temp")
.expect("failed to create temp dir for `tracing-flame` output");
let (flame_layer, guard) = FlameLayer::with_file("./.temp/tracing.folded").unwrap();

tracing_subscriber::registry()
.with(flame_layer)
.with(filter_layer)
.with(fmt_layer)
.init();

tracing::info!("{test_name}");

std::panic::set_hook(Box::new(move |info| {
use std::io::Write;
let backtrace = std::backtrace::Backtrace::capture();

if let Err(err) = guard.flush() {
tracing::error!("flame layer not flushed: {err}");
}
tracing::error!("{info}\n{backtrace}");
std::io::stderr().flush().ok();
std::io::stdout().flush().ok();
std::process::exit(1);
}));
}
Loading

0 comments on commit 34738f0

Please sign in to comment.