Whamcloud - gitweb
Stop routerstat from resetting the router's statistics after every read, which
authormorrone <morrone>
Sat, 12 Jul 2003 00:40:54 +0000 (00:40 +0000)
committermorrone <morrone>
Sat, 12 Jul 2003 00:40:54 +0000 (00:40 +0000)
will allow multiple users to run routerstat at the same time.  Since the
stats aren't reset, it also needs to handle rollover.

lnet/utils/routerstat.c
lustre/portals/utils/routerstat.c

index 37da12c..99bc59b 100644 (file)
@@ -21,12 +21,15 @@ do_stat (int fd)
 {
    static char  buffer[1024];
    static double last = 0.0;
 {
    static char  buffer[1024];
    static double last = 0.0;
+   static unsigned long long old_bytes;
+   static unsigned long      old_packets;
+   static unsigned long      old_errors;
    double now;
    double t;
    double now;
    double t;
-   long long bytes;
-   long      packets;
-   long      errors;
-   long      depth;
+   unsigned long long new_bytes, bytes;
+   unsigned long      new_packets, packets;
+   unsigned long      new_errors, errors;
+   unsigned long      depth;
    int    n;
    
    lseek (fd, 0, SEEK_SET);
    int    n;
    
    lseek (fd, 0, SEEK_SET);
@@ -39,7 +42,8 @@ do_stat (int fd)
    }    
    buffer[n] = 0;
    
    }    
    buffer[n] = 0;
    
-   n = sscanf (buffer, "%Ld %ld %ld %ld", &bytes, &packets, &errors, &depth);
+   n = sscanf (buffer, "%Lu %lu %lu %lu",
+              &new_bytes, &new_packets, &new_errors, &depth);
    
    if (n < 3)
    {
    
    if (n < 3)
    {
@@ -48,27 +52,44 @@ do_stat (int fd)
    }
    
    if (last == 0.0)
    }
    
    if (last == 0.0)
-      printf ("%Ld bytes, %ld packets (sz %Ld) %ld errors", 
-             bytes, packets, (long long)((packets == 0) ? 0LL : bytes/packets), errors);
+      printf ("%llu bytes, %lu packets (sz %lld), %lu errors", 
+             new_bytes, new_packets,
+             (long long)((new_packets == 0) ? 0LL : new_bytes/new_packets),
+             new_errors);
    else
    {
       t = now - last;
 
    else
    {
       t = now - last;
 
-      printf ("%9Ld (%7.2fMb/s), %7ld packets (sz %5Ld, %5ld/s) %ld errors (%ld/s)", 
+      if (new_bytes < old_bytes)
+         bytes = -1ULL - old_bytes + new_bytes + 1;
+      else
+         bytes = new_bytes - old_bytes;
+      if (new_packets < old_packets)
+         packets = -1UL - old_packets + new_packets + 1;
+      else
+         packets = new_packets - old_packets;
+      if (new_errors < old_errors)
+         errors = -1UL - old_errors + new_errors + 1;
+      else
+         errors = new_errors - old_errors;
+      
+      printf ("%9llu bytes (%7.2fMb/s), %7lu packets (sz %5lld, %5ld/s), %lu errors (%ld/s)", 
              bytes, ((double)bytes)/((1<<20) * t),
              packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t),
              errors, (long)(errors/t));
    }
              bytes, ((double)bytes)/((1<<20) * t),
              packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t),
              errors, (long)(errors/t));
    }
+   old_bytes = new_bytes;
+   old_packets = new_packets;
+   old_errors = new_errors;
 
    if (n == 4)
 
    if (n == 4)
-      printf (" (%ld)\n", depth);
+      printf (", depth (%ld)\n", depth);
    else
       printf ("\n");
 
    fflush (stdout);
    
    lseek (fd, 0, SEEK_SET);
    else
       printf ("\n");
 
    fflush (stdout);
    
    lseek (fd, 0, SEEK_SET);
-   write (fd, "\n", 1);
    last = timenow();
 }
 
    last = timenow();
 }
 
@@ -80,7 +101,7 @@ int main (int argc, char **argv)
    if (argc > 1)
       interval = atoi (argv[1]);
 
    if (argc > 1)
       interval = atoi (argv[1]);
 
