#include <semaphore.h>
bool opt_verbose = false;
+bool opt_quiet = false;
#define HIST_MAX_US 1000000
#define HIST_RES_US 10
static struct option long_opts[] = {
- { "period", 1, 0, 'p' },
- { "budget", 1, 0, 'b' },
- { "source", 1, 0, 's' },
- { "dest", 1, 0, 'd' },
- { "async", 0, 0, 'a' },
- { "number", 0, 0, 'n' },
- { "count", 0, 0, 'c' },
- { "verbose",0, 0, 'v' },
+ { "period", required_argument, 0, 'p' },
+ { "budget", required_argument, 0, 'b' },
+ { "source", required_argument, 0, 's' },
+ { "dest", required_argument, 0, 'd' },
+ { "async", no_argument, 0, 'a' },
+ { "number", required_argument, 0, 'n' },
+ { "count", required_argument, 0, 'c' },
+ { "verbose",no_argument, 0, 'v' },
+ { "quiet", no_argument, 0, 'q' },
{ 0, 0, 0, 0}
};
printf(" -a, --async Send packets asynchronously\n");
printf(" -n, --number Number of streams with the same parameters\n");
printf(" -c, --count Number of messages to send [infinity]\n");
+ printf(" -q, --quiet Print only final statistics\n");
printf(" -/, --stream New stream separator\n");
printf(" -v, --verbose Be more verbose\n");
}
int ret;
bool options_found = false;
- while ((opt = getopt_long(*argc, *argv, "/ab:c:p:s:d:n:v", long_opts, NULL)) != -1) {
+ while ((opt = getopt_long(*argc, *argv, "/ab:c:d:n:p:qs:v", long_opts, NULL)) != -1) {
options_found = true;
switch (opt) {
case 'a':
break;
case 'v':
opt_verbose = true;
+ break;
+ case 'q':
+ opt_quiet = true;
+ break;
case '/':
break;
default:
clock_gettime(CLOCK_MONOTONIC, &tsr);
tss = msg->ts;
if (msg->cnt != last_cnt+1) {
- printf("%3d: packet(s) lost!\n", rp->id);
+ if (!opt_quiet)
+ printf("%3d: packet(s) lost!\n", rp->id);
__sync_fetch_and_add(&stats.lost, msg->cnt - last_cnt+1);
} else {
hist_add(&hist, tsdiff2us(&tsr, &tss));
return NULL;
}
-void print_stat(bool full)
+void print_stat(bool final)
{
printf("Sent: %5d Received: %5d Lost: %5d Max: %6.3f ms",
stats.sent, stats.received, stats.lost, hist.max/1000.0);
- if (full) {
- printf(" Max: %6.3f ms 90%%: %6.3f ms",
+ if (final) {
+ printf(" Max: %6.3f ms 90%%: %6.3f ms\n",
hist_get_percentile(&hist, 100)/1000.0,
hist_get_percentile(&hist, 90)/1000.0);
}
- printf("\r");
+ else
+ printf("\r");
fflush(stdout);
}
}
} while(ret == 0);
- while (!exit_flag) {
+ while (!exit_flag && !opt_quiet) {
int v;
print_stat(false);
sem_getvalue(&finished, &v);
sem_wait(&finished);
print_stat(true);
- printf("\n");
return 0;
}