diff options
| author | ache <ache@ache.one> | 2026-08-04 16:53:42 +0200 |
|---|---|---|
| committer | ache <ache@ache.one> | 2026-08-04 17:00:54 +0200 |
| commit | 1d1736e742e2328d12503ee81ac51e1c2de3e35e (patch) | |
| tree | d83dd4654b4186414e3c9b144f20b1d9b289957d /src/main.rs | |
| parent | Add stats computing (diff) | |
Print stats
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 9181bf6..f6ac365 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,8 +13,9 @@ mod stats; use args::Args; use ip::parse_ip; use pinger::{spawn_ping, PingResult}; -use print::{print_ping_line, print_legende_line}; +use print::{print_last_ping_line, print_legende_line, print_ping_line, print_stats}; use state::State; +use stats::compute_stats; #[tokio::main] async fn main() { @@ -69,9 +70,9 @@ async fn main() { // Update the state of the received packet Ok(result) => { match result { - PingResult::Ping { rrt, ttl, id } => { + PingResult::Ping { rtt, ttl, id } => { if (id as usize) < states.len() { - states[id as usize] = State::Received { rtt: rrt, ttl }; + states[id as usize] = State::Received { rtt: rtt, ttl }; } } PingResult::NoPingErr { id: _, ref error } => { @@ -101,6 +102,22 @@ async fn main() { // Prints lines based on the state of each ping print_ping_line(&states); + // Print stats + if args.stats { + if let Some(stats) = compute_stats(&states) { + print_stats(&stats); + } + // Print stats of the last 30 pings + // let firstIndex = if states.len() - 30 > 0 { + // states.len() - 30 + // } else { + // 0 + // }; + // if let Some(stats) = compute_stats(&states[firstIndex..]) { + // print_stats(&stats); + // } + } + // Sleep for 1 second before the next ping // FEAT: Should be configurable via CLI |