]> git.gsnw.org Git - fping.git/commitdiff
Merge pull request #136 from tycho/high-resolution-clock-sources
authorDavid Schweikert <david@schweikert.ch>
Sat, 11 Jul 2020 13:59:19 +0000 (15:59 +0200)
committerGitHub <noreply@github.com>
Sat, 11 Jul 2020 13:59:19 +0000 (15:59 +0200)
Move to 1us resolution for latency measurements

1  2 
configure.ac
src/fping.c

diff --cc configure.ac
Simple merge
diff --cc src/fping.c
index 7d6aa16660fe446964ffe315a0de719ff6a0f2e9,518a8781fc60399ae12da07a93a96028396d26eb..3522123e283326413a0276f7a33c2ca07e02e3c6
@@@ -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(&current_time, NULL);
+         clock_gettime(CLOCKID, &current_time);
  
 +        if (status_snapshot) {
 +            status_snapshot = 0;
 +            print_per_system_splits();
 +        }
 +
          /* Print report */
-         if (report_interval && (loop_flag || count_flag) && (timeval_diff(&current_time, &next_report_time) >= 0)) {
+         if (report_interval && (loop_flag || count_flag) && (timespec_diff_10us(&current_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",