Count repeat, not recorded sessions

This commit is contained in:
Pascal Engélibert 2026-03-24 16:44:40 +01:00
commit f5be72d59e
3 changed files with 41 additions and 13 deletions

View file

@ -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) {