[BACK]Return to nfsstat.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / nfsstat

Diff for /src/usr.bin/nfsstat/nfsstat.c between version 1.8 and 1.9

version 1.8, 2000/04/18 15:24:26 version 1.9, 2000/04/18 20:17:54
Line 59 
Line 59 
 #include <nfs/nfsproto.h>  #include <nfs/nfsproto.h>
 #include <nfs/nfs.h>  #include <nfs/nfs.h>
 #include <signal.h>  #include <signal.h>
   #include <fcntl.h>
   #include <ctype.h>
 #include <errno.h>  #include <errno.h>
   #include <kvm.h>
   #include <nlist.h>
 #include <unistd.h>  #include <unistd.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
   #include <limits.h>
   #include <paths.h>
 #include <err.h>  #include <err.h>
   
 #define SHOW_SERVER 0x01  #define SHOW_SERVER 0x01
 #define SHOW_CLIENT 0x02  #define SHOW_CLIENT 0x02
 #define SHOW_ALL (SHOW_SERVER | SHOW_CLIENT)  #define SHOW_ALL (SHOW_SERVER | SHOW_CLIENT)
   
   struct nlist nl[] = {
   #define N_NFSSTAT       0
           { "_nfsstats" },
           { "" },
   };
   kvm_t *kd;
 u_char  signalled;                      /* set if alarm goes off "early" */  u_char  signalled;                      /* set if alarm goes off "early" */
 int nfs_id;  int nfs_id;
   
 void getnfsstats __P((struct nfsstats *));  void getnfsstats __P((struct nfsstats *));
 static __inline void printhdr __P((void));  void printhdr __P((void));
 static __inline void intpr __P((u_int));  void intpr __P((u_int));
 static __inline void sidewaysintpr __P((u_int, u_int));  void sidewaysintpr __P((u_int, u_int));
 static __inline void usage __P((void));  void usage __P((void));
   
 int  int
 main(argc, argv)  main(argc, argv)
Line 89 
Line 101 
         char *p;          char *p;
         u_int interval;          u_int interval;
         u_int display = SHOW_ALL;          u_int display = SHOW_ALL;
           char *memf, *nlistf;
         int ch;          int ch;
   
         interval = 0;          interval = 0;
           memf = nlistf = NULL;
         while ((ch = getopt(argc, argv, "M:N:w:sc")) != -1)          while ((ch = getopt(argc, argv, "M:N:w:sc")) != -1)
                 switch(ch) {                  switch(ch) {
                 case 'M':                  case 'M':
                           memf = optarg;
                           break;
                 case 'N':                  case 'N':
                         /* compat */                          nlistf = optarg;
                         break;                          break;
                 case 'w':                  case 'w':
                         interval = (u_int)strtol(optarg, &p, 0);                          interval = (u_int)strtol(optarg, &p, 0);
Line 116 
Line 132 
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
         {  #define BACKWARD_COMPATIBILITY
   #ifdef  BACKWARD_COMPATIBILITY
           if (*argv) {
                   interval = atoi(*argv);
                   if (*++argv) {
                           nlistf = *argv;
                           if (*++argv)
                                   memf = *argv;
                   }
           }
   #endif
           if (nlistf || memf) {
                   char errbuf[_POSIX2_LINE_MAX];
   
                   if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, errbuf)) == 0)
                           errx(1, "nfsstat: %s", errbuf);
                   if (kvm_nlist(kd, nl) != 0)
                           errx(1, "kvm_nlist: can't get names");
           } else {
                 int mib[3];                  int mib[3];
                 size_t len;                  size_t len;
   
Line 147 
Line 181 
                         errx(1, "cannot find nfs filesystem id");                          errx(1, "cannot find nfs filesystem id");
         }          }
   
 #define BACKWARD_COMPATIBILITY  
 #ifdef  BACKWARD_COMPATIBILITY  
         if (*argv)  
                 interval = atoi(*argv);  
 #endif  
         if (interval)          if (interval)
                 sidewaysintpr(interval, display);                  sidewaysintpr(interval, display);
         else          else
Line 164 
Line 193 
 getnfsstats(p)  getnfsstats(p)
         struct nfsstats *p;          struct nfsstats *p;
 {  {
         int mib[3];          if (kd) {
         size_t len = sizeof(*p);                  if (kvm_read(kd, nl[N_NFSSTAT].n_value, p, sizeof(*p)) != sizeof(*p))
                           errx(1, "kvm_read failed");
           } else {
                   int mib[3];
                   size_t len = sizeof(*p);
   
         mib[0] = CTL_VFS;                  mib[0] = CTL_VFS;
         mib[1] = nfs_id; /* 2 */                  mib[1] = nfs_id; /* 2 */
         mib[2] = NFS_NFSSTATS;                  mib[2] = NFS_NFSSTATS;
   
         if (sysctl(mib, 3, p, &len, NULL, 0))                  if (sysctl(mib, 3, p, &len, NULL, 0))
                 err(1, "sysctl");                          err(1, "sysctl");
           }
 }  }
   
 /*  /*
  * Print a description of the nfs stats.   * Print a description of the nfs stats.
  */   */
 static __inline void  void
 intpr(display)  intpr(display)
         u_int display;          u_int display;
 {  {
Line 331 
Line 365 
  * collected over that interval.  Assumes that interval is non-zero.   * collected over that interval.  Assumes that interval is non-zero.
  * First line printed at top of screen is always cumulative.   * First line printed at top of screen is always cumulative.
  */   */
 static __inline void  void
 sidewaysintpr(interval, display)  sidewaysintpr(interval, display)
         u_int interval;          u_int interval;
         u_int display;          u_int display;
Line 387 
Line 421 
         /*NOTREACHED*/          /*NOTREACHED*/
 }  }
   
 static __inline void  void
 printhdr()  printhdr()
 {  {
         printf("        %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s\n",          printf("        %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s %8.8s\n",
Line 406 
Line 440 
         signalled = 1;          signalled = 1;
 }  }
   
 static __inline void  void
 usage()  usage()
 {  {
         extern char *__progname;          extern char *__progname;
         fprintf(stderr, "usage: %s [-s] [-c] [-w interval]\n", __progname);          fprintf(stderr,
               "usage: %s [-M core] [-N system] [-s] [-c] [-w interval]\n",
               __progname);
         exit(1);          exit(1);
 }  }

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9