Skip to content

Commit a95a845

Browse files
apollo_network_benchmark: setup trace logging in benchmark
1 parent c8c4982 commit a95a845

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_network_benchmark/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ license-file.workspace = true
99
testing = []
1010

1111
[dependencies]
12-
clap = { workspace = true, features = ["derive"] }
12+
clap = { workspace = true, features = ["derive", "env"] }
1313
lazy_static.workspace = true
1414
tokio = { workspace = true, features = ["full", "sync"] }
15+
tracing.workspace = true
16+
tracing-subscriber.workspace = true
1517

1618

1719
[dev-dependencies]

crates/apollo_network_benchmark/src/bin/broadcast_network_stress_test_node/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Runs a node that stress tests the p2p communication of the network.
22
33
use clap::Parser;
4+
use tracing::Level;
45

56
#[cfg(test)]
67
mod message_test;
@@ -11,6 +12,22 @@ use apollo_network_benchmark::node_args::NodeArgs;
1112

1213
#[tokio::main]
1314
async fn main() -> Result<(), Box<dyn std::error::Error>> {
14-
let _args = NodeArgs::parse();
15+
let args = NodeArgs::parse();
16+
17+
let level = match args.user.verbosity {
18+
0 => None,
19+
1 => Some(Level::ERROR),
20+
2 => Some(Level::WARN),
21+
3 => Some(Level::INFO),
22+
4 => Some(Level::DEBUG),
23+
_ => Some(Level::TRACE),
24+
};
25+
tracing::subscriber::set_global_default(
26+
tracing_subscriber::FmtSubscriber::builder().with_max_level(level).finish(),
27+
)
28+
.expect("Failed to set global default subscriber");
29+
30+
println!("Starting network stress test with args:\n{args:?}");
31+
1532
Ok(())
1633
}

crates/apollo_network_benchmark/src/node_args.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@ use clap::Parser;
22

33
#[derive(Parser, Debug, Clone)]
44
#[command(version, about, long_about = None)]
5-
pub struct NodeArgs {}
5+
/// Arguments from the runner, not meant to be set by the user.
6+
pub struct RunnerArgs {}
7+
8+
#[derive(Parser, Debug, Clone)]
9+
#[command(version, about, long_about = None)]
10+
/// Arguments from the user.
11+
pub struct UserArgs {
12+
/// Set the verbosity level of the logger, the higher the more verbose
13+
#[arg(short, long, env, default_value = "2")]
14+
pub verbosity: u8,
15+
}
16+
17+
#[derive(Parser, Debug, Clone)]
18+
#[command(version, about, long_about = None)]
19+
pub struct NodeArgs {
20+
#[command(flatten)]
21+
pub runner: RunnerArgs,
22+
#[command(flatten)]
23+
pub user: UserArgs,
24+
}

0 commit comments

Comments
 (0)