(FILECREATED "18-Aug-85 16:09:25" {ERIS}<LISPUSERS>SYSTAT.;11 23176  

      changes to:  (FNS SYSTAT.↑T)

      previous date: "19-Jun-85 14:02:35" {ERIS}<LISPUSERS>SYSTAT.;10)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT SYSTATCOMS)

(RPAQQ SYSTATCOMS ((* SYSTAT -- By Kelly Roach *)
	(DECLARE: EVAL@COMPILE DONTCOPY (RECORDS MISCSTATS SPACEDATA SYSTATBLOCK))
	(RECORDS SYSTATENTRY)
	(CONSTANTS (LIGHTGRAYSHADE 1))
	(FNS SYSTAT.PROCESS SYSTAT.MSECSWAIT SYSTAT.QUICKLY SYSTAT.SLOWLY SYSTAT.BITBLT.EVAL 
	     SYSTAT.BITBLT.GETTOPVAL SYSTAT.PRINT.EVAL SYSTAT.PRINT.GETTOPVAL SYSTAT.WINDOW 
	     SYSTAT.CREATEW SYSTAT.CLEARW SYSTAT.SHADEW SYSTAT.REPAINTFN SYSTAT.COMPUTE.BLOCK 
	     SYSTAT.PRINT.KEYS SYSTAT.UPDATE SYSTAT.UPDATE.SYSTATENTRY SYSTAT.BUTTONEVENTFN 
	     SYSTAT.MIDDLEBUTTONFN SYSTAT.REACTIVATE SYSTAT.DEACTIVATE SYSTAT.↑T)
	(INITVARS (\LASTVMEMFILEPAGE 16383)
		  (SYSTAT.QUICKLYMSECSWAIT 1000)
		  (SYSTAT.SLOWLYMSECSWAIT 10000)
		  (SYSTAT.QUICKLYFLG T)
		  (SYSTAT.DEFAULT.ENTRYS (LIST (SYSTAT.PRINT.GETTOPVAL "USERNAME" 'USERNAME)
					       (SYSTAT.PRINT.EVAL "DIRECTORYNAME"
								  '(DIRECTORYNAME T))
					       (SYSTAT.PRINT.GETTOPVAL "PROCESS" 'SYSTAT.PROCESS)
					       (SYSTAT.PRINT.GETTOPVAL "STATE" 'SYSTAT.STATE)
					       (SYSTAT.PRINT.GETTOPVAL "STACK FRAME" 'SYSTAT.FRAME)
					       (SYSTAT.BITBLT.GETTOPVAL "%% UTIL" 'SYSTAT.UTIL)
					       (SYSTAT.BITBLT.GETTOPVAL "%% NET IO" 'SYSTAT.NETIO)
					       (SYSTAT.BITBLT.GETTOPVAL "%% GC" 'SYSTAT.GC)
					       (SYSTAT.BITBLT.GETTOPVAL "%% KEYBOARD" '
									SYSTAT.KEYBOARD)
					       (SYSTAT.BITBLT.GETTOPVAL "%% SWAP" 'SYSTAT.SWAP)
					       (SYSTAT.PRINT.EVAL "OPEN FILES"
								  '(FLENGTH (OPENP)))
					       (SYSTAT.BITBLT.GETTOPVAL "MDS SPACE" 'SYSTAT.MDSFRAC)
					       (SYSTAT.BITBLT.GETTOPVAL "ATOM SPACE" 'SYSTAT.ATOMFRAC)
					       (SYSTAT.BITBLT.EVAL "PNAME SPACE"
								   '(FQUOTIENT (ADD1 \CurPnPage)
									       \LastPnPage))
					       (SYSTAT.BITBLT.EVAL "VMEM SPACE"
								   '(FQUOTIENT (VMEMSIZE)
									       \LASTVMEMFILEPAGE))))
		  (SYSTAT.DEFAULT.FORMS '((SYSTAT.↑T)))
		  (SYSTAT.WINDOW NIL)
		  (SYSTAT.MENU (create MENU ITEMS ← '((Quickly 'SYSTAT.QUICKLY "Run SYSTAT quickly")
					(Slowly 'SYSTAT.SLOWLY "Run SYSTAT slowly")
					(Update 'SYSTAT.UPDATE "Update window")
					(Deactivate 'SYSTAT.DEACTIVATE "Cease updating window")
					(Reactivate 'SYSTAT.REACTIVATE "Resume updating window"))
				       CHANGEOFFSETFLG ← T WHENHELDFN ← 'PPROMPT3))
		  (SYSTAT.RESTARTABLE T)
		  (SYSTAT.TIMEBOX (CLOCK 0))
		  (SYSTAT.KEYBOARDTIME 0)
		  (SYSTAT.KEYBOARDWAITTIME 0)
		  (SYSTAT.NETIOTIME 0)
		  (SYSTAT.GCTIME 0)
		  (SYSTAT.SWAPTIME 0)
		  (SYSTAT.UTIL 0)
		  (SYSTAT.SWAP 0)
		  (SYSTAT.NETIO 0)
		  (SYSTAT.GC 0)
		  (SYSTAT.KEYBOARD 0)
		  (SYSTAT.FRAME NIL)
		  (SYSTAT.PROCESS NIL)
		  (SYSTAT.STATE NIL))
	(P (* Redefine interrupt channel for ↑T *)
	   (MOVD? 'CONTROL-T 'OLDCONTROL-T)
	   (MOVD 'SYSTAT.WINDOW 'CONTROL-T))))



(* SYSTAT -- By Kelly Roach *)

(DECLARE: EVAL@COMPILE DONTCOPY 
[DECLARE: EVAL@COMPILE 

(BLOCKRECORD MISCSTATS ((STARTTIME FIXP)
			(TOTALTIME FIXP)
			(SWAPWAITTIME FIXP)
			(PAGEFAULTS FIXP)
			(SWAPWRITES FIXP)
			(DISKIOTIME FIXP)
			(DISKOPS FIXP)
			(KEYBOARDWAITTIME FIXP)
			(GCTIME FIXP)
			(NETIOTIME FIXP)
			(NETIOOPS FIXP)
			(SWAPTEMP0 FIXP)
			(SWAPTEMP1 FIXP)
			(RCLKSECOND FIXP)
			(SECONDSCLOCK FIXP)
			(MILLISECONDSCLOCK FIXP)
			(BASECLOCK FIXP)
			(RCLKTEMP0 FIXP)
			(SECONDSTMP FIXP)
			(MILLISECONDSTMP FIXP)
			(BASETMP FIXP)
			(EXCESSTIMETMP FIXP)
			(CLOCKTEMP0 FIXP)
			(DISKTEMP0 FIXP)
			(DISKTEMP1 FIXP)
			(TELERAIDTEMP1 FIXP)
			(TELERAIDTEMP2 FIXP)
			(TELERAIDTEMP3 FIXP)
			(LASTUSERACTION FIXP)
			(DLMOUSETIMER FIXP)
			(DLMOUSETEMP FIXP))
		       (CREATE (\ALLOCBLOCK 31)))

(RECORD SPACEDATA (MDSFREE MDSFRAC 8MBFRAC ATOMSFREE ATOMFRAC))

(RECORD SYSTATBLOCK (TAB FONTHEIGHT FONTASCENT FONTDESCENT GRAY WINDOWHEIGHT WINDOWWIDTH))
]
)
[DECLARE: EVAL@COMPILE 

(RECORD SYSTATENTRY (KEY MODE FETCHFN USERDATA)
		    (TYPE? (AND (IEQP (LENGTH DATUM)
				      4)
				(MEMB (SYSTATENTRY.MODE DATUM)
				      '(BITBLT PRINT)))))
]
(DECLARE: EVAL@COMPILE 

(RPAQQ LIGHTGRAYSHADE 1)

(CONSTANTS (LIGHTGRAYSHADE 1))
)
(DEFINEQ

(SYSTAT.PROCESS
  (LAMBDA NIL                                                (* kbr: "28-Jul-84 14:10")
    (PROG (MSECSWAIT)
          (DO (SYSTAT.UPDATE SYSTAT.WINDOW)
	      (SETQ MSECSWAIT (SYSTAT.MSECSWAIT))
	      (COND
		((EQ (BLOCK MSECSWAIT)
		     'RETURN)
		  (RETURN)))))))

(SYSTAT.MSECSWAIT
  (LAMBDA NIL                                                (* kbr: "28-Jul-84 14:10")
    (COND
      (SYSTAT.QUICKLYFLG SYSTAT.QUICKLYMSECSWAIT)
      (T SYSTAT.SLOWLYMSECSWAIT))))

(SYSTAT.QUICKLY
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG NIL
          (SETQ SYSTAT.QUICKLYFLG T)
          (SYSTAT.REACTIVATE WINDOW))))

(SYSTAT.SLOWLY
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG NIL
          (SETQ SYSTAT.QUICKLYFLG NIL)
          (SYSTAT.REACTIVATE WINDOW))))

(SYSTAT.BITBLT.EVAL
  (LAMBDA (KEY USERDATA)                                     (* kbr: "28-Jul-84 14:10")
    (CREATE SYSTATENTRY
	    KEY ← KEY
	    MODE ← 'BITBLT
	    FETCHFN ← (FUNCTION EVAL)
	    USERDATA ← USERDATA)))

(SYSTAT.BITBLT.GETTOPVAL
  (LAMBDA (KEY USERDATA)                                     (* kbr: "28-Jul-84 14:10")
    (CREATE SYSTATENTRY
	    KEY ← KEY
	    MODE ← 'BITBLT
	    FETCHFN ← (FUNCTION GETTOPVAL)
	    USERDATA ← USERDATA)))

(SYSTAT.PRINT.EVAL
  (LAMBDA (KEY USERDATA)                                     (* kbr: "28-Jul-84 14:10")
    (CREATE SYSTATENTRY
	    KEY ← KEY
	    MODE ← 'PRINT
	    FETCHFN ← (FUNCTION EVAL)
	    USERDATA ← USERDATA)))

(SYSTAT.PRINT.GETTOPVAL
  (LAMBDA (KEY USERDATA)                                     (* kbr: "28-Jul-84 14:10")
    (CREATE SYSTATENTRY
	    KEY ← KEY
	    MODE ← 'PRINT
	    FETCHFN ← (FUNCTION GETTOPVAL)
	    USERDATA ← USERDATA)))

(SYSTAT.WINDOW
  (LAMBDA (POSITION FONT)                                    (* kbr: "28-Jul-84 14:10")
    (PROG NIL
          (COND
	    ((NULL FONT)
	      (SETQ FONT (FONTCREATE 'GACHA 8))))
          (COND
	    ((NULL SYSTAT.WINDOW)
	      (SETQ SYSTAT.WINDOW (SYSTAT.CREATEW SYSTAT.DEFAULT.ENTRYS SYSTAT.DEFAULT.FORMS POSITION 
						  FONT)))
	    (T (SYSTAT.REACTIVATE SYSTAT.WINDOW)))
          (RETURN SYSTAT.WINDOW))))

(SYSTAT.CREATEW
  (LAMBDA (ENTRYS FORMS POSITION FONT)                       (* kbr: "28-Jul-84 14:10")
    (PROG (SYSTATBLOCK HEIGHT WIDTH REGION WINDOW)
          (FOR SYSTATENTRY IN ENTRYS WHEN (NOT (TYPE? SYSTATENTRY SYSTATENTRY))
	     DO (ERROR "ARG NOT SYSTATENTRY" SYSTATENTRY))
          (SETQ SYSTATBLOCK (SYSTAT.COMPUTE.BLOCK ENTRYS FONT NIL NIL))
                                                             (* Create WINDOW *)
          (SETQ HEIGHT (fetch (SYSTATBLOCK WINDOWHEIGHT) of SYSTATBLOCK))
          (SETQ WIDTH (fetch (SYSTATBLOCK WINDOWWIDTH) of SYSTATBLOCK))
          (COND
	    ((NULL POSITION)
	      (SETQ POSITION (GETBOXPOSITION WIDTH HEIGHT NIL NIL NIL "Position SYSTAT.WINDOW"))))
          (SETQ REGION (CREATE REGION
			       LEFT ← (fetch (POSITION XCOORD) of POSITION)
			       BOTTOM ← (fetch (POSITION YCOORD) of POSITION)
			       HEIGHT ← HEIGHT
			       WIDTH ← WIDTH))
          (SETQ WINDOW (CREATEW REGION))                     (* WINDOW properties *)
          (DSPFONT FONT WINDOW)
          (DSPRIGHTMARGIN MAX.SMALLP WINDOW)
          (WINDOWPROP WINDOW 'SYSTAT.BLOCK SYSTATBLOCK)
          (WINDOWPROP WINDOW 'SYSTAT.ENTRYS ENTRYS)
          (WINDOWPROP WINDOW 'SYSTAT.FORMS FORMS)
          (WINDOWPROP WINDOW 'CLOSEFN 'SYSTAT.DEACTIVATE)
          (WINDOWPROP WINDOW 'BUTTONEVENTFN 'SYSTAT.BUTTONEVENTFN)
          (WINDOWPROP WINDOW 'REPAINTFN 'SYSTAT.REPAINTFN)
          (SYSTAT.REPAINTFN WINDOW)
          (SYSTAT.REACTIVATE WINDOW)
          (RETURN WINDOW))))

(SYSTAT.CLEARW
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG (SYSTATBLOCK)                                      (* Can%'t use CLEARW inside a REPAINTFN%, must use 
							     DSPFILL *)
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW 'SYSTAT.BLOCK))
          (DSPFILL NIL WHITESHADE 'REPLACE WINDOW)
          (replace (SYSTATBLOCK GRAY) of SYSTATBLOCK with NIL))))

(SYSTAT.SHADEW
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
                                                             (* Shade or unshade window *)
    (PROG (SYSTATBLOCK)
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW 'SYSTAT.BLOCK))
          (DSPFILL NIL LIGHTGRAYSHADE 'INVERT WINDOW)
          (replace (SYSTATBLOCK GRAY) of SYSTATBLOCK with (NOT (fetch (SYSTATBLOCK GRAY)
								  of SYSTATBLOCK))))))

(SYSTAT.REPAINTFN
  (LAMBDA (WINDOW REGION)                                    (* kbr: "28-Jul-84 14:10")
                                                             (* Called by the window package to Redisplay WINDOW *)
    (PROG NIL
          (SYSTAT.CLEARW WINDOW)
          (SYSTAT.PRINT.KEYS WINDOW)
          (SYSTAT.UPDATE WINDOW))))

(SYSTAT.COMPUTE.BLOCK
  (LAMBDA (ENTRYS FONT TITLE BORDER)                         (* kbr: "28-Jul-84 14:10")
                                                             (* Use windowprops of WINDOW to calc new SYSTATBLOCK of 
							     WINDOW *)

          (* The point of the SYSTATBLOCK is to have already packaged some of the numbers SYSTAT.UPDATE would otherwise have
	  to waste time in computing *)


    (PROG (FONTHEIGHT FONTASCENT FONTDESCENT SYSTATBLOCK TAB HEIGHT WIDTH)
          (SETQ FONTHEIGHT (FONTPROP FONT 'HEIGHT))
          (SETQ FONTASCENT (FONTPROP FONT 'ASCENT))
          (SETQ FONTDESCENT (FONTPROP FONT 'DESCENT))
          (SETQ TAB (IPLUS (APPLY (FUNCTION IMAX)
				  (FOR SYSTATENTRY IN ENTRYS COLLECT (STRINGWIDTH
								       (fetch (SYSTATENTRY KEY)
									  of SYSTATENTRY)
								       FONT)))
			   (STRINGWIDTH "AAAAA" FONT)))
          (SETQ HEIGHT (HEIGHTIFWINDOW (ITIMES FONTHEIGHT (LENGTH ENTRYS))
				       TITLE BORDER))
          (SETQ WIDTH (WIDTHIFWINDOW (ITIMES 2 TAB)
				     BORDER))
          (SETQ SYSTATBLOCK
	    (CREATE SYSTATBLOCK
		    TAB ← TAB
		    FONTHEIGHT ← FONTHEIGHT
		    FONTASCENT ← FONTASCENT
		    FONTDESCENT ← FONTDESCENT
		    WINDOWHEIGHT ← HEIGHT
		    WINDOWWIDTH ← WIDTH))
          (RETURN SYSTATBLOCK))))

(SYSTAT.PRINT.KEYS
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
                                                             (* This function prints the KEYs of the SYSTATENTRYs of 
							     a WINDOW *)
    (PROG (ENTRYS SYSTATBLOCK FONTASCENT FONTHEIGHT HEIGHT)
          (SETQ ENTRYS (WINDOWPROP WINDOW 'SYSTAT.ENTRYS))
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW 'SYSTAT.BLOCK))
          (SETQ FONTASCENT (fetch (SYSTATBLOCK FONTASCENT) of SYSTATBLOCK))
          (SETQ FONTHEIGHT (fetch (SYSTATBLOCK FONTHEIGHT) of SYSTATBLOCK))
          (SETQ HEIGHT (ITIMES (LENGTH ENTRYS)
			       FONTHEIGHT))
          (MOVETO 0 (IDIFFERENCE HEIGHT FONTASCENT)
		  WINDOW)
          (FOR SYSTATENTRY IN ENTRYS
	     DO                                              (* Use PRIN1 in case KEY is a string *)
		(PRIN1 (fetch (SYSTATENTRY KEY) of SYSTATENTRY)
		       WINDOW)
		(TERPRI WINDOW)))))

(SYSTAT.UPDATE
  (LAMBDA (WINDOW)                                           (* kbr: "19-Jun-85 13:41")
                                                             (* Calculate and print rhs of WINDOW *)
    (PROG (SYSTATBLOCK GRAY TAB FONTHEIGHT FONTASCENT FONTDESCENT ENTRYS REGION)
          (SETQ SYSTAT.SPACEDATA (STORAGE.LEFT))
          (SETQ SYSTAT.MDSFRAC (FDIFFERENCE 1.0 (fetch (SPACEDATA MDSFRAC) of SYSTAT.SPACEDATA)))
          (SETQ SYSTAT.ATOMFRAC (FDIFFERENCE 1.0 (fetch (SPACEDATA ATOMFRAC) of SYSTAT.SPACEDATA)))
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW (QUOTE SYSTAT.BLOCK)))
          (SETQ TAB (fetch (SYSTATBLOCK TAB) of SYSTATBLOCK))
          (SETQ FONTHEIGHT (fetch (SYSTATBLOCK FONTHEIGHT) of SYSTATBLOCK))
          (SETQ FONTASCENT (fetch (SYSTATBLOCK FONTASCENT) of SYSTATBLOCK))
          (SETQ FONTDESCENT (fetch (SYSTATBLOCK FONTDESCENT) of SYSTATBLOCK))
          (COND
	    ((AND (ZEROP (DSPXPOSITION NIL WINDOW))
		  (IEQP (DSPYPOSITION NIL WINDOW)
			(IDIFFERENCE (WINDOWPROP WINDOW (QUOTE HEIGHT))
				     FONTASCENT)))           (* Hack for case where user did CLEARW *)
	      (SYSTAT.REPAINTFN WINDOW)
	      (RETURN)))
          (COND
	    ((fetch (SYSTATBLOCK GRAY) of SYSTATBLOCK)       (* WINDOW is deactivated. Ungray for the update.
							     *)
	      (SYSTAT.SHADEW WINDOW)))
          (for FORM in (WINDOWPROP WINDOW (QUOTE SYSTAT.FORMS)) do (EVAL FORM))
          (SETQ ENTRYS (WINDOWPROP WINDOW (QUOTE SYSTAT.ENTRYS)))
          (SETQ REGION (create REGION
			       LEFT ← TAB
			       BOTTOM ← 0
			       HEIGHT ← FONTHEIGHT
			       WIDTH ← TAB))
          (for SYSTATENTRY in ENTRYS as I from (SUB1 (LENGTH ENTRYS)) to 0 by -1
	     do (replace (REGION BOTTOM) of REGION with (IPLUS (ITIMES I FONTHEIGHT)
							       FONTDESCENT))
		(SYSTAT.UPDATE.SYSTATENTRY SYSTATENTRY WINDOW REGION FONTASCENT))
          (COND
	    ((AND (NULL (FIND.PROCESS (QUOTE SYSTAT.PROCESS)))
		  (NOT (fetch (SYSTATBLOCK GRAY) of SYSTATBLOCK)))
                                                             (* WINDOW is deactivated *)
	      (SYSTAT.SHADEW WINDOW))))))

(SYSTAT.UPDATE.SYSTATENTRY
  (LAMBDA (SYSTATENTRY WINDOW REGION FONTASCENT)             (* kbr: "28-Jul-84 14:10")
    (PROG (MODE VALUE LENGTH)
          (BITBLT NIL NIL NIL WINDOW (fetch (REGION LEFT) of REGION)
		  (fetch (REGION BOTTOM) of REGION)
		  (IPLUS (WINDOWPROP WINDOW 'WIDTH)
			 (IMINUS (fetch (REGION LEFT) of REGION))
			 1)
		  FONTASCENT
		  'TEXTURE
		  'REPLACE WHITESHADE)
          (SETQ MODE (fetch (SYSTATENTRY MODE) of SYSTATENTRY))
          (SETQ VALUE (APPLY* (fetch (SYSTATENTRY FETCHFN) of SYSTATENTRY)
			      (fetch (SYSTATENTRY USERDATA) of SYSTATENTRY)
			      SYSTATENTRY WINDOW))
          (COND
	    ((AND (EQ MODE 'BITBLT)
		  (NUMBERP VALUE))
	      (SETQ LENGTH (FTIMES VALUE (FLOAT (fetch (REGION WIDTH) of REGION))))
	      (COND
		((NOT (FLESSP LENGTH 0.0))
		  (BITBLT NIL NIL NIL WINDOW (fetch (REGION LEFT) of REGION)
			  (fetch (REGION BOTTOM) of REGION)
			  LENGTH FONTASCENT 'TEXTURE 'PAINT BLACKSHADE))
		(T                                           (* User%'s aren%'t suppose to have negative VALUEs%, but
							     we%'ll be lenient. *)
		   (BITBLT NIL NIL NIL WINDOW (FPLUS (fetch (REGION LEFT) of REGION)
						     (FMINUS LENGTH))
			   (fetch (REGION BOTTOM) of REGION)
			   (FMINUS LENGTH)
			   (fetch (REGION HEIGHT) of REGION)
			   'TEXTURE
			   'PAINT BLACKSHADE))))
	    (T (MOVETO (fetch (REGION LEFT) of REGION)
		       (fetch (REGION BOTTOM) of REGION)
		       WINDOW)
	       (PRIN1 VALUE WINDOW))))))

(SYSTAT.BUTTONEVENTFN
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG NIL
          (COND
	    ((LASTMOUSESTATE LEFT)
	      (SYSTAT.UPDATE WINDOW))
	    ((LASTMOUSESTATE MIDDLE)
	      (SYSTAT.MIDDLEBUTTONFN WINDOW))))))

(SYSTAT.MIDDLEBUTTONFN
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG (COMMAND)
          (SETQ COMMAND (MENU SYSTAT.MENU))
          (COND
	    (COMMAND (APPLY* COMMAND WINDOW))))))

(SYSTAT.REACTIVATE
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG (SYSTATBLOCK)
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW 'SYSTAT.BLOCK))
          (COND
	    ((fetch (SYSTATBLOCK GRAY) of SYSTATBLOCK)
	      (SYSTAT.SHADEW WINDOW)))
          (COND
	    ((NULL (FIND.PROCESS 'SYSTAT.PROCESS))
	      (ADD.PROCESS '(SYSTAT.PROCESS)
			   'RESTARTABLE SYSTAT.RESTARTABLE))
	    (T (WAKE.PROCESS 'SYSTAT.PROCESS))))))

(SYSTAT.DEACTIVATE
  (LAMBDA (WINDOW)                                           (* kbr: "28-Jul-84 14:10")
    (PROG (SYSTATBLOCK)
          (SETQ SYSTATBLOCK (WINDOWPROP WINDOW 'SYSTAT.BLOCK))
          (COND
	    ((AND (ACTIVEWP WINDOW)
		  (NOT (fetch (SYSTATBLOCK GRAY) of SYSTATBLOCK)))
	      (SYSTAT.SHADEW WINDOW)))
          (DEL.PROCESS 'SYSTAT.PROCESS))))

(SYSTAT.↑T
  (LAMBDA NIL                                                (* kbr: "18-Aug-85 16:06")
    (PROG (PROCESS STKNAME TOTALDELTA UTILDELTA SWAPDELTA NETIODELTA GCDELTA KEYBOARDDELTA)
          (COND
	    ((EQ SYSTAT.PROCESS (PROCESS.NAME (TTY.PROCESS)))
	      (SETQ PROCESS (CAR (NTH \PROCESSES (RAND 1 (LENGTH \PROCESSES))))))
	    (T (SETQ PROCESS (TTY.PROCESS))))
          (SETQ SYSTAT.PROCESS (PROCESS.NAME PROCESS))
          (COND
	    ((EQ PROCESS (THIS.PROCESS))                     (* PROCESS is the current process *)
	      (SETQ SYSTAT.FRAME 'SYSTAT.↑T))
	    (T (SETQ STACK (\MAKESTACKP NIL (fetch (PROCESS PROCFX) of PROCESS)))
	       (SETQ SYSTAT.FRAME (STKNTHNAME 0 STACK))
	       (for I from 1 while (FMEMB SYSTAT.FRAME '(ERRORSET DISMISS BLOCK))
		  do (SETQ SYSTAT.FRAME (STKNTHNAME I STACK)))))
          (SELECTQ SYSTAT.FRAME
		   ((\INTERRUPTFRAME \INTERRUPTED INTERRUPTED \DOINTERRUPTINTTY)
		     (SETQ SYSTAT.STATE 'Interrupted))
		   ((\TTYBACKGROUND CHAT.TYPEIN)
		     (SETQ SYSTAT.STATE "IO wait"))
		   ((DISMISS BLOCK \BACKGROUND AWAIT.EVENT MONITOR.AWAIT.EVENT \PROCESS.GO.TO.SLEEP)
                                                             (* Forms of blocking *)
		     (SETQ SYSTAT.STATE "Waiting"))
		   (SETQ SYSTAT.STATE 'Running))
          (COND
	    ((NULL SYSTAT.KEYBOARDTIME)                      (* Just initialize the first time *)
	      (SETQ SYSTAT.KEYBOARDTIME (fetch (MISCSTATS KEYBOARDWAITTIME) of \MISCSTATS))
	      (SETQ SYSTAT.TIMEBOX (CLOCK0 SYSTAT.TIMEBOX))
	      (SETQ SYSTAT.SWAPTIME (fetch (MISCSTATS SWAPWAITTIME) of \MISCSTATS))
	      (SETQ SYSTAT.NETIOTIME (fetch (MISCSTATS NETIOTIME) of \MISCSTATS))
	      (SETQ SYSTAT.GCTIME (fetch (MISCSTATS GCTIME) of \MISCSTATS))
	      (RETURN)))                                     (* calculates the amount of time spent not in disk wait
							     since the last control-T. Considers only time outside 
							     of key board wait.)
          (SETQ TOTALDELTA (IPLUS (IMINUS SYSTAT.TIMEBOX)
				  (SETQ SYSTAT.TIMEBOX (CLOCK0 SYSTAT.TIMEBOX))))
          (SETQ KEYBOARDDELTA (IPLUS (IMINUS SYSTAT.KEYBOARDTIME)
				     (SETQ SYSTAT.KEYBOARDTIME (fetch (MISCSTATS KEYBOARDWAITTIME)
								  of \MISCSTATS))))
          (SETQ SWAPDELTA (IPLUS (IMINUS SYSTAT.SWAPTIME)
				 (SETQ SYSTAT.SWAPTIME (fetch (MISCSTATS SWAPWAITTIME) of \MISCSTATS))
				 ))
          (SETQ NETIODELTA (IPLUS (SETQ SYSTAT.NETIOTIME (fetch (MISCSTATS NETIOTIME) of \MISCSTATS))
				  (IMINUS SYSTAT.NETIOTIME)))
          (SETQ GCDELTA (IPLUS (SETQ SYSTAT.GCTIME (fetch (MISCSTATS GCTIME) of \MISCSTATS))
			       (IMINUS SYSTAT.GCTIME)))
          (SETQ UTILDELTA (IDIFFERENCE TOTALDELTA (IPLUS SWAPDELTA NETIODELTA GCDELTA)))
          (SETQ SYSTAT.UTIL (FQUOTIENT UTILDELTA TOTALDELTA))
          (SETQ SYSTAT.SWAP (FQUOTIENT SWAPDELTA TOTALDELTA))
          (SETQ SYSTAT.NETIO (FQUOTIENT NETIODELTA TOTALDELTA))
          (SETQ SYSTAT.GC (FQUOTIENT GCDELTA TOTALDELTA))
          (SETQ SYSTAT.KEYBOARD (FQUOTIENT KEYBOARDDELTA TOTALDELTA)))))
)

(RPAQ? \LASTVMEMFILEPAGE 16383)

(RPAQ? SYSTAT.QUICKLYMSECSWAIT 1000)

(RPAQ? SYSTAT.SLOWLYMSECSWAIT 10000)

(RPAQ? SYSTAT.QUICKLYFLG T)

(RPAQ? SYSTAT.DEFAULT.ENTRYS (LIST (SYSTAT.PRINT.GETTOPVAL "USERNAME" 'USERNAME)
				   (SYSTAT.PRINT.EVAL "DIRECTORYNAME" '(DIRECTORYNAME T))
				   (SYSTAT.PRINT.GETTOPVAL "PROCESS" 'SYSTAT.PROCESS)
				   (SYSTAT.PRINT.GETTOPVAL "STATE" 'SYSTAT.STATE)
				   (SYSTAT.PRINT.GETTOPVAL "STACK FRAME" 'SYSTAT.FRAME)
				   (SYSTAT.BITBLT.GETTOPVAL "%% UTIL" 'SYSTAT.UTIL)
				   (SYSTAT.BITBLT.GETTOPVAL "%% NET IO" 'SYSTAT.NETIO)
				   (SYSTAT.BITBLT.GETTOPVAL "%% GC" 'SYSTAT.GC)
				   (SYSTAT.BITBLT.GETTOPVAL "%% KEYBOARD" 'SYSTAT.KEYBOARD)
				   (SYSTAT.BITBLT.GETTOPVAL "%% SWAP" 'SYSTAT.SWAP)
				   (SYSTAT.PRINT.EVAL "OPEN FILES" '(FLENGTH (OPENP)))
				   (SYSTAT.BITBLT.GETTOPVAL "MDS SPACE" 'SYSTAT.MDSFRAC)
				   (SYSTAT.BITBLT.GETTOPVAL "ATOM SPACE" 'SYSTAT.ATOMFRAC)
				   (SYSTAT.BITBLT.EVAL "PNAME SPACE" '(FQUOTIENT (ADD1 \CurPnPage)
										 \LastPnPage))
				   (SYSTAT.BITBLT.EVAL "VMEM SPACE" '(FQUOTIENT (VMEMSIZE)
										\LASTVMEMFILEPAGE))))

(RPAQ? SYSTAT.DEFAULT.FORMS '((SYSTAT.↑T)))

(RPAQ? SYSTAT.WINDOW NIL)

(RPAQ? SYSTAT.MENU (create MENU ITEMS ← '((Quickly 'SYSTAT.QUICKLY "Run SYSTAT quickly")
			    (Slowly 'SYSTAT.SLOWLY "Run SYSTAT slowly")
			    (Update 'SYSTAT.UPDATE "Update window")
			    (Deactivate 'SYSTAT.DEACTIVATE "Cease updating window")
			    (Reactivate 'SYSTAT.REACTIVATE "Resume updating window"))
			   CHANGEOFFSETFLG ← T WHENHELDFN ← 'PPROMPT3))

(RPAQ? SYSTAT.RESTARTABLE T)

(RPAQ? SYSTAT.TIMEBOX (CLOCK 0))

(RPAQ? SYSTAT.KEYBOARDTIME 0)

(RPAQ? SYSTAT.KEYBOARDWAITTIME 0)

(RPAQ? SYSTAT.NETIOTIME 0)

(RPAQ? SYSTAT.GCTIME 0)

(RPAQ? SYSTAT.SWAPTIME 0)

(RPAQ? SYSTAT.UTIL 0)

(RPAQ? SYSTAT.SWAP 0)

(RPAQ? SYSTAT.NETIO 0)

(RPAQ? SYSTAT.GC 0)

(RPAQ? SYSTAT.KEYBOARD 0)

(RPAQ? SYSTAT.FRAME NIL)

(RPAQ? SYSTAT.PROCESS NIL)

(RPAQ? SYSTAT.STATE NIL)
(* Redefine interrupt channel for ↑T *)
(MOVD? 'CONTROL-T 'OLDCONTROL-T)
(MOVD 'SYSTAT.WINDOW 'CONTROL-T)
(PUTPROPS SYSTAT COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (4368 20939 (SYSTAT.PROCESS 4378 . 4683) (SYSTAT.MSECSWAIT 4685 . 4894) (SYSTAT.QUICKLY 
4896 . 5102) (SYSTAT.SLOWLY 5104 . 5311) (SYSTAT.BITBLT.EVAL 5313 . 5550) (SYSTAT.BITBLT.GETTOPVAL 
5552 . 5799) (SYSTAT.PRINT.EVAL 5801 . 6036) (SYSTAT.PRINT.GETTOPVAL 6038 . 6283) (SYSTAT.WINDOW 6285
 . 6729) (SYSTAT.CREATEW 6731 . 8338) (SYSTAT.CLEARW 8340 . 8786) (SYSTAT.SHADEW 8788 . 9274) (
SYSTAT.REPAINTFN 9276 . 9641) (SYSTAT.COMPUTE.BLOCK 9643 . 10985) (SYSTAT.PRINT.KEYS 10987 . 11979) (
SYSTAT.UPDATE 11981 . 14430) (SYSTAT.UPDATE.SYSTATENTRY 14432 . 16041) (SYSTAT.BUTTONEVENTFN 16043 . 
16330) (SYSTAT.MIDDLEBUTTONFN 16332 . 16573) (SYSTAT.REACTIVATE 16575 . 17070) (SYSTAT.DEACTIVATE 
17072 . 17458) (SYSTAT.↑T 17460 . 20937)))))
STOP