diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index ecac05a1c1..43122e4f99 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -12,14 +12,16 @@ // ZettaScale Zenoh Team, // use clap::Parser; -use zenoh::{bytes::ZBytes, qos::CongestionControl, shm::ShmProviderBuilder, Config, Wait}; +use zenoh::{ + bytes::ZBytes, key_expr::KeyExpr, qos::CongestionControl, shm::ShmProviderBuilder, Config, Wait, +}; use zenoh_examples::CommonArgs; #[tokio::main] async fn main() { // initiate logging zenoh::init_log_from_env_or("error"); - let (config, sm_size, size) = parse_args(); + let (config, sm_size, size, key_expr) = parse_args(); let z = zenoh::open(config).await.unwrap(); @@ -37,7 +39,7 @@ async fn main() { } let publisher = z - .declare_publisher("test/thr") + .declare_publisher(key_expr) // Make sure to not drop messages because of congestion control .congestion_control(CongestionControl::Block) .await @@ -59,13 +61,17 @@ struct Args { shared_memory: usize, /// Sets the size of the payload to publish. payload_size: usize, + /// The key expression to be used for the throughput test + #[arg(short, long, default_value = "test/thr")] + key_expr: KeyExpr<'static>, + ///Common args for all examples #[command(flatten)] common: CommonArgs, } -fn parse_args() -> (Config, usize, usize) { +fn parse_args() -> (Config, usize, usize, KeyExpr<'static>) { let args = Args::parse(); let sm_size = args.shared_memory * 1024 * 1024; let size = args.payload_size; - (args.common.into(), sm_size, size) + (args.common.into(), sm_size, size, args.key_expr) } diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index dc18715e2a..e6bae45d6e 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -17,6 +17,7 @@ use std::convert::TryInto; use clap::Parser; use zenoh::{ bytes::ZBytes, + key_expr::KeyExpr, qos::{CongestionControl, Priority}, Wait, }; @@ -42,7 +43,7 @@ fn main() { let session = zenoh::open(args.common).wait().unwrap(); let publisher = session - .declare_publisher("test/thr") + .declare_publisher(args.key_expr) .congestion_control(CongestionControl::Block) .priority(prio) .express(args.express) @@ -84,6 +85,10 @@ struct Args { number: usize, /// Sets the size of the payload to publish payload_size: usize, + /// The key expression to be used for the throughput test + #[arg(short, long, default_value = "test/thr")] + key_expr: KeyExpr<'static>, + ///Common args for all examples #[command(flatten)] common: CommonArgs, } diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index 7a5cd54e0c..8ac72aafa1 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -14,7 +14,7 @@ use std::time::Instant; use clap::Parser; -use zenoh::{Config, Wait}; +use zenoh::{key_expr::KeyExpr, Wait}; use zenoh_examples::CommonArgs; struct Stats { @@ -71,24 +71,22 @@ fn main() { // initiate logging zenoh::init_log_from_env_or("error"); - let (config, m, n) = parse_args(); - - let session = zenoh::open(config).wait().unwrap(); + let args = Args::parse(); - let key_expr = "test/thr"; + let session = zenoh::open(args.common).wait().unwrap(); - let mut stats = Stats::new(n); + let mut stats = Stats::new(args.number); session - .declare_subscriber(key_expr) + .declare_subscriber(args.key_expr) .callback_mut(move |_sample| { stats.increment(); - if stats.finished_rounds >= m { + if stats.finished_rounds >= args.samples { std::process::exit(0) } }) .background() .wait() - .unwrap(); + .expect("Failed to open Zenoh session"); println!("Press CTRL-C to quit..."); std::thread::park(); @@ -102,11 +100,10 @@ struct Args { #[arg(short, long, default_value = "100000")] /// Number of messages in each throughput measurements. number: usize, + /// The key expression to be used for the throughput test + #[arg(short, long, default_value = "test/thr")] + key_expr: KeyExpr<'static>, + ///Common args for all examples #[command(flatten)] common: CommonArgs, } - -fn parse_args() -> (Config, usize, usize) { - let args = Args::parse(); - (args.common.into(), args.samples, args.number) -}