|
|
1.1 ! root 1: /* $Header: RCS/loadst.v Revision 1.1 83/02/09 17:16:53 fen Rel$ */ ! 2: /* ! 3: * loadst -- print current time and load statistics. ! 4: * -- James Gosling @ CMU, May 1981 ! 5: * loadst [ -n ] [ interval ] ! 6: * 07/29/81 jag -- also print info on presence of mail. ! 7: * 05/05/82 jag -- add disk drive utilization statistics. ! 8: */ ! 9: ! 10: #define NO_SHORTNAMES /* Do not want config to try to include remap.h */ ! 11: #include "../src/config.h" ! 12: #include <stdio.h> ! 13: #include <pwd.h> ! 14: ! 15: /* Define two macros KERNEL_FILE (file to find kernel symtab in) ! 16: and LDAV_SYMBOL (symbol name to look for), based on system type. ! 17: Also define NLIST_STRUCT if the type `nlist' is a structure we ! 18: can get from nlist.h; otherwise must use a.out.h and initialize ! 19: with strcpy. Note that config.h may define NLIST_STRUCT ! 20: for more modrern USG systems. */ ! 21: ! 22: #ifdef USG ! 23: #ifdef HPUX ! 24: #define LDAV_SYMBOL "_avenrun" ! 25: #define KERNEL_FILE "/hp-ux" ! 26: #define NLIST_STRUCT ! 27: #else /* not HPUX */ ! 28: #define LDAV_SYMBOL "avenrun" ! 29: #define KERNEL_FILE "/unix" ! 30: #endif /* not HPUX */ ! 31: #else /* not USG */ ! 32: #define LDAV_SYMBOL "_avenrun" ! 33: #define NLIST_STRUCT ! 34: #ifndef KERNEL_FILE ! 35: #define KERNEL_FILE "/vmunix" ! 36: #endif /* no KERNEL_FILE yet */ ! 37: #endif /* not USG */ ! 38: ! 39: ! 40: #ifdef LOAD_AVE_TYPE ! 41: #ifndef NLIST_STRUCT ! 42: #include <a.out.h> ! 43: #else /* NLIST_STRUCT */ ! 44: #include <nlist.h> ! 45: #endif /* NLIST_STRUCT */ ! 46: #endif /* LOAD_AVE_TYPE */ ! 47: ! 48: #ifdef USG ! 49: #include <time.h> ! 50: #include <sys/types.h> ! 51: #else /* not USG */ ! 52: #include <sys/time.h> ! 53: #include <sys/param.h> ! 54: #ifdef LOAD_AVE_TYPE ! 55: #include <sys/dk.h> ! 56: #endif /* LOAD_AVE_TYPE */ ! 57: #endif /* USG */ ! 58: ! 59: #include <sys/stat.h> ! 60: ! 61: /* We don't want Emacs's macro definitions for these USG primitives. */ ! 62: ! 63: #undef open ! 64: #undef read ! 65: ! 66: struct tm *localtime (); ! 67: ! 68: #ifdef LOAD_AVE_TYPE ! 69: #ifndef NLIST_STRUCT ! 70: struct nlist nl[2]; ! 71: #else /* NLIST_STRUCT */ ! 72: struct nlist nl[] = ! 73: { ! 74: { LDAV_SYMBOL }, ! 75: #if defined (CPUSTATES) && defined (DK_NDRIVE) ! 76: #define X_CPTIME 1 ! 77: { "_cp_time" }, ! 78: #define X_DKXFER 2 ! 79: { "_dk_xfer" }, ! 80: #endif /* have CPUSTATES and DK_NDRIVE */ ! 81: { 0 }, ! 82: }; ! 83: #endif /* NLIST_STRUCT */ ! 84: #endif /* LOAD_AVE_TYPE */ ! 85: ! 86: #if defined (CPUSTATES) && defined (DK_NDRIVE) ! 87: ! 88: struct ! 89: { ! 90: long time[CPUSTATES]; ! 91: long xfer[DK_NDRIVE]; ! 92: } s, s1; ! 93: ! 94: double etime; ! 95: ! 96: #endif /* have CPUSTATES and DK_NDRIVE */ ! 97: ! 98: int nflag; /* -n flag -- no newline */ ! 99: int uflag; /* -u flag -- user current user ID rather ! 100: than login user ID */ ! 101: int repetition; /* repetition interval */ ! 102: ! 103: ! 104: main (argc, argv) ! 105: char **argv; ! 106: { ! 107: register int kmem, i; ! 108: char *mail; ! 109: char *user_name; ! 110: struct stat st; ! 111: ! 112: kmem = open ("/dev/kmem", 0); ! 113: ! 114: #ifdef LOAD_AVE_TYPE ! 115: #ifndef NLIST_STRUCT ! 116: strcpy (nl[0].n_name, LDAV_SYMBOL); ! 117: strcpy (nl[1].n_name, ""); ! 118: #endif /* not NLIST_STRUCT */ ! 119: ! 120: nlist (KERNEL_FILE, nl); ! 121: #endif /* LOAD_AVE_TYPE */ ! 122: ! 123: while (--argc > 0) ! 124: { ! 125: argv++; ! 126: if (strcmp (*argv, "-n") == 0) ! 127: nflag++; ! 128: else if (strcmp (*argv, "-u") == 0) ! 129: uflag++; ! 130: else ! 131: if ((repetition = atoi (*argv)) <= 0) ! 132: { ! 133: fprintf (stderr, "Bogus argument: %s\n", *argv); ! 134: exit (1); ! 135: } ! 136: } ! 137: ! 138: user_name = uflag ? ((struct passwd *) getpwuid (getuid ())) -> pw_name ! 139: #ifdef USG ! 140: : (char *) getenv ("LOGNAME"); ! 141: #else ! 142: : (char *) getenv ("USER"); ! 143: #endif ! 144: ! 145: mail = (char *) malloc (strlen (user_name) + 30); ! 146: ! 147: #ifdef USG ! 148: sprintf (mail, "/usr/mail/%s", user_name); ! 149: #else /* not USG */ ! 150: sprintf (mail, "/usr/spool/mail/%s", user_name); ! 151: #endif /* not USG */ ! 152: ! 153: if (stat (mail, &st) >= 0 ! 154: && (st.st_mode & S_IFMT) == S_IFDIR) ! 155: { ! 156: strcat (mail, "/"); ! 157: strcat (mail, user_name); ! 158: } ! 159: ! 160: while (1) ! 161: { ! 162: register struct tm *nowt; ! 163: long now; ! 164: ! 165: time (&now); ! 166: nowt = localtime (&now); ! 167: ! 168: printf ("%d:%02d%s ", ! 169: ((nowt->tm_hour + 11) % 12) + 1, ! 170: nowt->tm_min, ! 171: nowt->tm_hour >= 12 ? "pm" : "am"); ! 172: ! 173: #ifdef LOAD_AVE_TYPE ! 174: if (kmem >= 0) ! 175: { ! 176: LOAD_AVE_TYPE avenrun[3]; ! 177: avenrun[0] = 0; ! 178: lseek (kmem, (long) nl[0].n_value, 0); ! 179: read (kmem, avenrun, sizeof (avenrun)); ! 180: printf ("%.2f", LOAD_AVE_CVT (avenrun[0]) / 100.0); ! 181: } ! 182: #endif /* LOAD_AVE_TYPE */ ! 183: ! 184: printf ("%s", (stat (mail, &st) >= 0 && st.st_size) ? " Mail" : ""); ! 185: ! 186: #if defined (CPUSTATES) && defined (DK_NDRIVE) ! 187: if (kmem >= 0) ! 188: { ! 189: lseek (kmem, (long) nl[X_CPTIME].n_value, 0); ! 190: read (kmem, s.time, sizeof s.time); ! 191: lseek (kmem, (long) nl[X_DKXFER].n_value, 0); ! 192: read (kmem, s.xfer, sizeof s.xfer); ! 193: etime = 0; ! 194: for (i = 0; i < DK_NDRIVE; i++) ! 195: { ! 196: register t = s.xfer[i]; ! 197: s.xfer[i] -= s1.xfer[i]; ! 198: s1.xfer[i] = t; ! 199: } ! 200: for (i = 0; i < CPUSTATES; i++) ! 201: { ! 202: register t = s.time[i]; ! 203: s.time[i] -= s1.time[i]; ! 204: s1.time[i] = t; ! 205: etime += s.time[i]; ! 206: } ! 207: if (etime == 0.) ! 208: etime = 1.; ! 209: etime /= 60.; ! 210: ! 211: { register max = s.xfer[0]; ! 212: for (i = 1; i < DK_NDRIVE; i++) ! 213: if (s.xfer[i] > max) ! 214: max = s.xfer[i]; ! 215: printf ("[%d]", (int) (max / etime + 0.5)); ! 216: } ! 217: } ! 218: #endif /* have CPUSTATES and DK_NDRIVE */ ! 219: if (!nflag) ! 220: putchar ('\n'); ! 221: fflush (stdout); ! 222: if (repetition <= 0) ! 223: break; ! 224: sleep (repetition); ! 225: } ! 226: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.