Count repeat, not recorded sessions
This commit is contained in:
parent
35417a200a
commit
f5be72d59e
3 changed files with 41 additions and 13 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<u64>) {
|
||||
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<u64>) {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -294,7 +294,9 @@ pub async fn play(
|
|||
println!("break timeout");
|
||||
break;
|
||||
} else {
|
||||
println!("continue");
|
||||
if debug {
|
||||
println!("continue");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue