Skip to content

Commit

Permalink
print lost pings in loop and count mode, fixes #175
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikert committed Jul 30, 2020
1 parent 130b1d6 commit 43f6e34
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
27 changes: 22 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
7 changes: 6 additions & 1 deletion ci/test-08-options-n-q.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
{
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*$});
}

Expand Down
25 changes: 24 additions & 1 deletion src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 43f6e34

Please sign in to comment.