From f5be72d59e5993a25dda86a3237a64977e77c237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20Eng=C3=A9libert?= Date: Tue, 24 Mar 2026 16:44:40 +0100 Subject: [PATCH] Count repeat, not recorded sessions --- src/client.rs | 30 ++++++++++++++++++------------ src/record.rs | 20 ++++++++++++++++++++ src/server.rs | 4 +++- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/client.rs b/src/client.rs index 2fa579f..f9a654c 100644 --- a/src/client.rs +++ b/src/client.rs @@ -104,6 +104,7 @@ pub async fn play( // Its handle is released when the task panics. let limiter: &'static _ = Box::leak(Box::new(Semaphore::new(concurrency))); let counter: &'static _ = Box::leak(Box::new(AtomicU32::new(0))); + let counter_repeat: &'static _ = Box::leak(Box::new(AtomicU32::new(0))); let running: &'static _ = Box::leak(Box::new(Mutex::new(HashSet::new()))); let total = records.len() * repeat as usize; let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap(); @@ -268,9 +269,6 @@ pub async fn play( if debug { println!("Client: {} / {}", cnt + 1, total); } - if let Some(notify_socket) = ¬ify_socket { - notify_socket.send(&cnt.to_be_bytes()).ok(); - } let mut running_guard = running.lock().await; running_guard.remove(conn_id); drop(running_guard); @@ -278,9 +276,13 @@ pub async fn play( }); //tokio::time::sleep(std::time::Duration::from_millis(500)).await; } - } - while limiter.available_permits() < concurrency { - tokio::time::sleep(Duration::from_secs(1)).await; + let cnt = counter_repeat.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if debug { + println!("Client: repeat {} / {}", cnt + 1, repeat); + } + if let Some(notify_socket) = ¬ify_socket { + notify_socket.send(&cnt.to_be_bytes()).ok(); + } } } else { for _i in 0..repeat { @@ -351,9 +353,6 @@ pub async fn play( if debug { println!("Client: {} / {}", cnt, total); } - if let Some(notify_socket) = notify_socket { - notify_socket.send(&cnt.to_be_bytes()).ok(); - } let mut running_guard = running.lock().await; running_guard.remove(conn_id); drop(running_guard); @@ -361,10 +360,17 @@ pub async fn play( }); //tokio::time::sleep(std::time::Duration::from_millis(500)).await; } + let cnt = counter_repeat.fetch_add(1, std::sync::atomic::Ordering::Relaxed); + if debug { + println!("Client: repeat {} / {}", cnt + 1, repeat); + } + if let Some(notify_socket) = ¬ify_socket { + notify_socket.send(&cnt.to_be_bytes()).ok(); + } } - while limiter.available_permits() < concurrency { - tokio::time::sleep(Duration::from_secs(1)).await; - } + } + while limiter.available_permits() < concurrency { + tokio::time::sleep(Duration::from_secs(1)).await; } println!("Unfinished: {:?}", running.lock().await); diff --git a/src/record.rs b/src/record.rs index 37c49bd..7b09563 100644 --- a/src/record.rs +++ b/src/record.rs @@ -223,7 +223,22 @@ pub fn read_record_file(path: &str) -> Records { records } +fn round(n: f32, prec: f32) -> f32 { + (n * prec).round() / prec +} + +fn format_size(bytes: u64) -> String { + match bytes { + 0..1024 => format!("{bytes}"), + 1024..0x100000 => format!("{}k", ((bytes * 100 / 1024) as f32).round() / 100.), + 0x100000..0x40000000 => format!("{}M", ((bytes * 100 / 0x100000) as f32).round() / 100.), + 0x40000000.. => format!("{}G", ((bytes * 100 / 0x40000000) as f32).round() / 100.), + } +} + pub fn print_records(records: &Records, number: Option) { + let mut total_c2s = 0; + let mut total_s2c = 0; for (conn_id, (server_name, records)) in records { if let Some(number) = number && number != *conn_id @@ -236,13 +251,18 @@ pub fn print_records(records: &Records, number: Option) { match direction { Direction::ClientToServer => { println!(" ({req_id}) >> {len}"); + total_c2s += len; } Direction::ServerToClient => { println!(" ({req_id}) << {len}"); + total_s2c += len; } } } } + println!("Total:"); + println!(" >> {}", format_size(total_c2s)); + println!(" << {}", format_size(total_s2c)); } pub fn make_test_record(path: &str) { diff --git a/src/server.rs b/src/server.rs index 5536fd3..855d724 100644 --- a/src/server.rs +++ b/src/server.rs @@ -294,7 +294,9 @@ pub async fn play( println!("break timeout"); break; } else { - println!("continue"); + if debug { + println!("continue"); + } continue; } };