Uptime (with load average) for AIX 2.2.1.
Marcel Mol
marcel at duteca
Sun Oct 14 05:59:31 AEST 1990
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# README 1124 bytes
# uptime.c 15069 bytes
# uptime.l 1354 bytes
# avenrun.c 17927 bytes
# delshm.c 442 bytes
# This archive created: Sat Oct 13 20:56:49 MET 1990
# By: Marcel J.E. Mol
export PATH
echo shar: extracting README
if test -f 'README'
then
echo shar: over-writing existing file "'README'"
fi
sed -e 's/^-//' << \_E_O_F_ > README
-Uptime for AIX 2.2.1
-
-The avenrun and uptime program are known to work on AIX 2.2.1.
-They might work on previous AIX versions and maybe even under AIX 3.
-To make it work, first compile the avenrun program (see the src for
-more help), and start it up every time the systems boots (put it
-in one of your /etc/rc files).
-The compile the uptime program and store it in some public directory.
-
-The avenrun program collects the vital data and saves it in a piece
-of shared memory. The uptime program then reads this information and
-performs the calculations.
-
-If for some reason the avenrun programs stops, or is killed, it might
-be possible that you get a shared memory error message when starting
-it up again (manually). If this happens, run the delshm program to
-destroy the shared memory segment, and then restart avenrun. Things
-should be ok then.
-
-If you don't like the shared memory key, feel free to change it. But
-remember to change it in all three programs (uptime avenrun and delshm).
-
-If you're having problems with this package, or suggestions or bugs or
-improvements or whatever, don't hesitate to give me a ring.
_E_O_F_
if test 1124 -ne `wc -c < README `; then
echo shar: "'README'" unpacked with wrong size!
fi
echo shar: extracting uptime.c
if test -f 'uptime.c'
then
echo shar: over-writing existing file "'uptime.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > uptime.c
-/* @(#) uptime.c ver 3.2 22/06/90 */
-/*************************************************************************
- ** **
- ** Name : uptime **
- ** Author : Marcel J.E. Mol **
- ** Date : 23/03/88 (first release) **
- ** Version : 3.20 **
- ** Files : uptime.c Main source file **
- ** **
- ** ------------------------- Revision List ------------------------- **
- ** Ver Date Name Remarks **
- ** 3.20 22/06/90 Marcel Mol Change output layout **
- ** Added flags to specify **
- ** wanted output. Default **
- ** resembles BSD uptime **
- ** 3.10 12/06/90 Marcel Mol Show last 10-sec interval **
- ** 3.00 08/06/90 Marcel Mol Show page and I/O rates **
- ** 2.00 30/10/88 Marcel Mol Added cpu busy code **
- ** 1.10 03/05/88 Marcel Mol Use shared memory segments **
- ** to work with avenrun **
- ** 0.10 23/03/88 Marcel Mol First release **
- ** ================================================================= **
- ** **
- ** Install as follows: cc uptime.c -sOo uptime **
- ** mv uptime /usr/local/bin/uptime **
- ** **
- ** Usage: uptime [-<options>] **
- ** **
- ** The avenrun program will periodically update a shared memory**
- ** segment with performance data averaged over the last **
- ** minute, 5 minutes, 15 minutes and last 10 seconds. **
- ** Uptime uses these numbers to calculate load figures. **
- ** **
- ************************************************************************/
-
- /************************************************************************
- ** **
- ** NAME **
- ** uptime -- Show system information and performance figures **
- ** **
- ** **
- ** SYNOPSIS **
- ** uptime [-<options>] **
- ** **
- ** **
- ** DESCRIPTION **
- ** Every ten seconds avenrun will update a shared memory segment **
- ** with the mean number of processes that at are ready to **
- ** run, and with the mean cpu busy percentages for user, kernal, **
- ** wait and idle processing. It also keeps track of paging **
- ** figures and non-paging I/O rates. The means are measured over **
- ** the last minute, five minutes, fifteen minutes and last 10 **
- ** seconds. These numbers are a measure for the system load. **
- ** **
- ** The uptime program allows to look at all this information. **
- ** Uptime also shows the number of users currently logged on, **
- ** and how long the system is up. **
- ** **
- ** OPTIONS **
- ** See 'uptime -h' when compiled, or the usage() funtion at the **
- ** end of this file. **
- ** **
- ** AUTHOR **
- ** Marcel J.E. Mol **
- ** **
- ** FILES **
- ** /etc/utmp logged on users and system up time **
- ** /unix to get shared memory segment **
- ** **
- ** BUGS **
- ** The results are only valid after 1, 5 and respectively 15 **
- ** minutes after startup of avenrun. **
- ** Overflow in the system counters my result in strange figures **
- ** for certain intervals. **
- ** **
- ** Mail bugs to: marcel at duteca.tudelft.nl **
- ** **
- ************************************************************************/
-
-char * copyright = "@(#) uptime ver 3.2 22/06/90 M.J.E. Mol (c) 1988, 1990";
-#include <stdio.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/sysinfo.h>
-#include <utmp.h>
-
-
-#define UTMP "/etc/utmp"
-#define KERNEL "/unix"
-
-#define MIN (60)
-#define HOUR (MIN * 60)
-#define DAY (HOUR * 24)
-#define WEEK (DAY * 7)
-#define MONTH (DAY * 30)
-
-FILE *utmp;
-
-char *months[] = {
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
-};
-
-char * progname;
-
-struct tm *localtime();
-char *vtime();
-char *uptime();
-char *itoa();
-void usage();
-
-
-main(argc,argv)
-int argc;
-char ** argv;
-{
- register struct utmp user;
- register short ucnt;
- long now;
- register int shm_id;
- register key_t shm_k;
- register float * avenrun;
- register float * busy;
- register int * meminbox;
- int opt;
- extern int optind; /* For getopt */
- extern char * optarg; /* For getopt */
- int all = 0; /* Show everything */
- int lastint = 0; /* Show last interval */
- int mem = 0; /* Show available memory */
- int util = 0; /* Show CPU utilizations */
- int ios = 0; /* Show non-paging I/O rates */
- int pagef = 0; /* Show page fault rate*/
- int pager = 0; /* Show page replace rate*/
-
- progname = *argv;
-
- while ((opt = getopt(argc, argv, "Aafhilmpu")) != EOF) {
- switch (opt) {
- case 'A' : lastint = 1;
- case 'a' : all = 1;
- break;
- case 'l' : lastint = 1;
- break;
- case 'u' : util = 1;
- break;
- case 'm' : mem = 1;
- break;
- case 'i' : ios = 1;
- break;
- case 'f' : pagef = 1;
- break;
- case 'p' : pager = 1;
- break;
- case 'h' : usage();
- break;
- default : fprintf(stderr,
- "%s: use -h option for help\n", progname);
- exit(1);
- break;
- }
- }
-
-
- if ((utmp = fopen(UTMP, "r")) == NULL) {
- perror(UTMP);
- exit(1);
- }
- ucnt = 0;
- while (fread(&user, sizeof user, 1, utmp) > 0) {
- if (user.ut_type == USER_PROCESS)
- ucnt++;
- }
-
- if ((shm_k = ftok(KERNEL, 'a')) == (key_t) -1) {
- perror(KERNEL);
- exit(2);
- }
- if ((shm_id = shmget(shm_k, (1+4) * 3 * sizeof(float), 0644)) < 0) {
- perror("shmget");
- exit(2);
- }
- if ((int) (avenrun = (float *) shmat(shm_id, (char *) 0, SHM_RDONLY))
- == -1) {
- perror("shmat");
- exit(2);
- }
-
- now = time((long *) 0);
- printf(" %s up%s, %d users, load average: ",
- vtime(&now), uptime(), ucnt);
- if (lastint)
- printf("%.2f, ", avenrun[3]);
- printf("%.2f, %.2f, %.2f\n", avenrun[0], avenrun[1], avenrun[2]);
-
- if (all || mem) {
- meminbox = (int *) &avenrun[32];
- printf (" Available real memory: %d Mb\n", *meminbox/(1024*1024));
- }
-
- if (all || util || ios || pagef || pager) {
- printf (" ");
- if (lastint)
- printf ("10-sec ");
- printf ("1-min 5-min 15-min\n");
- }
-
- if (all || util) {
- busy = avenrun + 4;
-
- /* Cpu usage by user process in busy[0..3] */
- printf (" CPU User: ");
- if (lastint)
- printf (" %6.2f%%,", 100 * busy[3]);
- printf (" %6.2f%%,", 100 * busy[0]);
- printf (" %6.2f%%,", 100 * busy[1]);
- printf (" %6.2f%%\n", 100 * busy[2]);
-
- /* Cpu usage by kernal process in busy[4..7] */
- printf (" CPU Kernel: ");
- if (lastint)
- printf (" %6.2f%%,", 100 * busy[7]);
- printf (" %6.2f%%,", 100 * busy[4]);
- printf (" %6.2f%%,", 100 * busy[5]);
- printf (" %6.2f%%\n", 100 * busy[6]);
-
- /* Cpu usage waiting for I/O in busy[8..11] */
- printf (" CPU Waiting:");
- if (lastint)
- printf (" %6.2f%%,", 100 * busy[11]);
- printf (" %6.2f%%,", 100 * busy[8]);
- printf (" %6.2f%%,", 100 * busy[9]);
- printf (" %6.2f%%\n", 100 * busy[10]);
-
- /* Cpu idle in busy[12..15] */
- printf (" CPU Idle: ");
- if (lastint)
- printf (" %6.2f%%,", 100 * busy[15]);
- printf (" %6.2f%%,", 100 * busy[12]);
- printf (" %6.2f%%,", 100 * busy[13]);
- printf (" %6.2f%%\n", 100 * busy[14]);
- }
-
- if (all || pager) {
- printf (" Pagereplace: ");
- if (lastint)
- printf ("%8.4f, ", avenrun[23]);
- printf ("%8.4f, %8.4f, %8.4f\n", avenrun[20], avenrun[21], avenrun[22]);
- }
- if (all || pagef) {
- printf (" Pagefaults: ");
- if (lastint)
- printf ("%8.4f, ", avenrun[27]);
- printf ("%8.4f, %8.4f, %8.4f\n", avenrun[24], avenrun[25], avenrun[26]);
- }
- if (all || ios) {
- printf (" I/O rate: ");
- if (lastint)
- printf ("%8.4f, ", avenrun[31]);
- printf ("%8.4f, %8.4f, %8.4f\n", avenrun[28], avenrun[29], avenrun[30]);
- }
-
- if (shmdt((char *) avenrun) == -1) {
- perror("shmdt");
- exit(2);
- }
-
- exit(0);
-
-} /* main */
-
-
-char *uptime()
-{
- static char timebuf[128];
- register struct utmp bootdata;
- register long oldpos;
- register long now;
- register short cnt, ocnt;
-
- fseek(utmp, 0L, 0);
- do {
- fread(&bootdata, sizeof(bootdata), 1, utmp);
- } while (bootdata.ut_type != BOOT_TIME);
- now = time((long *) 0);
- now -= bootdata.ut_time;
- if (now < 0L)
- return " with strange clock time";
- timebuf[0] = '\0';
- ocnt = 0;
- cnt = 0;
- while (now >= MONTH) {
- cnt++;
- now -= MONTH;
- }
- if (cnt > 0) {
- strcat(timebuf, itoa(cnt));
- strcat(timebuf, " mon");
- if (cnt > 1)
- strcat(timebuf, "s");
- if (++ocnt == 2)
- return timebuf;
- }
- cnt = 0;
- while (now >= WEEK) {
- cnt++;
- now -= WEEK;
- }
- if (cnt > 0) {
- strcat(timebuf, itoa(cnt));
- strcat(timebuf, " wk");
- if (cnt > 1)
- strcat(timebuf, "s");
- if (++ocnt == 2)
- return timebuf;
- }
- cnt = 0;
- while (now >= DAY) {
- cnt++;
- now -= DAY;
- }
- if (cnt > 0) {
- strcat(timebuf, itoa(cnt));
- strcat(timebuf, " day");
- if (cnt > 1)
- strcat(timebuf, "s");
- if (++ocnt == 2)
- return timebuf;
- }
- cnt = 0;
- while (now >= HOUR) {
- cnt++;
- now -= HOUR;
- }
- if (cnt > 0) {
- strcat(timebuf, itoa(cnt));
- strcat(timebuf, " hr");
- if (cnt > 1)
- strcat(timebuf, "s");
- if (++ocnt == 2)
- return timebuf;
- }
-
- cnt = now / MIN;
- strcat(timebuf, itoa(cnt));
- strcat(timebuf, " min");
- if ((cnt > 1) || (cnt == 0))
- strcat(timebuf, "s");
- return timebuf;
-
-} /* uptime */
-
-
-
-char *itoa(n)
-register int n;
-{
- static char buf[20];
-
- sprintf(buf, " %d", n);
- return buf;
-
-} /* itoa */
-
-
-char *vtime(when)
-register long *when;
-{
- register struct tm then;
- register struct tm now;
- static char buf[20];
-#ifdef AMPM
- register short hour;
- register short ampm;
-#endif
- long clock;
-
- clock = time((long *) 0);
- now = *localtime(&clock);
- then = *localtime(when);
- if (then.tm_mon != now.tm_mon || then.tm_mday != now.tm_mday) {
- sprintf(buf, "%s %2d", months[then.tm_mon], then.tm_mday);
- return buf;
- }
-#ifdef AMPM
- if (then.tm_hour == 0) {
- ampm = 'a';
- hour = 12;
- }
- else if (then.tm_hour > 0 && then.tm_hour < 12) {
- ampm = 'a';
- hour = then.tm_hour;
- }
- else if (then.tm_hour == 12) {
- ampm = 'p';
- hour = 12;
- }
- else {
- ampm = 'p';
- hour = then.tm_hour - 12;
- }
- sprintf(buf, "%d:%02d%cm", hour, then.tm_min, ampm);
-#else
- sprintf(buf, "%d:%02d", then.tm_hour, then.tm_min);
-#endif
- return buf;
-
-} /* vtime */
-
-
-
-void usage()
-{
-
- fprintf(stderr, "%s\n", copyright);
- fprintf(stderr, "Uptime: show performance figures of the AIX system\n");
- fprintf(stderr, "\nUsage: uptime [-Aalfhimpu]\n\n");
- fprintf(stderr, " -a: Shows all figures\n");
- fprintf(stderr, " -A: Shows all figures (including -l flag)\n");
- fprintf(stderr, " -l: Shows also last (10 second) interval figures\n");
- fprintf(stderr, " -f: Shows page fault rate\n");
- fprintf(stderr, " -h: Shows this help message\n");
- fprintf(stderr, " -i: Shows non-paging system wide I/O rate\n");
- fprintf(stderr, " -m: Shows available real memory in the machine\n");
- fprintf(stderr, " -p: Shows page replace rate\n");
- fprintf(stderr, " -u: Shows CPU busy figures\n");
-
- exit(1);
-
-} /* usage */
_E_O_F_
if test 15069 -ne `wc -c < uptime.c `; then
echo shar: "'uptime.c'" unpacked with wrong size!
fi
echo shar: extracting uptime.l
if test -f 'uptime.l'
then
echo shar: over-writing existing file "'uptime.l'"
fi
sed -e 's/^-//' << \_E_O_F_ > uptime.l
-.TH UPTIME l ver 3.2 22/06/90
-.UC
-.SH NAME
-uptime \- Show system information and performance figures.
-.SH SYNOPSIS
-.B uptime [-Aalfhimpu]
-.SH DESCRIPTION
-Uptime prints the current time, the time the system has been up,
-the number off currently logged on users,
-the average number of jobs in the run queue over the last 1, 5 and
-15 minutes.
-It optionally shows cpu busy percentages, paging information and non-paging disk
-I/O rate over the same intervals.
-It can also show the ammount of real memory in the system.
-The busy percentages are shown for cpu usage by the user, cpu usage
-by the kernel, cpu waiting for I/O completion and cpu idle time.
-Another option is to show the figures for the last 10-second interval.
-.SH OPTIONS
- -a: Shows all figures
- -A: Shows all figures (including -l flag)
- -l: Shows also last (10 second) interval figures
- -f: Shows page fault rate
- -h: Shows this help message
- -i: Shows non-paging system wide I/O rate
- -m: Shows available real memory in the machine
- -p: Shows page replace rate
- -u: Shows CPU busy figures
-.SH FILES
-/unix system name list.
-/etc/utmp hlogged on users and system boot time.
-/etc/avenrun program that measures the load and I/O stuff.
-.SH AUTHOR
-Marcel J.E. Mol marcel at duteca.tudelft.nl
_E_O_F_
if test 1354 -ne `wc -c < uptime.l `; then
echo shar: "'uptime.l'" unpacked with wrong size!
fi
echo shar: extracting avenrun.c
if test -f 'avenrun.c'
then
echo shar: over-writing existing file "'avenrun.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > avenrun.c
-/* @(#) avenrun.c ver 3.1 12/06/90 */
-/*************************************************************************
- ** **
- ** Name : avenrun **
- ** Author : Marcel J.E. Mol **
- ** Date : 23/03/88 (first release) **
- ** Version : 3.10 **
- ** Files : avenrun.c Main source file **
- ** **
- ** ------------------------- Revision List ------------------------- **
- ** Ver Date Name Remarks **
- ** 3.10 12/06/90 Marcel Mol Also save one interval data**
- ** 3.00 08/06/90 Marcel Mol Added page and I/O rates **
- ** 2.00 30/10/88 Marcel Mol Added cpu busy code **
- ** 1.10 03/05/88 Marcel Mol Use shared memory segments **
- ** and rename to avenrun **
- ** 1.00 23/03/88 Marcel Mol First release **
- ** ================================================================= **
- ** **
- ** Install as follows: cc avenrun.c -sOo avenrun **
- ** mv avenrun /etc/avenrun **
- ** /etc/avenrun & **
- ** **
- ** Usage: Become superuser. **
- ** Start avenrun with the following command: **
- ** avenrun & **
- ** Avenrun will periodically update a shared memory segment **
- ** with the averages of the past minute, 5 minutes, **
- ** 15 minutes and last 10 seconds. **
- ** Use the uptime program to see these numbers. **
- ** **
- ** **
- ************************************************************************/
-
- /************************************************************************
- ** **
- ** NAME **
- ** avenrun -- Keep track of system load **
- ** **
- ** **
- ** SYNOPSIS **
- ** avenrun **
- ** **
- ** **
- ** DESCRIPTION **
- ** Every ten seconds avenrun will update a shared memory segment **
- ** with the mean number of processes that at are ready to **
- ** run, and with the mean cpu busy percentages for user, kernal, **
- ** wait and idle processing. It also keeps track of paging **
- ** figures and non-paging I/O rates. The means are measured over **
- ** the last minute, five minutes, fifteen minutes and last 10 **
- ** seconds. These numbers are a measure for the system load. **
- ** **
- ** AUTHOR **
- ** Marcel J.E. Mol **
- ** **
- ** BUGS **
- ** The results are only valid after 1, 5 and respectively 15 **
- ** minutes after startup of avenrun. **
- ** Overflow in the system counters my result in strange figures **
- ** for certain intervals. **
- ** Mail bugs to: marcel at duteca.tudelft.nl **
- ** **
- ************************************************************************/
-char *copyright = "@(#) avenrun.c ver 3.1 12/06/90 copyright (c) M.J.E. Mol";
-
-#include <nlist.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/sysinfo.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <signal.h>
-
-#define SYSTEM "/unix"
-#define TIME 10 /* Time between polls */
-#define SAVES 91 /* == 15 min * 60 sec / TIME + 1 */
-
-
-struct nlist nl[] = { /* We need the runque and cpu field */
- { "_sysinfo" }, /* of the sysinfo structure */
-#define X_SYSINFO 0
- { "_meminbox" },
-#define X_MEMINBOX 1
- { 0 }
-};
-
-
-struct sysinfo inf;
-long runque[SAVES]; /* Array of run lengths */
-long pagereplace[SAVES]; /* Array of page in/outs */
-long pagefaults[SAVES]; /* Array of pagefault */
-long otherio[SAVES]; /* Array of non-page I/Os */
-time_t busyticks[SAVES][4]; /* Busy counts for cpu */
-long ptime[SAVES]; /* Array of poll times */
-key_t aven_key; /* Key for shared memory */
-int aven_shm; /* Shared memory */
-float *avenrun = (float *) 0; /* Shared memory */
-
-
-int cleanup();
-
-
-main()
-{
- int kmem; /* file descriptor for /dev/kmem */
- register long runadr; /* address in kmem of sysinfo.runque */
- register long cpuadr; /* address in kmem of sysinfo.cpu */
- register float *load; /* load pointer in shared memory */
- register float *pager; /* pagereplace pointer in shared mem.*/
- register float *pagef; /* pagefault pointer in shared mem. */
- register float *ior; /* non-page I/O pointer in shared mem*/
- register float *busy; /* busy pointer in shared memory */
- register int i, i0, i1, i5, i15; /* indices in arrays */
- register int ttime; /* time between intervals */
- register time_t *p, *q; /* pointers in the busyticks array */
-
- switch (fork()) { /* Go run in background */
- case -1:
- perror("fork");
- exit(1);
- case 0:
- break;
- default:
- exit(0);
- }
-
- setpgrp(); /* create own process group */
-
- nlist(SYSTEM, nl); /* get address of system info */
- if ((nl[0].n_type==0) && (nl[0].n_value == 0)) {
- fprintf(stderr, "No namelist\n");
- exit(1);
- }
-
- if ((kmem = open("/dev/kmem", 0)) == -1) { /* read from kmem */
- perror("open kmem");
- exit(1);
- }
- runadr = (long) nl[X_SYSINFO].n_value + /* address of runque field */
- (long) &inf.runque - (long) &inf;
- cpuadr = (long) nl[X_SYSINFO].n_value + /* address of cpu field */
- (long) inf.cpu - (long) &inf;
-
- signal(SIGINT , cleanup);
- signal(SIGQUIT, cleanup);
- signal(SIGHUP , cleanup);
-
- init_shm(); /* Initialize packet prototype */
-
- /*
- * The system periodically examines the process table to see
- * whether any processes are in memory and in ready state. If so,
- * the system adds the number of such processes to the runque counter
- * Thus we periodically read this counter to determine the number of
- * such process that were added. By deviding this number by the
- * time past between two reads, the number of such processes per
- * second is calculated.
- *
- * The cpu fields (CPU_USER, CPU_KERNEL, CPU_IDLE, CPU_WAIT), tell
- * how many clock ticks the cpu is running in the indicated state.
- * from this the cpu busy percentages are calculated.
- */
-
- ptime[0] = time((long *) 0); /* use real time instead of TIME constant */
- if (lseek(kmem, runadr, 0) == -1) {
- perror("lseek");
- cleanup();
- }
- if (read(kmem, (char *) &runque[0], sizeof(long)) != sizeof(long)) {
- perror("kmemread");
- cleanup();
- }
- if (lseek(kmem, cpuadr, 0) == -1) {
- perror("lseek");
- cleanup();
- }
- if (read(kmem, (char *) &busyticks[0][0], 4 * sizeof(time_t))
- != 4 * sizeof(time_t)) {
- perror("kmemread");
- cleanup();
- }
- if (lseek(kmem, (long) nl[X_MEMINBOX].n_value, 0) == -1) {
- perror("lseek");
- cleanup();
- }
- if (read(kmem, (char *) &avenrun[32], sizeof (int)) != sizeof(int)) {
- perror("kmemread");
- exit(3);
- }
- pagereplace[0] = *(int *)0xbc;
- pagefaults[0] = *(int *)0xc0;
- otherio[0] = *(int *)0xc4;
-
- /*
- * Init the other counts.
- * This implies that the means are not
- * valid for 1, 5 resp. 15 minutes.
- */
-
- for (i = 1; i < SAVES; i++) {
- runque[i] = runque[i-1];
- pagereplace[i] = pagereplace[i-1];
- pagefaults[i] = pagefaults[i-1];
- otherio[i] = otherio[i-1];
- ptime[i] = ptime[i-1];
- busyticks[i][CPU_USER] = busyticks[i-1][CPU_USER];
- busyticks[i][CPU_KERNEL] = busyticks[i-1][CPU_KERNEL];
- busyticks[i][CPU_WAIT] = busyticks[i-1][CPU_WAIT];
- busyticks[i][CPU_IDLE] = busyticks[i-1][CPU_IDLE];
- }
-
- /*************************************************************************/
- /* the shared memory segment will save the calculated results as */
- /* floats in the following way: */
- /* +---------------------------------+ */
- /* 00: queuelen | 10-sec | 1-min | 5-min | 15-min | */
- /* 04: user-cpu | 10-sec | 1-min | 5-min | 15-min | */
- /* 08: kernel-cpu | 10-sec | 1-min | 5-min | 15-min | */
- /* 12: wait-cpu | 10-sec | 1-min | 5-min | 15-min | */
- /* 16: idle-cpu | 10-sec | 1-min | 5-min | 15-min | */
- /* 20: page-replace | 10-sec | 1-min | 5-min | 15-min | */
- /* 24: page-faults | 10-sec | 1-min | 5-min | 15-min | */
- /* 28: non-pageio | 10-sec | 1-min | 5-min | 15-min | */
- /* +---------------------------------+ */
- /*************************************************************************/
-
- load = &avenrun[0]; /* 4 floats to store load results */
- busy = &avenrun[4]; /* 16 floats for cpu busy results */
- pager= &avenrun[4+4*4]; /* 4 floats for pagereplace rate */
- pagef= &avenrun[4+4*4+4]; /* 4 floats for pagefault rate */
- ior = &avenrun[4+4*4+4+4]; /* 4 floats for non-page I/O rate */
- i = 0; /* Indices in arrays */
- i0 = SAVES - 1;
- i1 = SAVES - 60/TIME;
- i5 = SAVES - 300/TIME;
- i15 = 1;
-
- for (;;) {
- sleep(TIME); /* wait for next time to poll */
- if (++i == SAVES) i = 0; /* use arrays as circular buffers */
- if (++i0 == SAVES) i0 = 0;
- if (++i1 == SAVES) i1 = 0;
- if (++i5 == SAVES) i5 = 0;
- if (++i15 == SAVES) i15 = 0;
-
- ptime[i] = time((long *) 0);
- pagereplace[i] = *(int *)0xbc;
- pagefaults[i] = *(int *)0xc0;
- otherio[i] = *(int *)0xc4;
- if (lseek(kmem, runadr, 0) == -1) { /* must seek for every poll */
- perror("lseek");
- cleanup();
- }
- if (read(kmem, (char *) &runque[i], sizeof(long)) != sizeof(long)) {
- perror("kmemread");
- cleanup();
- }
- if (lseek(kmem, cpuadr, 0) == -1) {
- perror("lseek");
- cleanup();
- }
- if (read(kmem, (char *) &busyticks[i][0], 4 * sizeof(time_t))
- != 4 * sizeof(time_t)) {
- perror("kmemread");
- cleanup();
- }
- /* update load data */
- ttime = ptime[i] - ptime[i1]; /* passed time between polls */
- load[0] = ((float)(runque[i] - runque[i1])) / ttime;
- pager[0] = ((float)(pagereplace[i] - pagereplace[i1])) / ttime;
- pagef[0] = ((float)(pagefaults[i] - pagefaults[i1])) / ttime;
- ior[0] = ((float)(otherio[i] - otherio[i1])) / ttime;
- ttime = ptime[i] - ptime[i5];
- load[1] = ((float)(runque[i] - runque[i5])) / ttime;
- pager[1] = ((float)(pagereplace[i] - pagereplace[i5])) / ttime;
- pagef[1] = ((float)(pagefaults[i] - pagefaults[i5])) / ttime;
- ior[1] = ((float)(otherio[i] - otherio[i5])) / ttime;
- ttime = ptime[i] - ptime[i15];
- load[2] = ((float)(runque[i] - runque[i15])) / ttime;
- pager[2] = ((float)(pagereplace[i] - pagereplace[i15])) / ttime;
- pagef[2] = ((float)(pagefaults[i] - pagefaults[i15])) / ttime;
- ior[2] = ((float)(otherio[i] - otherio[i15])) / ttime;
- ttime = ptime[i] - ptime[i0];
- load[3] = ((float)(runque[i] - runque[i0])) / ttime;
- pager[3] = ((float)(pagereplace[i] - pagereplace[i0])) / ttime;
- pagef[3] = ((float)(pagefaults[i] - pagefaults[i0])) / ttime;
- ior[3] = ((float)(otherio[i] - otherio[i0])) / ttime;
-
- p = busyticks[i];
- q = busyticks[i1]; /* update 1 minute interval */
- ttime = (p[CPU_USER] - q[CPU_USER]) + /* total ticks */
- (p[CPU_KERNEL] - q[CPU_KERNEL]) +
- (p[CPU_WAIT] - q[CPU_WAIT]) +
- (p[CPU_IDLE] - q[CPU_IDLE]);
- busy[0] = ((float)(p[CPU_USER] - q[CPU_USER])) / ttime;
- busy[4] = ((float)(p[CPU_KERNEL] - q[CPU_KERNEL])) / ttime;
- busy[8] = ((float)(p[CPU_WAIT] - q[CPU_WAIT])) / ttime;
- busy[12]= ((float)(p[CPU_IDLE] - q[CPU_IDLE])) / ttime;
-
- q = busyticks[i5]; /* update 5 minute interval */
- ttime = (p[CPU_USER] - q[CPU_USER]) +
- (p[CPU_KERNEL] - q[CPU_KERNEL]) +
- (p[CPU_WAIT] - q[CPU_WAIT]) +
- (p[CPU_IDLE] - q[CPU_IDLE]);
- busy[1] = ((float)(p[CPU_USER] - q[CPU_USER])) / ttime;
- busy[5] = ((float)(p[CPU_KERNEL] - q[CPU_KERNEL])) / ttime;
- busy[9] = ((float)(p[CPU_WAIT] - q[CPU_WAIT])) / ttime;
- busy[13]= ((float)(p[CPU_IDLE] - q[CPU_IDLE])) / ttime;
-
- q = busyticks[i15]; /* update 15 minute interval */
- ttime = (p[CPU_USER] - q[CPU_USER]) +
- (p[CPU_KERNEL] - q[CPU_KERNEL]) +
- (p[CPU_WAIT] - q[CPU_WAIT]) +
- (p[CPU_IDLE] - q[CPU_IDLE]);
- busy[2] = ((float)(p[CPU_USER] - q[CPU_USER])) / ttime;
- busy[6] = ((float)(p[CPU_KERNEL] - q[CPU_KERNEL])) / ttime;
- busy[10]= ((float)(p[CPU_WAIT] - q[CPU_WAIT])) / ttime;
- busy[14]= ((float)(p[CPU_IDLE] - q[CPU_IDLE])) / ttime;
-
- q = busyticks[i0]; /* update 10 second interval */
- ttime = (p[CPU_USER] - q[CPU_USER]) +
- (p[CPU_KERNEL] - q[CPU_KERNEL]) +
- (p[CPU_WAIT] - q[CPU_WAIT]) +
- (p[CPU_IDLE] - q[CPU_IDLE]);
- busy[3] = ((float)(p[CPU_USER] - q[CPU_USER])) / ttime;
- busy[7] = ((float)(p[CPU_KERNEL] - q[CPU_KERNEL])) / ttime;
- busy[11]= ((float)(p[CPU_WAIT] - q[CPU_WAIT])) / ttime;
- busy[15]= ((float)(p[CPU_IDLE] - q[CPU_IDLE])) / ttime;
- }
-
-} /* main */
-
-
-
-init_shm()
-{
- if ((aven_key = ftok(SYSTEM, 'a')) == (key_t) -1) {
- perror(SYSTEM);
- exit(1);
- }
- /*
- * 1 for runque
- * 4 for CPU busy percentages
- * 1 for pagereplace
- * 1 for pagefaults
- * 1 for otherio
- * and how much memory do we have
- */
- if ((aven_shm = shmget(aven_key, (1+4+1+1+1) * 4 * sizeof (float) +
- sizeof(int),
- IPC_CREAT|IPC_EXCL|0644)) < 0) {
- perror("shmget");
- exit(1);
- }
- if ((int) (avenrun = (float *) shmat(aven_shm, (char *) 0, 0)) == -1) {
- perror("shmat");
- if (shmdt((char *) avenrun) == -1)
- perror("shmdt");
- if (shmctl(aven_shm, IPC_RMID, (struct shmid_ds *) 0) < 0)
- perror("shmctl(IPC_RMID)");
- exit(1);
- }
-
-} /* init_shm */
-
-
-
-cleanup()
-{
- if (avenrun == (float *) 0) {
- fprintf(stderr, "No shared memory segment initiated\n");
- exit(0);
- }
- if (shmdt(avenrun) < 0)
- perror("shmdtl");
- if (shmctl(aven_shm, IPC_RMID, (struct shmid_ds *) 0) < 0) {
- perror("shmctl");
- exit(1);
- }
-
- exit(0);
-
-} /* cleanup */
-
_E_O_F_
if test 17927 -ne `wc -c < avenrun.c `; then
echo shar: "'avenrun.c'" unpacked with wrong size!
fi
echo shar: extracting delshm.c
if test -f 'delshm.c'
then
echo shar: over-writing existing file "'delshm.c'"
fi
sed -e 's/^-//' << \_E_O_F_ > delshm.c
-
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-main() {
- int avend_id;
- key_t avend_k;
-
- if ((avend_k = ftok("/unix", 'a')) == (key_t) -1) {
- perror("/unix");
- exit(1);
- }
- if ((avend_id = shmget(avend_k, 3 * sizeof(double), 0644)) < 0) {
- perror("shmget");
- exit(1);
- }
- else if (shmctl(avend_id, IPC_RMID, (struct shmid_ds *)0) == -1) {
- perror("shctl");
- exit(1);
- }
- exit(0);
-
-} /* main */
_E_O_F_
if test 442 -ne `wc -c < delshm.c `; then
echo shar: "'delshm.c'" unpacked with wrong size!
fi
# end of shell archive
exit 0
--
#########################################
# Marcel J.E. Mol ######################################
# Delft University of Technology Pink Elephant Management Services #
# The Netherlands Voorburg #
# UUCP: marcel at duteca.tudelft.nl Tel: 070-3694231 #
# ######################################
#########################################
More information about the Comp.unix.aix
mailing list