From: David Schweikert Date: Sat, 11 Jul 2020 13:59:19 +0000 (+0200) Subject: Merge pull request #136 from tycho/high-resolution-clock-sources X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=721af135dbadc4fdfb5d5d4f55082fa4a25cd304;p=fping.git Merge pull request #136 from tycho/high-resolution-clock-sources Move to 1us resolution for latency measurements --- 721af135dbadc4fdfb5d5d4f55082fa4a25cd304 diff --cc src/fping.c index 7d6aa16,518a878..3522123 --- a/src/fping.c +++ b/src/fping.c @@@ -331,9 -348,8 +350,9 @@@ void print_per_system_splits(void) void print_netdata(void); void print_global_stats(void); void main_loop(); +void sigstatus(); void finish(); - char* sprint_tm(int t); + const char* sprint_tm(int64_t t); void ev_enqueue(HOST_ENTRY* h); HOST_ENTRY* ev_dequeue(); void ev_remove(HOST_ENTRY* h); @@@ -1030,10 -1063,8 +1066,10 @@@ int main(int argc, char** argv #endif signal(SIGINT, finish); + signal(SIGQUIT, sigstatus); + setlinebuf(stdout); - gettimeofday(&start_time, NULL); + clock_gettime(CLOCKID, &start_time); current_time = start_time; if (report_interval) { @@@ -1305,15 -1332,10 +1337,15 @@@ void main_loop( ; /* process other replies in the queue */ } - gettimeofday(¤t_time, NULL); + clock_gettime(CLOCKID, ¤t_time); + if (status_snapshot) { + status_snapshot = 0; + print_per_system_splits(); + } + /* Print report */ - if (report_interval && (loop_flag || count_flag) && (timeval_diff(¤t_time, &next_report_time) >= 0)) { + if (report_interval && (loop_flag || count_flag) && (timespec_diff_10us(¤t_time, &next_report_time) >= 0)) { if (netdata_flag) print_netdata(); else @@@ -1429,8 -1431,10 +1461,8 @@@ void print_per_system_stats(void { int i, j, avg, outage_ms; HOST_ENTRY* h; - int resp; + int64_t resp; - fflush(stdout); - if (verbose_flag || per_recv_flag) fprintf(stderr, "\n"); @@@ -2259,11 -2248,32 +2292,11 @@@ int wait_for_reply(long wait_time } } - if (h->num_recv == 1) { - num_alive++; - if (verbose_flag || alive_flag) { - printf("%s", h->host); - - if (verbose_flag) - printf(" is alive"); - - if (elapsed_flag) - printf(" (%s ms)", sprint_tm(this_reply)); - - if (addr_cmp((struct sockaddr*)&response_addr, (struct sockaddr*)&h->saddr)) { - char buf[INET6_ADDRSTRLEN]; - getnameinfo((struct sockaddr*)&response_addr, sizeof(response_addr), buf, INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST); - fprintf(stderr, " [<- %s]", buf); - } - - printf("\n"); - } - } - if (per_recv_flag) { if (timestamp_flag) { - printf("[%lu.%06lu] ", + printf("[%lu.%09lu] ", (unsigned long)recv_time.tv_sec, - (unsigned long)recv_time.tv_usec); + (unsigned long)recv_time.tv_nsec); } avg = h->total_time / h->num_recv; printf("%s%s : [%d], %d bytes, %s ms",