	PROGRAM	CPUREP
 
C  THIS IS A SIMPLE MINDED REPORT PROGRAM WHICH READS LB:[1,4]SYSLOG.DAT AND
C  DISPLAYS INFORMATION ON TOTAL SYSTEM USAGE.  THE % UTILIZATION VALUE
C  IS OBTAINED BY SUBTRACTING NULL TIME FROM AVAILABLE ELAPSED TIME.  ALL THE
C  GLOBAL STATISTICS ARE DISPLAYED(#CHECKPOINT REQUESTS, # LDR REQUESTS, 
C  SHF REQUESTS, RUN REQUESTS) AS WELL AS THE NUMBER OF LOGINS WITHIN THE
C  SAMPLE INTERVAL AND THE USAGE OF CO: IF CO: LOGGING IS ENABLED.
C  THE % CO: COLLUMN GIVES THE % OF CPU TIME THE COMPUTER SPENDS SERVICING
C  TASKS RUNNING ON CO:  THE QIO COUNTS ARE DISPLAYED ONLY IF QIO COUNTING
C  IS ENABLED ($ACMSK) AND CO: QIO COUNTS ARE DISPLAYED ONLY IF USER
C  QIO ACCOUNTING IS ENABLED.
C	TO BUILD THIS TASK
C		A) BUILD PIN AND TYPE  PIN CPUREP.PRC
C			OR
C		B)	F4P CPUREP=CPUREP/NOTR
C			TKB>CPUREP.TSK/CP/FP=CPUREP,XX:[1,1]F4POTS/LB
C			TKB>/
C			TKB>ACTFIL=2
C			TKB>UNITS=2
C			TKB>LIBR=F4PRES:RO
C			TKB>//
 

C --	CPU STATISTICS REPORT
 
	INTEGER*2 IBUF(13)
	INTEGER*4 ICPUTM,IQIOS,NULTIM,ISTART,IEND,IELAPS,INULL,JRUNCT
	INTEGER*4 ICOQIO,NMDAYS(12)
	LOGICAL*1 LFILE(24)				! FOR FILE NAME
	LOGICAL*1 LDATE(8),LLOGIN(3),LCOUTL(5),LCOQIO(10),LOLD
	LOGICAL*1 LTIME(8),LSTTIM(8), LQIO(10),LLOGOF(3),LANS
	EQUIVALENCE (IREC,IBUF(1))
C -- START RECORD
	EQUIVALENCE (IHR,IBUF(2))
	EQUIVALENCE (IMIN,IBUF(3))
	EQUIVALENCE (ISEC,IBUF(4))
	EQUIVALENCE (IYEAR,IBUF(5))
	EQUIVALENCE (IMONTH,IBUF(6))
	EQUIVALENCE (IDAY,IBUF(7))
	EQUIVALENCE (ITICS,IBUF(8))
	EQUIVALENCE (ITKPS,IBUF(9))
	EQUIVALENCE (IDELTA,IBUF(10))
	EQUIVALENCE (IACMSK,IBUF(13))
C -- GBL DATA
	EQUIVALENCE (NULTIM,IBUF(5))		! IBUF(5)=LOWVAL,IBUF(6)=HIVAL
	EQUIVALENCE (ISHFCT,IBUF(7))
	EQUIVALENCE (ICKPCT,IBUF(8))
	EQUIVALENCE (ILDRCT,IBUF(9))
	EQUIVALENCE (IQIOS,IBUF(10))		! I*4 WORD MATCHES 2 BFR WORDS
	EQUIVALENCE (IRUNCT,IBUF(12))
C -- CO PACKET
	EQUIVALENCE(ICPUTM,IBUF(8))
 
	DATA NMDAYS	/31,29,31,30,31,30,31,31,30,31,30,31/
	LUN1=1					! TERMINAL LUN
	LUN2=2					! FILE LUN(LB:[1,4]SYSLOG.DAT)
	LUN3=1					! ASSUME WON'T SPOOL
	OPEN(UNIT=LUN1,NAME='TI:')		! SET UP TERMINAL FOR I/O
 
 
