From e6ce5160d4de293e69e7d97ddc380ccbc59f16d5 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 6 Jun 2018 10:07:02 +0200 Subject: tools: Add quiet option to oping This adds a --quiet -Q option to oping so it will only print the statistics summary. Also fixes a division by 0 if duration is specified with interval 0. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/tools/oping/oping_client.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/tools/oping/oping_client.c') diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index e777d4cc..0f7695b5 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -102,23 +102,25 @@ void * reader(void * o) ms = ts_diff_us(&sent, &now) / 1000.0; - if (client.timestamp) { - struct timespec rtc; - clock_gettime(CLOCK_REALTIME, &rtc); - printf("[%zd.%06zu] ", - (ssize_t) rtc.tv_sec, - (size_t) rtc.tv_nsec / 1000); - } - if (id < exp_id) ++client.ooo; - printf("%d bytes from %s: seq=%d time=%.3f ms%s\n", - msg_len, - client.s_apn, - ntohl(msg->id), - ms, - id < exp_id ? " [out-of-order]" : ""); + if (!client.quiet) { + if (client.timestamp) { + struct timespec rtc; + clock_gettime(CLOCK_REALTIME, &rtc); + printf("[%zd.%06zu] ", + (ssize_t) rtc.tv_sec, + (size_t) rtc.tv_nsec / 1000); + } + + printf("%d bytes from %s: seq=%d time=%.3f ms%s\n", + msg_len, + client.s_apn, + ntohl(msg->id), + ms, + id < exp_id ? " [out-of-order]" : ""); + } if (ms < client.rtt_min) client.rtt_min = ms; @@ -157,8 +159,9 @@ void * writer(void * o) msg = (struct oping_msg *) buf; - printf("Pinging %s with %d bytes of data:\n\n", - client.s_apn, client.size); + if (!client.quiet) + printf("Pinging %s with %d bytes of data (%u packets):\n\n", + client.s_apn, client.size, client.count); pthread_cleanup_push((void (*) (void *)) free, buf); -- cgit v1.2.3