print lost pings in loop and count mode, fixes #175

pull/196/head
David Schweikert 4 years ago
parent 130b1d6f9b
commit 43f6e3498e

@ -1,13 +1,30 @@
fping 5.0 (unreleased) 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 ## New features
- Refactored event loop, now allowing for period (-p) to be smaller than - The number of sent pings is only counted when the pings are received or have
timeout (-t). The number of sent pings is now only incremented when the timed out, ensuring that the loss ratio will be always correct. This makes it
response is received or when the timeout happens, so that the loss statistic possible, for example, to use loop mode (-l) with interval statistics (-Q)
is always correct (especially important when using interval statistics (-Q) and a timeout larger than period, without having the issue that initially
(#193). some pings would be reported as missing (#193)
- Improved precision of measurements from 10us to 1us (#136, thanks @tycho) - Improved precision of measurements from 10us to 1us (#136, thanks @tycho)

@ -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"); my $cmd = Test::Command->new(cmd => "fping -t100 -p 100 -o -c 5 8.8.8.7");
$cmd->exit_is_num(1); $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*$}); $cmd->stderr_like(qr{^\s*8\.8\.8\.7 : xmt/rcv/%loss = 5/0/100%, outage\(ms\) = 50\d\s*$});
} }

@ -1262,6 +1262,29 @@ void main_loop()
stats_add(h, event->ping_index, 0, -1); 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? */ /* do we need to send a retry? */
if (!loop_flag && !count_flag) { if (!loop_flag && !count_flag) {
if (h->num_sent < retry + 1) { if (h->num_sent < retry + 1) {
@ -2348,7 +2371,7 @@ int wait_for_reply(int64_t wait_time)
/* print received ping (unless --quiet) */ /* print received ping (unless --quiet) */
if (per_recv_flag) { if (per_recv_flag) {
if (timestamp_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; avg = h->total_time / h->num_recv;
printf("%-*s : [%d], %d bytes, %s ms", printf("%-*s : [%d], %d bytes, %s ms",

Loading…
Cancel
Save