v14i058: u386mon 2.20-S5R3 system monitor (386,68k,Tandem) part 5 of 6
wht at gatech.edu
wht at gatech.edu
Fri Aug 17 10:53:41 AEST 1990
Posting-number: Volume 14, Issue 58
Submitted-by: wht at gatech.edu@n4hgf.UUCP (Warren Tucker)
Archive-name: u386mon-2.20/part05
#!/bin/sh
# This is part 05 of u386mon.2.20
if touch 2>&1 | fgrep 'amc' > /dev/null
then TOUCH=touch
else TOUCH=true
fi
# ============= u386mon.c ==============
echo "x - extracting u386mon.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > u386mon.c &&
Xchar *revision = "2.20";
X/*+-------------------------------------------------------------------------
X u386mon.c - UNIX 386 (and other) system monitor
X ...!{gatech,emory}!n4hgf!wht
X
X Defined functions:
X adb_trap()
X calc_cpu_avg(per_state)
X calc_wait_avg(per_state)
X caught_signal(sig)
X draw_cpuscale_literals(win,y,x)
X draw_per_sec_literals(win,y,x)
X draw_waitscale_literals(win,y,x)
X extra_info_stuff()
X extra_static_stuff()
X get_cpu_avg(cpu_ticks,period)
X get_elapsed_time(elapsed_seconds)
X get_wait_avg(wait_ticks,period)
X leave(exit_code)
X leave_text(text,exit_code)
X leaving(exit_code)
X main(argc,argv,envp)
X update_cpuscale(win,y,x,width,per_state)
X update_waitscale(win,y,x,width,per_state,total_ticks)
X
X00000000001111111111222222222233333333334444444444555555555566666666667777777777
X01234567890123456789012345678901234567890123456789012345678901234567890123456789
X u386mon xxx.xxx PLOCK INVALID hh:mm:ss wht at n4hgf
X
X---- CPU --- tot usr ker brk ---------------------------------------------------
X Instant % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X 5 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X10 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X---- Wait -- tot io pio swp ---------------------------------------------------
X Instant % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X 5 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X10 Sec Avg % ### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:08-01-1990-19:24-jdc at dell.com-add DELL config */
X/*:08-01-1990-17:25-wht at n4hgf-fix sysi86 swap calculations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:07-28-1990-15:05-wht at n4hgf-make CYCLEmsec variable */
X/*:07-11-1990-03:45-root at n4hgf-faster proc table manipulation */
X/*:07-10-1990-19:06-root at n4hgf-redesign attributes/color pairs */
X/*:07-10-1990-18:33-root at n4hgf-move pio wait to medium alert */
X/*:07-10-1990-18:01-root at n4hgf-"improvement" didnt do much, but leave for now */
X/*:07-10-1990-13:54-root at n4hgf-improve nap heuristics and catch signals */
X/*:07-08-1990-20:31-root at n4hgf-make room for phread/phwrite */
X/*:07-03-1990-02:48-root at n4hgf-more accurate timing using ftime calculations */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-27-1990-01:07-wht at n4hgf-add ^R and ^L refresh */
X/*:06-25-1990-17:34-wht at n4hgf-add detail extra for 25 line tubes */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:26-r at n4hgf-version x0.12 seems bug free */
X/*:06-15-1990-18:32-wht at n4hgf-creation */
X
X#include "config.h"
X#define M_TERMINFO
X#include <curses.h>
X#undef timeout /* conflict in curses.h and bootinfo.h per trb at ima.ima.isc.com */
X#undef reg /* per nba at sysware.sysware.dk */
X#include "libpanel.h"
X#include <signal.h>
X#include <string.h>
X#include <fcntl.h>
X#include <nlist.h>
X#include <errno.h>
X#include <time.h>
X#include <sys/types.h>
X#if defined(HAS_TIMEB)
X# include <sys/timeb.h>
X#endif
X#include <sys/lock.h>
X#include <sys/utsname.h>
X#include <sys/stat.h>
X#if defined(HAS_ASCII)
X# include <sys/ascii.h>
X#else
X#define A_ESC '\033'
X#endif
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#if defined(HAS_BOOTINFO)
X# include <sys/bootinfo.h>
X#endif
X#include <sys/tuneable.h>
X#include <sys/sysinfo.h>
X#include <sys/sysmacros.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#if defined(mips)
X#include <sys/sbd.h>
X#endif
X#include <sys/proc.h>
X#include <sys/var.h>
X#if defined(i386) || defined(i486)
X# include <sys/sysi86.h>
X#endif
X#if defined(mips)
X# include <sys/sysmips.h>
X#endif
X#include <sys/swap.h>
X#if !defined(mips)
X# include <sys/trap.h>
X#endif
X#include "nlsym.h"
X#include "libkmem.h"
X#include "libmem.h"
X#include "libswap.h"
X#include "libnlsym.h"
X#include "u386mon.h"
X
Xlong nap();
XPANEL *mkpanel();
X
X#if defined(HAS_TIMEB)
X#define delta_msec(t,t0) ((( t.time * 1000L) + t.millitm) - \
X ((t0.time * 1000L) + t0.millitm))
X#endif
X
X#define INEXACT_STATE 2
X#define INVALID_STATE 5
X
X#if defined(mips)
X#define CYCLEmsecDef 5000L
X#define CYCLEmsecMax 9000L
X#else
X#define CYCLEmsecDef 2000L
X#define CYCLEmsecMax 4000L
X#endif
X
Xlong CYCLEmsec = CYCLEmsecDef;
X
Xstruct sysinfo sysinfo;
Xstruct sysinfo sysinfo_last;
X#define sysidelta(x) (sysinfo.x - sysinfo_last.x)
X
Xstruct minfo minfo;
Xstruct minfo minfo_last;
X#define midelta(x) (minfo.x - minfo_last.x)
X
X#if defined(HAS_BOOTINFO)
Xstruct bootinfo bootinfo;
X#endif
X
Xswpt_t swaptab [MSFILES];
Xswpi_t swapint = {SI_LIST, (char *)swaptab};
Xstruct tune tune;
Xstruct utsname utsname;
Xstruct var v;
X
X#if defined(HAS_TIMEB)
Xstruct timeb timeb_cycle_start;
Xstruct timeb timeb_cycle_end;
Xstruct timeb timeb_info_read;
Xstruct timeb timeb_last_info_read;
X#endif
X
Xint hz;
Xint nswap; /* seems to be in units of NBPSCTR bytes */
Xint maxmem;
Xint freemem;
Xdaddr_t myreadlen = 0L;
Xint myreadcnt = 0;
Xint stat_period_msec_y = -1;
Xint stat_period_msec_x = -1;
Xint color_avail = 0;
Xint invalidity = 0;
X
XPANEL *pscr;
XWINDOW *wscr;
Xextern WINDOW *wdet;
X
X#define CPU_AVG_MAX 10
Xint cpu_avg_init = 0;
Xtime_t *cpu_avg[CPU_AVG_MAX];
Xtime_t cpu_ticks[5];
X
X#define WAIT_AVG_MAX 10
Xint wait_avg_init = 0;
Xtime_t *wait_avg[WAIT_AVG_MAX];
Xtime_t wait_ticks[5];
X
X/*+-------------------------------------------------------------------------
X leaving() - perform leave() basic processing and return
X--------------------------------------------------------------------------*/
Xvoid
Xleaving()
X{
X wmove(wscr,CMD_TLY,0);
X use_cp(wscr,cpLIT);
X wclrtoeol(wscr);
X pflush();
X endwin();
X} /* end of leaving */
X
X/*+-------------------------------------------------------------------------
X leave(exit_code) - leave program with exit code
X--------------------------------------------------------------------------*/
Xvoid
Xleave(exit_code)
Xint exit_code;
X{
X leaving();
X exit(exit_code);
X} /* end of leave */
X
X/*+-------------------------------------------------------------------------
X leave_text(text,exit_code) - leave program with message and exit code
XIf exit_code == 255, do wperror
X--------------------------------------------------------------------------*/
Xvoid
Xleave_text(text,exit_code)
Xchar *text;
Xint exit_code;
X{
X if(exit_code == 255)
X {
X int y;
X register x;
X extern int errno;
X extern int sys_nerr;
X extern char *sys_errlist[];
X
X top_panel(pscr);
X wmove(wscr,MSG_TLY - 2,0);
X use_cp(wscr,cpHIGH);
X x = 0;
X while(x++ < COLS)
X waddch(wscr,(chtype)' ');
X wmove(wscr,MSG_TLY - 1,0);
X wprintw(wscr,"errno %d",errno);
X if(errno < sys_nerr)
X wprintw(wscr,": %s",sys_errlist[errno]);
X getyx(wscr,y,x);
X while(x++ < COLS)
X waddch(wscr,(chtype)' ');
X }
X if (text && *text) disp_msg(cpHIGH,text);
X leave(exit_code);
X} /* end of leave_text */
X
X/*+-------------------------------------------------------------------------
X adb_trap() - convenient trap for catching abort
X
X Get a look at stack before abort() botches it
X--------------------------------------------------------------------------*/
X#if defined(ADB_DEBUG)
Xvoid
Xadb_trap()
X{
X printf("too bad .... goodbye\n");
X} /* end of adb_trap */
X#endif
X
X/*+-------------------------------------------------------------------------
X caught_signal(sig) - SIGHUP thru SIGSYS: leave with possible abort
X--------------------------------------------------------------------------*/
Xvoid
Xcaught_signal(sig)
Xint sig;
X{
X leaving();
X switch(sig)
X {
X case SIGQUIT:
X case SIGILL:
X case SIGTRAP:
X case SIGIOT:
X case SIGEMT:
X case SIGFPE:
X case SIGBUS:
X case SIGSEGV:
X case SIGSYS:
X#if defined(ADB_DEBUG)
X adb_trap(); /* if debugging, stop at convenient breakpoint */
X#endif
X abort();
X }
X exit(200);
X} /* end of caught_signal */
X
X/*+-----------------------------------------------------------------------
X char *get_elapsed_time(elapsed_seconds) - "ddd+hh:mm:ss" returned
X static string address is returned
X------------------------------------------------------------------------*/
Xchar *
Xget_elapsed_time(elapsed_seconds)
Xtime_t elapsed_seconds;
X{
Xstatic char elapsed_time_str[32];
Xtime_t dd,hh,mm,ss;
X
X dd = 0;
X hh = elapsed_seconds / 3600;
X if(hh > 24)
X {
X dd = hh / 24;
X elapsed_seconds -= dd * 3600 * 24;
X hh %= 24;
X }
X elapsed_seconds -= hh * 3600;
X mm = elapsed_seconds / 60L;
X elapsed_seconds -= mm * 60L;
X ss = elapsed_seconds;
X
X if(dd)
X (void)sprintf(elapsed_time_str,"%3ld+%02ld:%02ld:%02ld",dd,hh,mm,ss);
X else
X (void)sprintf(elapsed_time_str," %2ld:%02ld:%02ld",hh,mm,ss);
X return(elapsed_time_str);
X} /* end of get_elapsed_time */
X
X/*+-------------------------------------------------------------------------
X draw_cpuscale_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_cpuscale_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
Xint x2 = x;
X
X wmove(win,y,x);
X use_cp(wscr,cpBANNER);
X waddstr(win,"---- CPU --- tot usr ker brk ");
X getyx(win,y,x2);
X while(x2 < COLS)
X waddch(win,(chtype)'-'),x2++;
X use_cp(wscr,cpLIT);
X wmove(win,y + 1,x);
X if(CYCLEmsec == 1000L)
X waddstr(win," Instant % ");
X else
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec / 1000L));
X wmove(win,y + 2,x);
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 5 / 1000L));
X wmove(win,y + 3,x);
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 10 / 1000L));
X
X} /* end of draw_cpuscale_literals */
X
X/*+-------------------------------------------------------------------------
X update_cpuscale(win,y,width,per_state)
X
X000000000011111111112222222222333333333344444444445555555555666666
X012345678901234567890123456789012345678901234567890123456789012345
Xtot usr ker misc
X### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X--------------------------------------------------------------------------*/
X#define _CPUSCALE_TX 0
X#define _CPUSCALE_UX 4
X#define _CPUSCALE_KX 8
X#define _CPUSCALE_BX 12
X#define _CPUSCALE_SX 16
X
Xtime_t
Xupdate_cpuscale(win,y,x,width,per_state)
XWINDOW *win;
Xint y;
Xint x;
Xregister width;
Xtime_t *per_state;
X{
Xregister itmp;
Xint accum = 0;
Xtime_t idle = per_state[CPU_IDLE] + per_state[CPU_WAIT];
Xtime_t cpu_ticks_total = idle + per_state[CPU_SXBRK] +
X per_state[CPU_KERNEL] + per_state[CPU_USER];
Xtime_t percent_user = (per_state[CPU_USER] * 100) / cpu_ticks_total;
Xtime_t percent_kernel = (per_state[CPU_KERNEL] * 100) / cpu_ticks_total;
Xtime_t percent_break = (per_state[CPU_SXBRK] * 100) / cpu_ticks_total;
Xtime_t percent_busy = percent_user + percent_kernel + percent_break;
X
X if(!idle) /* take care of integer div truncation */
X percent_busy = 100;
X
X wmove(win,y, x + _CPUSCALE_TX);
X if(percent_busy < 70)
X use_cp(wscr,cpLOW);
X else if(percent_busy < 90)
X use_cp(wscr,cpMED);
X else
X use_cp(wscr,cpHIGH);
X wprintw(win,"%3ld",percent_busy);
X
X wmove(win,y, x + _CPUSCALE_UX);
X use_cp(wscr,cpINFO);
X wprintw(win,"%3ld",percent_user);
X
X wmove(win,y, x + _CPUSCALE_KX);
X wprintw(win,"%3ld",percent_kernel);
X
X wmove(win,y, x + _CPUSCALE_BX);
X wprintw(win,"%3ld",percent_break);
X
X wmove(win,y, x + _CPUSCALE_SX);
X use_cp(wscr,cpLOW);
X itmp = (width * percent_user) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'u');
X
X use_cp(wscr,cpMED);
X itmp = (width * percent_kernel) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'k');
X
X use_cp(wscr,cpHIGH);
X itmp = (width * percent_break) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'b');
X
X if((percent_busy > 98) && ((width - accum) > 0))
X {
X waddch(win,(chtype)'*');
X accum++;
X }
X
X if((itmp = (width - accum)) > 0)
X {
X use_cp(wscr,cpLIT);
X while(itmp--)
X waddch(win,(chtype)' ');
X }
X return(cpu_ticks_total);
X} /* end of update_cpuscale */
X
X/*+-------------------------------------------------------------------------
X calc_cpu_avg(per_state) - add per_state array to avg array
X--------------------------------------------------------------------------*/
Xvoid
Xcalc_cpu_avg(per_state)
Xtime_t per_state[];
X{
Xregister itmp;
X
X if(!cpu_avg_init)
X {
X for(itmp = 0; itmp < CPU_AVG_MAX; itmp++)
X (void)memcpy(cpu_avg[itmp],per_state,sizeof(time_t) * 5);
X cpu_avg_init = 1;
X }
X else
X {
X for(itmp = 0; itmp < CPU_AVG_MAX - 1; itmp++)
X (void)memcpy(cpu_avg[itmp],cpu_avg[itmp + 1],sizeof(time_t) * 5);
X (void)memcpy(cpu_avg[itmp],per_state,sizeof(time_t) * 5);
X }
X
X} /* end of calc_cpu_avg */
X
X/*+-------------------------------------------------------------------------
X get_cpu_avg(cpu_ticks,period)
X--------------------------------------------------------------------------*/
Xget_cpu_avg(cpu_ticks,period)
Xtime_t cpu_ticks[];
Xint period;
X{
Xregister iperiod = CPU_AVG_MAX;
Xregister istate;
Xregister count = period;
X
X for(istate = 0; istate < 5; istate++)
X cpu_ticks[istate] = 0;
X
X while(count--)
X {
X iperiod--;
X for(istate = 0; istate < 5; istate++)
X {
X cpu_ticks[istate] += (cpu_avg[iperiod])[istate];
X }
X }
X
X for(istate = 0; istate < 5; istate++)
X cpu_ticks[istate] /= period;
X
X} /* end of get_cpu_avg */
X
X/*+-------------------------------------------------------------------------
X draw_waitscale_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_waitscale_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
Xint x2 = x;
X
X wmove(win,y,x);
X use_cp(wscr,cpBANNER);
X waddstr(win,"---- Wait -- tot io pio swp -- (% of real time) ");
X getyx(win,y,x2);
X while(x2 < COLS)
X waddch(win,(chtype)'-'),x2++;
X use_cp(wscr,cpLIT);
X wmove(win,y + 1,x);
X if(CYCLEmsec == 1000L)
X waddstr(win," Instant % ");
X else
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec / 1000L));
X wmove(win,y + 2,x);
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 5 / 1000L));
X wmove(win,y + 3,x);
X wprintw(win,"%2d Sec Avg %%",(int)(CYCLEmsec * 10 / 1000L));
X
X} /* end of draw_waitscale_literals */
X
X/*+-------------------------------------------------------------------------
X draw_per_sec_literals(win)
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_per_sec_literals(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
X
X wmove(win,y,x);
X use_cp(wscr,cpBANNER);
X waddstr(win,"---- Sysinfo/Minfo --- (last ");
X getyx(win,stat_period_msec_y,stat_period_msec_x);
X wprintw(win," %4ld msec activity) ",CYCLEmsec);
X getyx(win,y,x);
X while(x < getmaxx(win))
X waddch(win,(chtype)'-'),x++;
X
X} /* end of draw_per_sec_literals */
X
X/*+-------------------------------------------------------------------------
X update_waitscale(win,y,width,per_state)
X
X000000000011111111112222222222333333333344444444445555555555666666
X012345678901234567890123456789012345678901234567890123456789012345
Xtot io pio swp
X### ### ### ### xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X--------------------------------------------------------------------------*/
X#define _WAITSCALE_TX 0
X#define _WAITSCALE_IX 4
X#define _WAITSCALE_PX 8
X#define _WAITSCALE_WX 12
X#define _WAITSCALE_SX 16
X
Xtime_t
Xupdate_waitscale(win,y,x,width,per_state,total_ticks)
XWINDOW *win;
Xint y;
Xint x;
Xregister width;
Xtime_t *per_state;
Xtime_t total_ticks;
X{
Xregister itmp;
Xint accum = 0;
Xtime_t percent_io = 0L;
Xtime_t percent_swap = 0L;
Xtime_t percent_pio = 0L;
Xtime_t percent_total_wait;
Xtime_t total_wait;
X
X/* crock: because of latency, total_ticks < all wait ticks sometimes */
X total_wait = per_state[W_IO] + per_state[W_SWAP] + per_state[W_PIO];
X if(total_ticks < total_wait)
X total_ticks = total_wait;
X
X if(total_ticks)
X {
X percent_io = (per_state[W_IO] * 100) / total_ticks;
X percent_pio = (per_state[W_PIO] * 100) / total_ticks;
X percent_swap = (per_state[W_SWAP] * 100) / total_ticks;
X }
X
X wmove(win,y, x + _WAITSCALE_TX);
X percent_total_wait = percent_io + percent_swap + percent_pio;
X if(percent_total_wait < 30)
X use_cp(wscr,cpLOW);
X else if(percent_total_wait < 50)
X use_cp(wscr,cpMED);
X else
X use_cp(wscr,cpHIGH);
X wprintw(win,"%3ld",percent_total_wait);
X
X use_cp(wscr,cpINFO);
X wmove(win,y, x + _WAITSCALE_IX);
X wprintw(win,"%3ld",percent_io);
X
X wmove(win,y, x + _WAITSCALE_PX);
X wprintw(win,"%3ld",percent_pio);
X
X wmove(win,y, x + _WAITSCALE_WX);
X wprintw(win,"%3ld",percent_swap);
X
X wmove(win,y, x + _WAITSCALE_SX);
X use_cp(wscr,cpLOW);
X itmp = (width * percent_io) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'i');
X
X use_cp(wscr,cpMED);
X itmp = (width * percent_pio) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'p');
X
X use_cp(wscr,cpHIGH);
X itmp = (width * percent_swap) / 100;
X accum += itmp;
X while(itmp--)
X waddch(win,(chtype)'s');
X
X if((itmp = (width - accum)) > 0)
X {
X use_cp(wscr,cpLIT);
X while(itmp--)
X waddch(win,(chtype)' ');
X }
X
X} /* end of update_waitscale */
X
X/*+-------------------------------------------------------------------------
X calc_wait_avg(per_state) - add per_state array to avg array
X--------------------------------------------------------------------------*/
Xvoid
Xcalc_wait_avg(per_state)
Xtime_t per_state[];
X{
Xregister itmp;
X
X if(!wait_avg_init)
X {
X for(itmp = 0; itmp < WAIT_AVG_MAX; itmp++)
X (void)memcpy(wait_avg[itmp],per_state,sizeof(time_t) * 3);
X wait_avg_init = 1;
X }
X else
X {
X for(itmp = 0; itmp < WAIT_AVG_MAX - 1; itmp++)
X (void)memcpy(wait_avg[itmp],wait_avg[itmp + 1],sizeof(time_t) * 3);
X (void)memcpy(wait_avg[itmp],per_state,sizeof(time_t) * 3);
X }
X
X} /* end of calc_wait_avg */
X
X/*+-------------------------------------------------------------------------
X get_wait_avg(wait_ticks,period)
X--------------------------------------------------------------------------*/
Xget_wait_avg(wait_ticks,period)
Xtime_t wait_ticks[];
Xint period;
X{
Xregister iperiod = WAIT_AVG_MAX;
Xregister istate;
Xregister count = period;
X
X for(istate = 0; istate < 3; istate++)
X wait_ticks[istate] = 0;
X
X while(count--)
X {
X iperiod--;
X for(istate = 0; istate < 3; istate++)
X {
X wait_ticks[istate] += (wait_avg[iperiod])[istate];
X }
X }
X
X for(istate = 0; istate < 3; istate++)
X wait_ticks[istate] /= period;
X
X} /* end of get_wait_avg */
X
X/*+-------------------------------------------------------------------------
X extra_static_stuff()/extra_info_stuff() - for 43 line display
X--------------------------------------------------------------------------*/
Xvoid
Xextra_static_stuff()
X{
X display_var(wscr,EXTRA_TLY,EXTRA1_TLX);
X#if defined(HAS_BOOTINFO)
X display_bootinfo(wscr,EXTRA_TLY,EXTRA2_TLX);
X#endif
X display_tune(wscr,EXTRA_TLY,EXTRA3_TLX);
X} /* end of extra_static_stuff */
X
Xvoid
Xextra_info_stuff()
X{
X display_proc(wscr,EXTRA_TLY,EXTRA4_TLX);
X} /* end of extra_info_stuff */
X
X/*+-------------------------------------------------------------------------
X read_sysinfo_and_minfo()
X--------------------------------------------------------------------------*/
Xvoid
Xread_sysinfo_and_minfo()
X{
X#if defined(HAS_TIMEB)
X timeb_last_info_read = timeb_info_read;
X (void)ftime(&timeb_info_read);
X#endif
X kread((caddr_t)&sysinfo,sysinfoaddr,sizeof(sysinfo));
X kread((caddr_t)&minfo,minfoaddr,sizeof(minfo));
X} /* end of read_sysinfo_and_minfo */
X
X/*+-------------------------------------------------------------------------
X main(argc,argv,envp)
X--------------------------------------------------------------------------*/
X/*ARGSUSED*/
Xmain(argc,argv,envp)
Xint argc;
Xchar **argv;
Xchar **envp;
X{
Xregister itmp;
Xregister char *cptr;
Xregister chtype cmd;
Xregister chtype initial_cmd = 0;
Xint errflg = 0;
Xint plock_indicator = 0;
Xtime_t total_ticks;
Xlong stat_period_msec;
Xlong nap_msec;
Xint y,x;
Xint banner_free_x;
Xlong ltmp, now, then;
Xstruct tm *lt;
Xstatic char stdoutbuf[2048];
Xchar s80[80];
Xextern char *optarg;
Xextern int optind;
X
X/*
X * curses works better if standard output is fully buffered
X */
X (void)setvbuf(stdout,stdoutbuf,_IOFBF,sizeof(stdoutbuf));
X
X/*
X * check out command line
X */
X while((itmp = getopt(argc,argv,"lPps")) != -1)
X {
X switch(itmp)
X {
X case 'P':
X case 'p':
X#if defined(M_UNIX)
X case 's':
X#endif
X initial_cmd = (chtype) itmp;
X break;
X case 'l':
X plock_indicator = 1;
X break;
X case '?':
X errflg++;
X }
X }
X if(errflg || (optind != argc))
X {
X static char *usage_str[]=
X {
X "-l lock process into memory (if root)",
X "-p begin with short ps display",
X "-P begin with long ps display (if 43 line screen)",
X (char *)0
X };
X char **cpptr = usage_str;
X fprintf(stderr,"usage: %s [-l] [-p | -P]\n",**argv);
X while(*cpptr)
X (void)fprintf(stderr,"%s\n",*(cpptr++));
X exit(1);
X }
X
X/*
X * if man wants to plock() try it; fail silently if non-root
X */
X if(plock_indicator && plock(PROCLOCK))
X {
X nice(-5);
X plock_indicator = 0;
X }
X
X/*
X * Real(tm) performance monitor users will have done a kernel link
X * and won't need to rely on /etc/systemid
X */
X if(uname(&utsname))
X {
X leave_text("uname failed",255);
X exit(1);
X }
X
X/*
X * allocate memory for cpu time array averaging buckets
X */
X for(itmp = 0; itmp < CPU_AVG_MAX; itmp++)
X {
X if(!(cpu_avg[itmp] = (time_t *)malloc(sizeof(time_t) * 5)))
X leave_text("cannot alloc memory for cpu avg arrays",1);
X }
X
X/*
X * allocate memory for wait time array averaging buckets
X */
X for(itmp = 0; itmp < WAIT_AVG_MAX; itmp++)
X {
X if(!(wait_avg[itmp] = (time_t *)malloc(sizeof(time_t) * 3)))
X leave_text("cannot alloc memory for wait avg arrays",1);
X }
X
X/*
X * initialize curses environment
X */
X if(!initscr())
X {
X (void)printf("curses init failed\n");
X exit(1);
X }
X#if defined(COLOR_PAIR)
X has_colors_kludge();
X#endif
X clear();
X refresh();
X
X if((LINES < 24) || (COLS < 80))
X {
X waddstr(stdscr,"\n\n\nNeed at least 80x24 screen\n\n");
X refresh();
X endwin();
X exit(1);
X }
X
X noecho();
X keypad(stdscr,TRUE);
X typeahead(-1);
X#if !defined(HAS_RDCHK)
X cbreak ();
X#endif
X
X/*
X * see u386mon.h cXXX definitons for A_BOLD requirements for bright colors
X */
X#if defined(COLOR_PAIR)
X if(color_avail)
X {
X start_color();
X init_pair(cpLIT,cBLU,cBLK);
X init_pair(cpINFO,cGRN,cBLK);
X init_pair(cpLOW,cLTG,cBLK);
X init_pair(cpMED,cYEL,cBLK);
X init_pair(cpHIGH,cRED,cBLK);
X init_pair(cpBANNER,cBLK,cWHT);
X init_pair(cpREVERSE,cRED,cWHT);
X init_pair(cpBANWARN,cBLU,cWHT);
X }
X#endif
X
X#if (defined(i386) || defined(i486)) && defined(HI_BIT_CAN_BE_SET)
X /* a hack for now -- assuming AT char set */
X /* This does NOT work with SCO ... rumours are it does work somewhere */
X acs_map['l'] = A_ALTCHARSET | sTL;
X acs_map['m'] = A_ALTCHARSET | sTR;
X acs_map['j'] = A_ALTCHARSET | sBL;
X acs_map['k'] = A_ALTCHARSET | sBR;
X acs_map['x'] = A_ALTCHARSET | sVR; /* vertical rule */
X acs_map['q'] = A_ALTCHARSET | sHR; /* horizontal rule */
X acs_map['t'] = A_ALTCHARSET | sLT; /* left hand T */
X acs_map['u'] = A_ALTCHARSET | sRT; /* right hand T */
X#endif
X
X if(!(pscr = mkpanel(LINES,COLS,0,0,"main")))
X {
X addstr("cannot make screen panel");
X refresh();
X endwin();
X exit(1);
X }
X wscr = panel_window(pscr);
X top_panel(pscr);
X#if !defined(HAS_RDCHK)
X nodelay (wscr, TRUE);
X#endif
X
X/*
X * catch signals that can leave our tty in disarray
X */
X for(itmp = SIGHUP; itmp < SIGSYS; itmp++)
X signal(itmp,caught_signal);
X
X/*
X * read nlist symbols, open /dev/kmem, /dev/mem, /dev/swap,
X * initialize detail environment
X * (all of these must occur after curses init)
X * drop euid and egid (after opening privileged mem/devices)
X * initialize process status uid->name hasher
X */
X nlsym_read();
X kinit(0); /* /dev/kmem, read access only */
X minit(0); /* /dev/mem, read access only */
X sinit(); /* /dev/swap, only read access available */
X (void)setuid(getuid()); /* some people run us setuid, so clen that up */
X (void)setgid(getgid()); /* now that we have the fds open, drop egid */
X kread((caddr_t)&v,vaddr,sizeof(v));
X detail_init();
X
X/*
X * start fireworks
X */
X wmove(wscr,0,0);
X use_cp(wscr,cpBANNER);
X waddch(wscr,(chtype)' ');
X waddstr(wscr,**argv);
X waddch(wscr,(chtype)' ');
X waddstr(wscr,revision);
X
X#if defined(mips)
X waddstr(wscr,"/Tandem");
X#else
X#if defined(M_UNIX)
X waddstr(wscr,"/SCO");
X#else
X#if defined(ISC)
X#if defined(DELL)
X waddstr(wscr,"/Dell");
X#else
X waddstr(wscr,"/ISC");
X#endif
X#endif
X#endif
X#endif
X
X#if defined(DELL)
X wprintw(wscr," Rel %s Ver %s - Node %s ",
X utsname.release,utsname.version,utsname.nodename);
X#else
X#if defined(m68k)
X wprintw(wscr," %s %s - %s ",
X utsname.release,utsname.version,utsname.nodename);
X#else
X /* utsname.release and utsname.version are practcally redundant here */
X wprintw(wscr," %s - %s ",utsname.release,utsname.nodename);
X#endif
X#endif
X getyx(wscr,y,x);
X banner_free_x = x+2;
X while(x < getmaxx(wscr))
X waddch(wscr,(chtype)' '),x++;
X wmove(wscr,0,71);
X waddstr(wscr,"wht at n4hgf");
X if(plock_indicator)
X {
X wmove(wscr,0,banner_free_x);
X use_cp(wscr,cpMED);
X waddstr(wscr," PLOCK ");
X use_cp(wscr,cpBANNER);
X }
X wmove(wscr,3,0);
X use_cp(wscr,cpMED);
X waddstr(wscr,"WAIT");
X pflush();
X
X wmove(wscr,CMD_TLY,0);
X use_cp(wscr,cpBANNER);
X if(LINES >= 43)
X waddstr(wscr," ESC=quit P,p= ps m=main ");
X else
X waddstr(wscr," ESC=quit p=ps e=extra m=main ");
X#if defined(M_UNIX)
X waddstr(wscr," s=sio ");
X#endif
X
X if(getuid() == 0) /* root can launch fireworks very predictably */
X waddstr(wscr," l/u=lock/unlock ");
X waddstr(wscr," +/-=update rate");
X getyx(wscr,y,x);
X while(x < getmaxx(wscr))
X waddch(wscr,(chtype)' '),x++;
X use_cp(wscr,cpLIT);
X
X/*
X * make initial kmem readings
X */
X hz = (cptr = getenv("HZ")) ? atoi(cptr) : HZ;
X kread((caddr_t)&maxmem,maxmemaddr,sizeof(maxmem));
X kread((caddr_t)&tune,tuneaddr,sizeof(tune));
X kread((caddr_t)&v,vaddr,sizeof(v));
X
X kread((caddr_t)&nswap,nswapaddr,sizeof(nswap));
X itmp = -1;
X#if defined(S3BSWPI) /* 68000 handled here, not AT&T 3B */
X itmp = _sysm68k (S3BSWPI,&swapint); /* per nba at sysware.sysware.dk */
X#endif
X#if defined(SI86SWPI)
X itmp = sysi86(SI86SWPI,&swapint);
X#endif
X#if defined(SMIPSSWPI)
X itmp = sysmips(SMIPSSWPI,&swapint);
X#endif
X if(!itmp)
X {
X nswap = 0;
X for (itmp = 0; itmp < MSFILES; itmp++)
X nswap += swaptab[itmp].st_npgs * NBPP / NBPSCTR;
X }
X
X#if defined(HAS_BOOTINFO)
X kread((caddr_t)&bootinfo,bootinfoaddr,sizeof(bootinfo));
X#endif
X
X read_sysinfo_and_minfo();
X sysinfo_last = sysinfo;
X minfo_last = minfo;
X
X#if defined(HAS_TIMEB)
X timeb_last_info_read = timeb_info_read;
X#else
X (void)time (&now);
X#endif
X
X/*
X * initialize static display (literals)
X */
X draw_cpuscale_literals(wscr,CPUSCALE_TLY,0);
X draw_waitscale_literals(wscr,WAITSCALE_TLY,0);
X draw_per_sec_literals(wscr,PER_SEC_TLY,0);
X
X if(LINES >= 43)
X extra_static_stuff();
X
X/*
X * while(user_not_bored) entertain_and_inform_user();
X */
X#ifdef HAS_NAP
X nap(CYCLEmsec);
X#else
X napms(CYCLEmsec);
X#endif
X while(1)
X {
X
X#if defined(HAS_TIMEB)
X ftime(&timeb_cycle_start);
X stat_period_msec = delta_msec(timeb_info_read,timeb_last_info_read);
X (void)time(&now);
X#else
X then = now;
X (void)time(&now);
X stat_period_msec = (now - then) * 1000L;
X#endif
X
X lt = localtime(&now);
X wmove(wscr,0,62);
X use_cp(wscr,cpBANNER);
X wprintw(wscr,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
X
X kread((caddr_t)&freemem,freememaddr,sizeof(freemem));
X read_sysinfo_and_minfo();
X
X /* heuristic validity determination */
X wmove(wscr,0,banner_free_x + 8);
X if((itmp = stat_period_msec > (CYCLEmsec + 3000L)) ||
X (invalidity > INVALID_STATE))
X {
X use_cp(wscr,cpHIGH);
X waddstr(wscr," INVALID ");
X if(itmp)
X { /* gack - a hack */
X itmp = (stat_period_msec - CYCLEmsec) / 1000;
X if(itmp > 4)
X itmp = 4;
X invalidity += INVALID_STATE + itmp;
X }
X }
X else if((itmp = (stat_period_msec > (CYCLEmsec + 1500L))) ||
X (invalidity > INEXACT_STATE))
X {
X use_cp(wscr,cpMED);
X waddstr(wscr," INEXACT ");
X if(itmp)
X invalidity += INEXACT_STATE;
X }
X if(invalidity && !(--invalidity))
X {
X use_cp(wscr,cpBANNER);
X waddstr(wscr," ");
X }
X if(stat_period_msec > (CYCLEmsec + 1000L))
X use_cp(wscr,cpREVERSE);
X else if(stat_period_msec > (CYCLEmsec + 500L))
X use_cp(wscr,cpBANWARN);
X else
X use_cp(wscr,cpBANNER);
X wmove(wscr,stat_period_msec_y,stat_period_msec_x);
X wprintw(wscr,"%5ld",stat_period_msec);
X
X
X#if defined(FIRST_TRY)
X /* going this way seems to get cpu+wait ticks > real time */
X for (itmp = 0; itmp < 5; itmp++)
X cpu_ticks[itmp] = sysidelta(cpu[itmp]);
X for (itmp = 0; itmp < 3; itmp++)
X wait_ticks[itmp] = sysidelta(wait[itmp]);
X#else
X for (itmp = 0; itmp < 5; itmp++)
X {
X if(itmp != CPU_WAIT)
X cpu_ticks[itmp] = sysidelta(cpu[itmp]);
X }
X cpu_ticks[CPU_WAIT] = 0;
X for (itmp = 0; itmp < 3; itmp++)
X cpu_ticks[CPU_WAIT] += (wait_ticks[itmp] = sysidelta(wait[itmp]));
X#endif
X
X total_ticks = update_cpuscale(wscr,CPUSCALE_TLY + 1,CPUSCALE_SX,
X CPUSCALE_WIDTH,cpu_ticks);
X
X update_waitscale(wscr,WAITSCALE_TLY + 1,WAITSCALE_SX,
X WAITSCALE_WIDTH,wait_ticks,total_ticks);
X
X calc_cpu_avg(cpu_ticks);
X calc_wait_avg(wait_ticks);
X
X get_cpu_avg(cpu_ticks,5);
X total_ticks = update_cpuscale(wscr,CPUSCALE_TLY + 2,CPUSCALE_SX,
X CPUSCALE_WIDTH,cpu_ticks);
X
X get_wait_avg(wait_ticks,5);
X update_waitscale(wscr,WAITSCALE_TLY + 2,WAITSCALE_SX,
X WAITSCALE_WIDTH,wait_ticks,total_ticks);
X
X get_cpu_avg(cpu_ticks,10);
X total_ticks = update_cpuscale(wscr,CPUSCALE_TLY + 3,CPUSCALE_SX,
X CPUSCALE_WIDTH,cpu_ticks);
X
X get_wait_avg(wait_ticks,10);
X update_waitscale(wscr,WAITSCALE_TLY + 3,WAITSCALE_SX,
X WAITSCALE_WIDTH,wait_ticks,total_ticks);
X
X use_cp(wscr,cpINFO);
X y = PER_SEC_TLY + 1;
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"bread ","%7ld",sysidelta(bread));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"bwrite ","%7ld",sysidelta(bwrite));
X wmove(wscr,y++,PER_SEC1_TLX);
X if((ltmp = sysidelta(lread) - myreadcnt) < 0)
X ltmp = 0;
X disp_info_long(wscr,"lread ","%7ld",ltmp);
X myreadcnt = 0; /* reset /dev/{mem,kmem,swap} read count */
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"lwrite ","%7ld",sysidelta(lwrite));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"phread ","%7ld",sysidelta(phread));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"phwrite ","%7ld",sysidelta(phwrite));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"swapin ","%7ld",sysidelta(swapin));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"swapout ","%7ld",sysidelta(swapout));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"bswapin ","%7ld",sysidelta(bswapin));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"bswapout ","%7ld",sysidelta(bswapout));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"iget ","%7ld",sysidelta(iget));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"namei ","%7ld",sysidelta(namei));
X wmove(wscr,y++,PER_SEC1_TLX);
X disp_info_long(wscr,"dirblk ","%7ld",sysidelta(dirblk));
X
X y = PER_SEC_TLY + 1;
X wmove(wscr,y++,PER_SEC2_TLX);
X if((ltmp = sysidelta(readch) - myreadlen) < 0)
X ltmp = 0;
X disp_info_long(wscr,"readch ","%7ld",ltmp);
X myreadlen = 0; /* reset /dev/{mem,kmem,swap} read count */
X
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"writch ","%7ld",sysidelta(writech));
X
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"rawch ","%7ld",sysidelta(rawch));
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"canch ","%7ld",sysidelta(canch));
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"outch ","%7ld",sysidelta(outch));
X
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"msg ","%7ld",sysidelta(msg));
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr,"sema ","%7ld",sysidelta(sema));
X
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_static_long(wscr, "maxmem ","%6ldk",(long)maxmem * NBPP / 1024);
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr, "frmem ","%6ldk",(long)freemem * NBPP / 1024);
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_int (wscr, "mem used","%6d%%",
X 100 - (int)((freemem * 100) / maxmem));
X
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_static_int(wscr, "nswap ","%6ldk",nswap * NBPSCTR / 1024);
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_long(wscr, "frswp ","%6ldk",minfo.freeswap* NBPSCTR/1024);
X wmove(wscr,y++,PER_SEC2_TLX);
X disp_info_int(wscr, "swp used","%6d%%",
X 100 - (int)((minfo.freeswap * 100) / nswap));
X
X y = PER_SEC_TLY + 1;
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"pswitch ","%5ld",sysidelta(pswitch));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"syscall ","%5ld",sysidelta(syscall));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"sysread ","%5ld",sysidelta(sysread));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"syswrit ","%5ld",sysidelta(syswrite));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"sysfork ","%5ld",sysidelta(sysfork));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"sysexec ","%5ld",sysidelta(sysexec));
X
X y++;
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"runque ","%5ld",sysidelta(runque));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"runocc ","%5ld",sysidelta(runocc));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"swpque ","%5ld",sysidelta(swpque));
X wmove(wscr,y++,PER_SEC3_TLX);
X disp_info_long(wscr,"swpocc ","%5ld",sysidelta(swpocc));
X
X y = PER_SEC_TLY + 1;
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"vfault ","%3ld",midelta(vfault));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"demand ","%3ld",midelta(demand));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"pfault ","%3ld",midelta(pfault));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"cw ","%3ld",midelta(cw));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"steal ","%3ld",midelta(steal));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"frdpgs ","%3ld",midelta(freedpgs));
X#if defined(SVR32)
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"vfpg ","%3ld",midelta(vfpg));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"sfpg ","%3ld",midelta(sfpg));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"vspg ","%3ld",midelta(vspg));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"sspg ","%3ld",midelta(sspg));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"pnpfault","%3ld",sysidelta(pnpfault));
X wmove(wscr,y++,PER_SEC4_TLX);
X disp_info_long(wscr,"wrtfault","%3ld",sysidelta(wrtfault));
X#endif
X
X y = PER_SEC_TLY + 1;
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"unmodsw ","%3ld",midelta(unmodsw));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"unmodfl ","%3ld",midelta(unmodfl));
X#if defined(SVR32)
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"psoutok ","%3ld",midelta(psoutok));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"psinfai ","%3ld",midelta(psinfail));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"psinok ","%3ld",midelta(psinok));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"rsout ","%3ld",midelta(rsout));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"rsin ","%3ld",midelta(rsin));
X#endif
X
X y++;
X wmove(wscr,y++,PER_SEC5_TLX);
X use_cp(wscr,cpLIT);
X waddstr(wscr,"pages on ");
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"swap ","%5ld",midelta(swap));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"cache ","%5ld",midelta(cache));
X wmove(wscr,y++,PER_SEC5_TLX);
X disp_info_long(wscr,"file ","%5ld",midelta(file));
X
X if(LINES >= 43)
X extra_info_stuff();
X
X detail_panel_update();
X
X if(initial_cmd)
X {
X detail_panel_cmd(initial_cmd);
X initial_cmd = 0;
X }
X
X pflush();
X
X cmd = 0;
X#if defined(HAS_RDCHK)
X while(rdchk(0))
X#endif
X {
X switch(cmd = wgetch(wscr))
X {
X case 'L' & 0x1F: /* ^L */
X case 'R' & 0x1F: /* ^R */
X clearok (wscr, TRUE);
X touchwin(wscr);
X wrefresh(wscr);
X if(wdet)
X {
X touchwin(wdet);
X wrefresh(wscr);
X }
X break;
X
X case 'q':
X case A_ESC:
X goto GOOD_BYE;
X#if defined(M_UNIX)
X case 'b':
X if(bootinfo.bootstrlen > 79)
X itmp = 79;
X else
X itmp = bootinfo.bootstrlen;
X kread(s80,bootinfoaddr +
X (bootinfo.bootstr - (caddr_t)&bootinfo),itmp);
X s80[itmp] = 0;
X disp_msg(cpMED,s80);
X break;
X#endif
X case 'e':
X case 'P':
X case 'p':
X case 'm':
X#if defined(M_UNIX)
X case 's':
X#endif
X detail_panel_cmd(cmd);
X break;
X case 'l':
X if(!plock_indicator)
X {
X if(!plock(PROCLOCK))
X {
X plock_indicator = 1;
X wmove(wscr,0,banner_free_x);
X use_cp(wscr,cpMED);
X waddstr(wscr," PLOCK ");
X nice(-5);
X }
X }
X break;
X case 'u':
X if(plock_indicator)
X {
X if(!plock(UNLOCK))
X {
X plock_indicator = 0;
X wmove(wscr,0,banner_free_x);
X use_cp(wscr,cpBANNER);
X waddstr(wscr," ");
X nice(5);
X }
X }
X break;
X case '+':
X if(CYCLEmsec < CYCLEmsecMax)
X {
X invalidity += (INEXACT_STATE * (CYCLEmsec + 1000L)) /
X CYCLEmsec;
X CYCLEmsec += 1000L;
X draw_cpuscale_literals(wscr,CPUSCALE_TLY,0);
X draw_waitscale_literals(wscr,WAITSCALE_TLY,0);
X }
X else beep();
X break;
X case '-':
X if(CYCLEmsec > 1000L)
X {
X CYCLEmsec -= 1000L;
X draw_cpuscale_literals(wscr,CPUSCALE_TLY,0);
X draw_waitscale_literals(wscr,WAITSCALE_TLY,0);
X }
X else beep();
X break;
X case 0:
X case -1:
X break;
X default:
X beep();
X break;
X }
X }
X
X /* remember previous statistics for next delta */
X sysinfo_last = sysinfo;
X minfo_last = minfo;
X
X /* ex-lax: all in the name of regularity */
X#if defined(HAS_TIMEB)
X ftime(&timeb_cycle_end);
X nap_msec = CYCLEmsec - delta_msec(timeb_cycle_end,timeb_cycle_start);
X if(nap_msec < (CYCLEmsec - 300L))
X nap_msec = (CYCLEmsec - 300L);
X#else
X nap_msec = (CYCLEmsec - 300L);
X#endif
X#ifdef HAS_NAP
X (void)nap(nap_msec);
X#else
X napms(nap_msec); /* curses call: most round UP to nearest second */
X#endif
X }
X
XGOOD_BYE:
X leave_text("",0);
X /*NOTREACHED*/
X} /* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of u386mon.c */
SHAR_EOF
$TOUCH -am 0810142390 u386mon.c &&
chmod 0644 u386mon.c ||
echo "restore of u386mon.c failed"
Wc_c="`wc -c < u386mon.c`"
test 37979 -eq "$Wc_c" ||
echo u386mon.c: original size 37979, current size $Wc_c
# ============= var.c ==============
echo "x - extracting var.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > var.c &&
X/*+-------------------------------------------------------------------------
X var.c - u386mon var struct display
X
X Defined functions:
X display_var(win,y,x)
X
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:13-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-17:33-wht at n4hgf-alpha sort identifiers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:27-r at n4hgf-version x0.12 seems bug free */
X/*:06-17-1990-14:59-wht-creation */
X
X#include "config.h"
X#define M_TERMINFO
X#include <curses.h>
X#undef reg /* per nba at sysware.sysware.dk */
X#ifdef NATIVE_PANELS
X# include <panel.h>
X#else
X# include "libpanel.h"
X#endif
X#include <sys/types.h>
X#include <sys/var.h>
X#include "u386mon.h"
X
X/*+-------------------------------------------------------------------------
X display_var(win,y,x)
X--------------------------------------------------------------------------*/
Xvoid
Xdisplay_var(win,y,x)
XWINDOW *win;
Xint y;
Xint x;
X{
X use_cp(win,cpBANNER);
X wmove(win,y++,x);
X waddstr(win,"-- Var ---------");
X wmove(win,y++,x);
X disp_static_int(win,"v_autoup ","%5d",v.v_autoup);
X wmove(win,y++,x);
X disp_static_int(win,"v_buf ","%5d",v.v_buf);
X wmove(win,y++,x);
X disp_static_int(win,"v_clist ","%5d",v.v_clist);
X wmove(win,y++,x);
X disp_static_int(win,"v_file ","%5d",v.v_file);
X wmove(win,y++,x);
X disp_static_int(win,"v_hbuf ","%5d",v.v_hbuf);
X wmove(win,y++,x);
X disp_static_int(win,"v_inode ","%5d",v.v_inode);
X wmove(win,y++,x);
X disp_static_int(win,"v_maxpmem ","%5d",v.v_maxpmem);
X wmove(win,y++,x);
X disp_static_int(win,"v_maxup ","%5d",v.v_maxup);
X wmove(win,y++,x);
X disp_static_int(win,"v_mount ","%5d",v.v_mount);
X wmove(win,y++,x);
X disp_static_int(win,"v_pbuf ","%5d",v.v_pbuf);
X wmove(win,y++,x);
X disp_static_int(win,"v_proc ","%5d",v.v_proc);
X wmove(win,y++,x);
X disp_static_int(win,"v_region ","%5d",v.v_region);
X wmove(win,y++,x);
X disp_static_int(win,"v_vhndfrac ","%5d",v.v_vhndfrac);
X
X} /* end of display_var */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of var.c */
SHAR_EOF
$TOUCH -am 0810141890 var.c &&
chmod 0644 var.c ||
echo "restore of var.c failed"
Wc_c="`wc -c < var.c`"
test 2469 -eq "$Wc_c" ||
echo var.c: original size 2469, current size $Wc_c
# ============= config.h ==============
echo "x - extracting config.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > config.h &&
X/*+-------------------------------------------------------------------------
X config.h - u386mon system monitor configuration
X
XHopefully, we will hide most of the Machiavellian version-hackery
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:35-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:08-01-1990-19:24-jdc at dell.com-add DELL config */
X/*:08-01-1990-12:24-wht at n4hgf-2.11-try to support ISC 1.x.x */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:07-26-1990-17:51-wht-creation */
X
X#define U386MON
X
X#if defined(M_UNIX)
X#define HAS_RDCHK
X#define HAS_NAP
X#if !defined(SVR32)
X#define SVR32
X#endif
X/* The next two lines may speed up other True S5R3 versions, but I can't say */
X#define PERFORMANCE /* see u386mon.c, kludge.c, /usr/include/tinfo.h */
X#define CURSES_MACROS
X#endif
X
X#if defined(DELL)
X#define ISC
X#if !defined(SVR32)
X#define SVR32
X#endif
X#endif
X
X#ifdef ISC_1
X#define ISC
X#if !defined(SVR31)
X#define SVR31
X#endif
X#ifndef NO_ISTOUCH
X#define NO_ISTOUCH
X#endif
X#else /* !ISC 1.x.x */
X#if defined(ISC)
X#define HAS_RDCHK
X#define HAS_NAP
X#if !defined(SVR32)
X#define SVR32
X#endif
X#endif
X#endif
X
X#if defined(SVR32)
X#define NATIVE_PANELS
X#define HAS_BOOTINFO
X#define HAS_TIMEB
X#endif
X
X/*
X * some old curses do not have is_wintouched() or is_linetouched()
X * ... sigh ... This makes our homebrew panel object severely
X * disappointed, maybe useless ... but define NO_ISTOUCH to try
X * it if you get undefined externs for these two work saver functions.
X */
X#ifdef SVR31
X#ifndef NO_ISTOUCH
X/* #define NO_ISTOUCH */
X#endif
X#endif
X
X#if defined(mips)
X#if !defined(SVR31)
X#define SVR31
X#endif
X#if !defined(NO_ISTOUCH)
X#define NO_ISTOUCH
X#endif
X#endif
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of config.h */
SHAR_EOF
$TOUCH -am 0810141890 config.h &&
chmod 0644 config.h ||
echo "restore of config.h failed"
Wc_c="`wc -c < config.h`"
test 1925 -eq "$Wc_c" ||
echo config.h: original size 1925, current size $Wc_c
# ============= libkmem.h ==============
echo "x - extracting libkmem.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > libkmem.h &&
X/*+-----------------------------------------------------------------------
X libkmem.h
X ...!{gatech,emory}!n4hgf!wht
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:26-r at n4hgf-version x0.12 seems bug free */
X/*:10-28-1988-14:46-afterlint-creation */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* libkmem.c */
Xvoid kinit(int );
Xvoid kread(char *,long ,int );
Xvoid kwrite(long ,char *,int );
X
X#else /* compiler doesn't know about prototyping */
X
X/* libkmem.c */
Xvoid kinit();
Xvoid kread();
Xvoid kwrite();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of libkmem.h */
SHAR_EOF
$TOUCH -am 0810141890 libkmem.h &&
chmod 0644 libkmem.h ||
echo "restore of libkmem.h failed"
Wc_c="`wc -c < libkmem.h`"
test 1133 -eq "$Wc_c" ||
echo libkmem.h: original size 1133, current size $Wc_c
# ============= libmem.h ==============
echo "x - extracting libmem.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > libmem.h &&
X/*+-----------------------------------------------------------------------
X libmem.h
X ...!{gatech,emory}!n4hgf!wht
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:26-r at n4hgf-version x0.12 seems bug free */
X/*:10-28-1988-14:46-afterlint-creation */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* libmem.c */
Xvoid minit(int );
Xvoid mread(char *,long ,int );
Xvoid mwrite(long ,char *,int );
X
X#else /* compiler doesn't mnow about prototyping */
X
X/* libmem.c */
Xvoid minit();
Xvoid mread();
Xvoid mwrite();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of libmem.h */
SHAR_EOF
$TOUCH -am 0810141890 libmem.h &&
chmod 0644 libmem.h ||
echo "restore of libmem.h failed"
Wc_c="`wc -c < libmem.h`"
test 1129 -eq "$Wc_c" ||
echo libmem.h: original size 1129, current size $Wc_c
# ============= libpanel.h ==============
echo "x - extracting libpanel.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > libpanel.h &&
X
X/*+-------------------------------------------------------------------------
X libpanel.h - libpanel.c <panel.h> surrogate
X wht at n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-31-1990-08:18-wht at n4hgf-some cpps wont take #error even in untrue ifdef */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:07-23-1990-00:56-wht at n4hgf-full library working */
X/*:07-21-1990-15:42-wht-creation */
X
X#ifdef NATIVE_PANELS
X# include <panel.h>
X#else
X
Xtypedef struct panelobs
X{
X struct panelobs *above;
X struct panel *pan;
X} PANELOBS;
X
Xtypedef struct panel
X{
X WINDOW *win;
X int wstarty;
X int wendy;
X int wstartx;
X int wendx;
X struct panel *below;
X struct panel *above;
X char *user;
X struct panelobs *obscure;
X} PANEL;
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
Xextern WINDOW *panel_window(PANEL *pan);
Xextern void update_panels(void );
Xextern int hide_panel(PANEL *pan);
Xextern int show_panel(PANEL *pan);
Xextern int del_panel(PANEL *pan);
Xextern int top_panel(PANEL *pan);
Xextern int bottom_panel(PANEL *pan);
Xextern PANEL *new_panel(WINDOW *win);
Xextern PANEL *panel_above(PANEL *pan);
Xextern PANEL *panel_below(PANEL *pan);
Xextern int set_panel_userptr(PANEL *pan,char *uptr);
Xextern char *panel_userptr(PANEL *pan);
Xextern int move_panel(PANEL *pan,int starty,int startx);
Xextern int replace_panel(PANEL *pan,WINDOW *win);
X
X#else /* compiler doesn't know about prototyping */
X
Xextern WINDOW *panel_window();
Xextern void update_panels();
Xextern int hide_panel();
Xextern int show_panel();
Xextern int del_panel();
Xextern int top_panel();
Xextern int bottom_panel();
Xextern PANEL *new_panel();
Xextern PANEL *panel_above();
Xextern PANEL *panel_below();
Xextern int set_panel_userptr();
Xextern char *panel_userptr();
Xextern int move_panel();
Xextern int replace_panel();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X#endif /* NATIVE_PANELS */
X
X/* end of function declarations */
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of libpanel.h */
SHAR_EOF
$TOUCH -am 0810141890 libpanel.h &&
chmod 0644 libpanel.h ||
echo "restore of libpanel.h failed"
Wc_c="`wc -c < libpanel.h`"
test 2253 -eq "$Wc_c" ||
echo libpanel.h: original size 2253, current size $Wc_c
# ============= libswap.h ==============
echo "x - extracting libswap.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > libswap.h &&
X/*+-----------------------------------------------------------------------
X libswap.h
X ...!{gatech,emory}!n4hgf!wht
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-22-1990-02:03-root at n4hgf-creation from libmem */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* libswap.c */
Xvoid sinit(void );
Xvoid sread(char *,long ,int );
X
X#else /* compiler doesn't mnow about prototyping */
X
X/* libswap.c */
Xvoid sinit();
Xvoid sread();
Xvoid swrite();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of libswap.h */
SHAR_EOF
$TOUCH -am 0810141890 libswap.h &&
chmod 0644 libswap.h ||
echo "restore of libswap.h failed"
Wc_c="`wc -c < libswap.h`"
test 1054 -eq "$Wc_c" ||
echo libswap.h: original size 1054, current size $Wc_c
# ============= libnlsym.h ==============
echo "x - extracting libnlsym.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > libnlsym.h &&
X/*+-----------------------------------------------------------------------
X libnlsym.h
X ...!{gatech,emory}!n4hgf!wht
X------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:08-10-1990-14:12-jmd at p1so/wht at n4hgf-2.20-add Tandem Integrity S2 */
X/*:08-07-1990-14:24-wht at n4hgf-nba@sysware.sysware.dk S5R31 updates */
X/*:08-02-1990-15:36-wht at n4hgf-2.12-old curses hacks+minor 3.2 formalizations */
X/*:07-28-1990-18:06-wht at n4hgf-2.10 release */
X/*:06-27-1990-01:57-wht at n4hgf-1.10-incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht at n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht at n4hgf-v1.01-add ISC support thanks to peter at radig.de */
X/*:06-21-1990-14:26-r at n4hgf-version x0.12 seems bug free */
X/*:10-28-1988-14:47-afterlint-creation */
X
X#ifndef BUILDING_LINT_ARGS
X#ifdef LINT_ARGS
X
X/* libnlsym.c */
Xvoid nlsym_error(char * );
Xvoid nlsym_read(void);
X
X#else /* compiler doesn't know about prototyping */
X
X/* libnlsym.c */
Xvoid nlsym_error();
Xvoid nlsym_read();
X
X#endif /* LINT_ARGS */
X#endif /* BUILDING_LINT_ARGS */
X
X/* end of libnlsym.h */
SHAR_EOF
$TOUCH -am 0810141890 libnlsym.h &&
chmod 0644 libnlsym.h ||
echo "restore of libnlsym.h failed"
Wc_c="`wc -c < libnlsym.h`"
test 1100 -eq "$Wc_c" ||
echo libnlsym.h: original size 1100, current size $Wc_c
true || echo "restore of libnlsym.h failed"
echo "End of part 5, continue with part 6"
exit 0
More information about the Comp.sources.misc
mailing list