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.
|
// Its handle is released when the task panics.
|
||||||
let limiter: &'static _ = Box::leak(Box::new(Semaphore::new(concurrency)));
|
let limiter: &'static _ = Box::leak(Box::new(Semaphore::new(concurrency)));
|
||||||
let counter: &'static _ = Box::leak(Box::new(AtomicU32::new(0)));
|
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 running: &'static _ = Box::leak(Box::new(Mutex::new(HashSet::new())));
|
||||||
let total = records.len() * repeat as usize;
|
let total = records.len() * repeat as usize;
|
||||||
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
|
let connect_to = connect_to.to_socket_addrs().unwrap().next().unwrap();
|
||||||
|
|
@ -268,9 +269,6 @@ pub async fn play(
|
||||||
if debug {
|
if debug {
|
||||||
println!("Client: {} / {}", cnt + 1, total);
|
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;
|
let mut running_guard = running.lock().await;
|
||||||
running_guard.remove(conn_id);
|
running_guard.remove(conn_id);
|
||||||
drop(running_guard);
|
drop(running_guard);
|
||||||
|
|
@ -278,9 +276,13 @@ pub async fn play(
|
||||||
});
|
});
|
||||||
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
//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;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _i in 0..repeat {
|
for _i in 0..repeat {
|
||||||
|
|
@ -351,9 +353,6 @@ pub async fn play(
|
||||||
if debug {
|
if debug {
|
||||||
println!("Client: {} / {}", cnt, total);
|
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;
|
let mut running_guard = running.lock().await;
|
||||||
running_guard.remove(conn_id);
|
running_guard.remove(conn_id);
|
||||||
drop(running_guard);
|
drop(running_guard);
|
||||||
|
|
@ -361,11 +360,18 @@ pub async fn play(
|
||||||
});
|
});
|
||||||
//tokio::time::sleep(std::time::Duration::from_millis(500)).await;
|
//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 {
|
while limiter.available_permits() < concurrency {
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
println!("Unfinished: {:?}", running.lock().await);
|
println!("Unfinished: {:?}", running.lock().await);
|
||||||
|
|
||||||
if let Some(notify_socket) = notify_socket {
|
if let Some(notify_socket) = notify_socket {
|
||||||
|
|
|
||||||
|
|
@ -223,7 +223,22 @@ pub fn read_record_file(path: &str) -> Records {
|
||||||
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>) {
|
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 {
|
for (conn_id, (server_name, records)) in records {
|
||||||
if let Some(number) = number
|
if let Some(number) = number
|
||||||
&& number != *conn_id
|
&& number != *conn_id
|
||||||
|
|
@ -236,13 +251,18 @@ pub fn print_records(records: &Records, number: Option<u64>) {
|
||||||
match direction {
|
match direction {
|
||||||
Direction::ClientToServer => {
|
Direction::ClientToServer => {
|
||||||
println!(" ({req_id}) >> {len}");
|
println!(" ({req_id}) >> {len}");
|
||||||
|
total_c2s += len;
|
||||||
}
|
}
|
||||||
Direction::ServerToClient => {
|
Direction::ServerToClient => {
|
||||||
println!(" ({req_id}) << {len}");
|
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) {
|
pub fn make_test_record(path: &str) {
|
||||||
|
|
|
||||||
|
|
@ -294,7 +294,9 @@ pub async fn play(
|
||||||
println!("break timeout");
|
println!("break timeout");
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
if debug {
|
||||||
println!("continue");
|
println!("continue");
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue