gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] Print offset in ntpshmmon?


From: Miroslav Lichvar
Subject: [gpsd-dev] Print offset in ntpshmmon?
Date: Tue, 21 Apr 2015 13:23:22 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

When debugging problems with NTP SHM segments, I use a very simple
program to print the SHM segment. Now that gpsd includes ntpshmmon,
which has a nice feature that it finds all used segments
automatically, I thought I could start using that instead.

For me, it's quite useful to see the offset (the difference between
the clock and receive timestamps). Would there be any interest in
adding that to ntpshmmon?

It seems there is no more room for additional entries to fit in 80
columns. Would it be ok to replace the clock timestamp?

--- a/ntpshmmon.c
+++ b/ntpshmmon.c
@@ -20,6 +20,7 @@
 /* int is too small, avoid floats  */
 /* WARNING!  this will overflow if x and y differ by more than a few seconds */
 #define timespec_diff_ns(x, y) 
(long)(((x).tv_sec-(y).tv_sec)*1000000000+(x).tv_nsec-(y).tv_nsec)
+#define timespec_diff(x, y)    
(((x).tv_sec-(y).tv_sec)+1e-9*((x).tv_nsec-(y).tv_nsec))

 static struct shmTime *segments[NTPSEGMENTS + 1];
 static struct timespec tick[NTPSEGMENTS + 1];
@@ -80,7 +81,7 @@ int main(int argc, char **argv)
     }

     (void)printf("ntpshmmon version 1\n");
-    (void)printf("       Name   Seen@                Clock                Real 
              L Prec\n");
+    (void)printf("       Name   Seen@                Clock                
Offset             L Prec\n");

     do {
        struct shm_stat_t       shm_stat;
@@ -93,11 +94,11 @@ int main(int argc, char **argv)
            {
            case OK:
                if (timespec_diff_ns(shm_stat.tvc, tick[i]) >= cycle * 
1000000000) {
-                   printf("sample %s %ld.%09ld %ld.%09ld %ld.%09ld %d %3d\n",
+                   printf("sample %s %ld.%09ld %ld.%09ld %+020.9f %d %3d\n",
                           ntp_name(i),
                           (long)shm_stat.tvc.tv_sec, shm_stat.tvc.tv_nsec,
                           (long)shm_stat.tvr.tv_sec, shm_stat.tvr.tv_nsec,
-                          (long)shm_stat.tvt.tv_sec, shm_stat.tvt.tv_nsec,
+                          timespec_diff(shm_stat.tvt, shm_stat.tvr),
                           shm_stat.leap, shm_stat.precision);
                    tick[i] = shm_stat.tvc;
                    --nsamples;


-- 
Miroslav Lichvar



reply via email to

[Prev in Thread] Current Thread [Next in Thread]