-   fd = open ("/proc/sys/portals/router", O_RDWR);
+   fd = open ("/proc/sys/portals/router", O_RDONLY);
    if (fd < 0)
    {
       fprintf (stderr, "Can't open stat: %s\n", strerror (errno));
    if (fd < 0)
    {
       fprintf (stderr, "Can't open stat: %s\n", strerror (errno));
index 37da12c..99bc59b 100644 (file)
@@ -21,12 +21,15 @@ do_stat (int fd)
 {
    static char  buffer[1024];
    static double last = 0.0;
 {
    static char  buffer[1024];
    static double last = 0.0;
+   static unsigned long long old_bytes;
+   static unsigned long      old_packets;
+   static unsigned long      old_errors;
    double now;
    double t;
    double now;
    double t;
-   long long bytes;
-   long      packets;
-   long      errors;
-   long      depth;
+   unsigned long long new_bytes, bytes;
+   unsigned long      new_packets, packets;
+   unsigned long      new_errors, errors;
+   unsigned long      depth;
    int    n;
    
    lseek (fd, 0, SEEK_SET);
    int    n;
    
    lseek (fd, 0, SEEK_SET);
@@ -39,7 +42,8 @@ do_stat (int fd)
    }    
    buffer[n] = 0;
    
    }    
    buffer[n] = 0;
    
-   n = sscanf (buffer, "%Ld %ld %ld %ld", &bytes, &packets, &errors, &depth);
+   n = sscanf (buffer, "%Lu %lu %lu %lu",
+              &new_bytes, &new_packets, &new_errors, &depth);
    
    if (n < 3)
    {
    
    if (n < 3)
    {
@@ -48,27 +52,44 @@ do_stat (int fd)
    }
    
    if (last == 0.0)
    }
    
    if (last == 0.0)
-      printf ("%Ld bytes, %ld packets (sz %Ld) %ld errors", 
-             bytes, packets, (long long)((packets == 0) ? 0LL : bytes/packets), errors);
+      printf ("%llu bytes, %lu packets (sz %lld), %lu errors", 
+             new_bytes, new_packets,
+             (long long)((new_packets == 0) ? 0LL : new_bytes/new_packets),
+             new_errors);
    else
    {
       t = now - last;
 
    else
    {
       t = now - last;
 
-      printf ("%9Ld (%7.2fMb/s), %7ld packets (sz %5Ld, %5ld/s) %ld errors (%ld/s)", 
+      if (new_bytes < old_bytes)
+         bytes = -1ULL - old_bytes + new_bytes + 1;
+      else
+         bytes = new_bytes - old_bytes;
+      if (new_packets < old_packets)
+         packets = -1UL - old_packets + new_packets + 1;
+      else
+         packets = new_packets - old_packets;
+      if (new_errors < old_errors)
+         errors = -1UL - old_errors + new_errors + 1;
+      else
+         errors = new_errors - old_errors;
+      
+      printf ("%9llu bytes (%7.2fMb/s), %7lu packets (sz %5lld, %5ld/s), %lu errors (%ld/s)", 
              bytes, ((double)bytes)/((1<<20) * t),
              packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t),
              errors, (long)(errors/t));
    }
              bytes, ((double)bytes)/((1<<20) * t),
              packets, (long long)((packets == 0) ? 0LL : bytes/packets), (long)(packets/t),
              errors, (long)(errors/t));
    }
+   old_bytes = new_bytes;
+   old_packets = new_packets;
+   old_errors = new_errors;
 
    if (n == 4)
 
    if (n == 4)
-      printf (" (%ld)\n", depth);
+      printf (", depth (%ld)\n", depth);
    else
       printf ("\n");
 
    fflush (stdout);
    
    lseek (fd, 0, SEEK_SET);
    else
       printf ("\n");
 
    fflush (stdout);
    
    lseek (fd, 0, SEEK_SET);
-   write (fd, "\n", 1);
    last = timenow();
 }
 
    last = timenow();
 }
 
@@ -80,7 +101,7 @@ int main (int argc, char **argv)
    if (argc > 1)
       interval = atoi (argv[1]);
 
    if (argc > 1)
       interval = atoi (argv[1]);
 
-   fd = open ("/proc/sys/portals/router", O_RDWR);
+   fd = open ("/proc/sys/portals/router", O_RDONLY);
    if (fd < 0)
    {
       fprintf (stderr, "Can't open stat: %s\n", strerror (errno));
    if (fd < 0)
    {
       fprintf (stderr, "Can't open stat: %s\n", strerror (errno));