C  -- OPEN LB:[1,4]SYSLOG.DAT
	CALL ERRSET(43,.TRUE.,.FALSE.,,.FALSE.,)! DON'T WARN USER IF UIC ON
						! LB: IS MISSING
	CALL ERRSET(29,.TRUE.,.FALSE.,,.FALSE.,)! DON'T WARN IF OPEN ERROR
	WRITE(LUN1,5)				! SPOOL OUTPUT?
5	FORMAT(' SPOOL OUTPUT[Y/N]: ',$)	!
	READ(LUN1,10)LANS			! GEN ANSWER
10	FORMAT(1A1)				!
	IF(LANS.NE.'Y')			GOTO 15 ! DON'T SPOOL
	LUN3=3					! SET TO SPOOL
	OPEN(UNIT=LUN3,NAME='LP.LST',		! OPEN SPOOL FILE
     -	     CARRIAGECONTROL='LIST',		!
     -       DISPOSE='PRINT')			!
15	WRITE(LUN1,20)
20	FORMAT(' LOGFILE: ',$)			! PROMPT FOR LOGFILE NAME
	READ(LUN1,25,ERR=15,END=9999)N,LFILE	! GET FILE NAME
25	FORMAT(Q,24A1)				! IN CHARACTER FORMAT
	IF(N.EQ.0) GOTO 40			! <CR>, => LB:[1,4]SYSLOG.DAT
 
	OPEN(UNIT=LUN2,NAME='LB:TMP.TMP;1',	! TEMP SCRATCH FILE TO SET LB:
     -		       TYPE='SCRATCH')		!
	CLOSE(UNIT=LUN2)			! AND CLOSE IT IMMEDIATELY
	OPEN(UNIT=LUN2,				! OPEN FILE SPECIFIED BY LFILE
     -	     NAME	=LFILE,			!
     -	     READONLY,				!
     -	     FORM	='UNFORMATTED',		!
     -	     TYPE	='OLD',			!
     -	     ACCESS	='SEQUENTIAL',		!
     -	     SHARED,				! LOG...MUST HAVE WRITE ACCESS
     -	     ERR	=9000)			!
 						!
	GOTO 50					! SKIP SECOND OPEN
 
40	OPEN(UNIT=LUN2,				! OPEN DEFAULT FILE
     -       NAME	= 'LB:[1,4]SYSLOG.DAT',	!
     -	     READONLY,				!
     -	     FORM	= 'UNFORMATTED',	!
     -	     TYPE	= 'OLD',		!
     -	     ACCESS	= 'SEQUENTIAL',		!
     -	     SHARED,				! LOG... MUST HAVE WRITE ACCES
     -	     ERR	= 9000)			!
 
50	WRITE(LUN3,80)
80	FORMAT(' 'T45,'GLOBAL CPU USAGE STATISTICS',/)
C	WRITE(LUN1,90)
90	FORMAT(' 'T4,'DATE',T18,'TIME',T32,'% UTIL',
     -		T39,'SHF RQST',T48,'CHK RQST',T58,'LDR RQST',T68,'RUN RQST',
     -		T78,'QIO COUNT',T88,' LOGINS',T96,'LOGOFFS',
     -		T105,'% CO:',T111,'CO: QIO CNT')

	LSTDAY=0				! ASSUME DAY(UNMATCHABLE DATE)
100	READ(LUN2,ERR=9100,END=9990) IBUF	! READ THE ACCOUNT FILE
 						!
	IF(IREC.NE.1  .AND.			! SKIP IF NOT START OR
     -     IREC.NE.4) GOTO 140			! CHANGE DELTA
	NEWDAY=IDAY				! POINT TO NEW DATE
	NEWMON=IMONTH				! GET NEW MONTH
	DO 110 ,I=1,8				!
110	LTIME(I)=' '				!
	ENCODE(8,120,LDATE)IMONTH,IDAY,IYEAR	! GET ASCII DATE
120	FORMAT(I2,'/',I2,'/',I2)		!
	DO 130,I=1,8				!
