From 43f6e3498e360b6b6101795a72dfaa78cde33b17 Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 30 Jul 2020 09:04:04 +0200 Subject: [PATCH] print lost pings in loop and count mode, fixes #175 --- CHANGELOG.md | 27 ++++++++++++++++++++++----- ci/test-08-options-n-q.pl | 7 ++++++- src/fping.c | 25 ++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4566b02..2c872ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,30 @@ fping 5.0 (unreleased) ====================== +## Incompatible Changes + +- In non-quiet loop and count mode, a line is printed for every lost packet + (#175, thanks @kbucheli): + + ``` + $ fping -D -c2 8.8.8.8 8.8.8.7 + [1596092373.18423] 8.8.8.8 : [0], 84 bytes, 12.8 ms (12.8 avg, 0% loss) + [1596092374.18223] 8.8.8.7 : [0], timed out (NaN avg, 100% loss) + [1596092374.18424] 8.8.8.8 : [1], 84 bytes, 12.3 ms (12.5 avg, 0% loss) + [1596092375.18344] 8.8.8.7 : [1], timed out (NaN avg, 100% loss) + + 8.8.8.8 : xmt/rcv/%loss = 2/2/0%, min/avg/max = 12.3/12.5/12.8 + 8.8.8.7 : xmt/rcv/%loss = 2/0/100% + ``` + ## New features -- Refactored event loop, now allowing for period (-p) to be smaller than - timeout (-t). The number of sent pings is now only incremented when the - response is received or when the timeout happens, so that the loss statistic - is always correct (especially important when using interval statistics (-Q) - (#193). +- The number of sent pings is only counted when the pings are received or have + timed out, ensuring that the loss ratio will be always correct. This makes it + possible, for example, to use loop mode (-l) with interval statistics (-Q) + and a timeout larger than period, without having the issue that initially + some pings would be reported as missing (#193) + - Improved precision of measurements from 10us to 1us (#136, thanks @tycho) diff --git a/ci/test-08-options-n-q.pl b/ci/test-08-options-n-q.pl index 07d5442..51720bf 100755 --- a/ci/test-08-options-n-q.pl +++ b/ci/test-08-options-n-q.pl @@ -31,7 +31,12 @@ $cmd->stderr_is_eq("fping: use either one of -d or -n\n"); { my $cmd = Test::Command->new(cmd => "fping -t100 -p 100 -o -c 5 8.8.8.7"); $cmd->exit_is_num(1); -$cmd->stdout_is_eq(""); +$cmd->stdout_is_eq("8.8.8.7 : [0], timed out (NaN avg, 100% loss) +8.8.8.7 : [1], timed out (NaN avg, 100% loss) +8.8.8.7 : [2], timed out (NaN avg, 100% loss) +8.8.8.7 : [3], timed out (NaN avg, 100% loss) +8.8.8.7 : [4], timed out (NaN avg, 100% loss) +"); $cmd->stderr_like(qr{^\s*8\.8\.8\.7 : xmt/rcv/%loss = 5/0/100%, outage\(ms\) = 50\d\s*$}); } diff --git a/src/fping.c b/src/fping.c index 91f3f3a..cab4af1 100644 --- a/src/fping.c +++ b/src/fping.c @@ -1262,6 +1262,29 @@ void main_loop() stats_add(h, event->ping_index, 0, -1); + if (per_recv_flag) { + if (timestamp_flag) { + printf("[%10.5f] ", (double)current_time_ns / 1e9); + } + printf("%-*s : [%d], timed out", + max_hostname_len, h->host, event->ping_index); + if(h->num_recv > 0) { + printf(" (%s avg, ", sprint_tm(h->total_time / h->num_recv)); + } + else { + printf(" (NaN avg, "); + } + if (h->num_recv <= h->num_sent) { + printf("%d%% loss)", + ((h->num_sent - h->num_recv) * 100) / h->num_sent); + } + else { + printf("%d%% return)", + (h->num_recv_total * 100) / h->num_sent); + } + printf("\n"); + } + /* do we need to send a retry? */ if (!loop_flag && !count_flag) { if (h->num_sent < retry + 1) { @@ -2348,7 +2371,7 @@ int wait_for_reply(int64_t wait_time) /* print received ping (unless --quiet) */ if (per_recv_flag) { if (timestamp_flag) { - printf("[%10.5f] ", (double)(recv_time / 1000000)/1000); + printf("[%10.5f] ", (double)recv_time / 1e9); } avg = h->total_time / h->num_recv; printf("%-*s : [%d], %d bytes, %s ms",