130	IF(LDATE(I).EQ.' ')LDATE(I)='0'		! CONVERT SPACES TO '0'
	JACMSK=IACMSK				! SAVE ACCOUNTING MASK WORD
	ICOFLG=0				! ASSUME NO CO: LOGGING
	IF((JACMSK.AND."400).EQ."400)ICOFLG=1	! SHOW CO: LOGGING IS ENABLED
140	CONTINUE				!
	IF(IREC.NE.1)		GOTO 145	! SKIP OVER IF START RECORD
	ISTHR=IHR				! SET START TIME
	ISTMIN=IMIN				! SET START TIME
	ISTSEC=ISEC				! SET START TIME
	ENCODE(8,150,LSTTIM)ISTHR,ISTMIN,ISTSEC	! ENCODE THE START TIME
	JTKPS=ITKPS				! SAVE THE TICS/SEC
	DO 142, I=1,8				! CONVERT SPACES TO 0'S
142	IF(LSTTIM(I).EQ.' ')LSTTIM(I)='0'	! TO MAKE PRETTY
	GOTO 100				! READ AGAIN IF START RECORD
145	IF(LDATE(1).EQ.' ') 	GOTO 100	! IF FIRST RECORD NOT START 
	IF(LDATE(1).EQ.0)	GOTO 100	! "    "   "      "     "
	IF(IREC.EQ.5)NLOGIN=NLOGIN+1		! KEEP TRACK OF LOGONS
	IF(IREC.EQ.6)NLOGOF=NLOGOF+1		! AND NUMBER OF LOGOFFS
	IF(IREC.EQ.5)		GOTO 100	! AND READ AGAIN
	IF(IREC.EQ.8)COTIM=ICPUTM/JTKPS		! IF CO: PACKET SAVE CPUTIME 
	IF(IREC.EQ.2)QIOS=IQIOS			! CONVERT TO REAL VALUE
	IF(IREC.EQ.8)ICOQIO=IQIOS		! AND QIO COUNT
	IF(IREC.EQ.8)		GOTO 160	! AND PROCESS CO: PACKET DATA
	IF(IREC.NE.2)		GOTO 100	! FIND GLOBL STAT RECORDS
	ISTART=60*ISTHR+ISTMIN			! CPU TIME IN MINUTES AT START
	ISTART=60*ISTART+ISTSEC			! CONVERT TO SECONDS
	ENCODE(8,150,LTIME)IHR,IMIN,ISEC	! CONVERT TIME TO ASCII
	DO 147,I=1,8				! CONVERT SPACES TO 0'S
147	IF(LTIME(I).EQ.' ')LTIME(I)='0'		! TO MAKE PRETTY
150	FORMAT(I2,':',I2,':',I2)		!
	IEND=60*IHR+IMIN			! PUT  THE TIME IN SEC (I*4)
	IEND=IEND*60+ISEC			! SO WON'T HAVE OVERFLOW
	ELAPS=IEND-ISTART			!
	IF(ELAPS.GE.0) GOTO 155			! IF SYSTEM RUNS PAST MIDNIGHT
C						! TIME CALC GETS SCREWED UP
 	ELAPS=ELAPS+60*60*24			! OFFSET VALUE BY 24*60*60 SEC
	NEWDAY=NEWDAY+1				! TRICK FAILS IF END OF MONTH
	IF(NEWDAY.GT.NMDAYS(NEWMON))NEWDAY=0	! GOT TO START A NEW MONTH
	IF(NEWDAY.EQ.0)NEWMON=NEWMON+1		! SO BUMP UP MONTH
	IF(NEWDAY.EQ.0)NEWDAY=1			! AND START A NEW MONTH
	ENCODE(5,151,LDATE)NEWMON,NEWDAY	!**THIS SHOULD BE FIXED
151	FORMAT(I2,'/',I2)			!
	DO 152,I=1,8				! FILL SPACES WITH '0'
152	IF(LDATE(I).EQ.' ')LDATE(I)='0'		! TO MAKE PRETTY
155	FREE=NULTIM/JTKPS			! COMPUTE NULL TIME IN SECONDS
	ISHF=ISHFCT				! SAVE VALUES
	ICKP=ICKPCT				! FOR PRINTING LATER
	ILDR=ILDRCT				!
	IRUN=IRUNCT				!
	X=FREE					!*****TEMP
	UTILIZ=100.*(1-FREE/ELAPS)		! % SYSTEM UTILIZATION
	IF(ICOFLG.EQ.1)		GOTO 100	! IF CO: LOGGING ENABLED
 
160	CONTINUE				! 
	DO 180,I=1,5				! FILL IN WITH SPACES IN CASE
180	LCOUTL(I)=' '				! CO: LOGGING NOT ENABLED
	IF(ICOFLG.EQ.0)			GOTO 400! IF CO: LOGGING NOT ENABLED
	FREE=100.*COTIM/ELAPS			! COMPUTE % CO: TIME
	ENCODE(5,200,LCOUTL)FREE		!
200	FORMAT(F5.1)				!
	IF((COTIM+X).GT.ELAPS)WRITE(LUN3,99)ELAPS,COTIM,X!****TEMP
99	FORMAT(' TIME CHECK ERROR - ELAPSE, COTIME, NULL TIME) =',3F8.0)!*TEMP
400	CONTINUE				!
	DO 440,I=1,10				! SPACE OUT QIO WORD
	LQIO(I)=' '				! FILL WITH BLANKS
440	LCOQIO(I)=' '				! PUT SPACES IN QIO FIELDS
	IF((JACMSK.AND."2).NE."2)	GOTO 500! IF QIO'S NOT BEING LOGGED
C	QIOS=IQIOS				! CONVERT TO REAL
	ENCODE(10,460,LQIO)QIOS			! ENCODE THE QIO'S
460	FORMAT(1PE10.3)				! THERE MAY BE A LOG
	IF(ICOFLG.NE.1)			GOTO 500! IF CO: LOGGING NOT ENABLED
	IF((JACMSK.AND."1000).NE."1000) GOTO 500! IF USER QIO NOT ENABLED
	QIOS=ICOQIO				! MAKE A REAL NUMBER
	ENCODE(10,460,LCOQIO)QIOS		! AND ENCODE FOR PRINTOUT
500	CONTINUE				!
	DO 510, I=1,3				! FILL IN WITH SPACES
510	LLOGIN(I)=' '				!
	IF((JACMSK.AND."200).NE."200) GOTO 550	! IF LOGON COUNTING DISABLED
	ENCODE(3,520,LLOGIN)NLOGIN		! ENCODE # OF LOGINS
	ENCODE(3,520,LLOGOF)NLOGOF		! ENCODE # OF LOGOFFS
520	FORMAT(I3)				! NOT >999/4HRS PLEASE
550	CONTINUE				!
	IF(IRUN.GT.0)JRUN=IRUN			!
	IF(IRUN.LT.0)JRUN=32768-IRUN		!
	IF(LSTDAY.NE.NEWDAY)WRITE(LUN3,575)	! SKIP  LINE IF DATE CHANGES
575	FORMAT(' ')				! TO MAKE LIST EASIER TO READ
	IF(LSTDAY.NE.NEWDAY)WRITE(LUN3,90)	! AND STICK IN HEADER
	LSTDAY=NEWDAY				! RESET VALUE

	WRITE(LUN3,900)LDATE,LSTTIM,LTIME,	!
     -			UTILIZ,ISHF,ICKP,	!
     -			ILDR,JRUN,LQIO,		!
     -			LLOGIN,LLOGOF,LCOUTL,	!
     -                  LCOQIO
900	FORMAT(' '8A1,2X,8A1,'-',8A1,3X,F6.1,I6,!
     -		3I10,3X,10A1,3X,3A1,5X,3A1,	!
     -		3X,5A1,2X,10A1)
	DO 910, I=1,8				! PUT END TIME IN START TIME
910	LSTTIM(I)=LTIME(I)			! FOR THE NEXT TIME
	ISTHR=IHR				!
	ISTMIN=IMIN				!
	ISTSEC=ISEC				!
	NLOGIN=0				! RESET COUNTER
	NLOGOF=0				! ALSO RESET
	GOTO 100				! AND READ LOG FILE AGAIN
9000	WRITE(LUN1,9010)			! WE GOT AN ERROR, WARN USER
9010	FORMAT(' CPUREP -- OPEN ERROR, FILE NOT FOUND')	!
	GOTO 9990				!
9100	WRITE(LUN1,9010)			! IF WE GET A READ ERROR
9110	FORMAT(' CPUREP -- READ ERROR IN SYSLOG.DAT') ! WARN USER 
	GOTO 9990				!
9990	CLOSE(UNIT=LUN2)			! CLOSE UP AND EXIT
	CLOSE(UNIT=LUN3)			! CLOSE SPOOL FILE
9999	CONTINUE				!
	END					!
