dHOG: PROC OPTIONS(MAIN); ,/* PROCEDURE MONITORS USAGE OF SYSTEM RESOURCES BY INDIVIDUAL PROCESSES  AUTHOR: AL JAWORSKI  DATE: MARCH 18, 1982 */ X %INCLUDE $STSDEF; %INCLUDE SYS$GETJPI; %INCLUDE SYS$WAITFR; %INCLUDE TREE; L%INCLUDE VTPUT; %INCLUDE VTCLEAR; %INCLUDE SCAN; x%INCLUDE TRIM; %INCLUDE CENTER; @%INCLUDE VTBRIGHT; %INCLUDE VTUNDER; %INCLUDE VTRESET; l%INCLUDE GETFIX; %INCLUDE QIOWPUT; 4%INCLUDE WAIT; %INCLUDE ALPHAMERIC; %INCLUDE GETWORD; ` DCL (SS$_NORMAL,SS$_NOMOREPROC) FIXED BINARY(31) GLOBALREF VALUE; ( DCL (I,PROCESS_ADDRESS,RETURN_VALUE,CYCLE_TIME,FAULT_THRESHOLD,NUM_RESETS) FIXED BINARY(31); DCL PRCNAM CHAR(15) INIT(''); T DCL VPRCNAM CHAR(15) VARYING; DCL IMAGNAME CHAR(64) INIT('');  DCL VIMAGNAME CHAR(64) VARYING; DCL IMAGEBODY CHAR(10) VARYING; DCL (CPUTIM,BUFIO,DIRIO,PAGEFLTS,WSSIZE) FIXED BINARY(31); H DCL CLOCK_TIME CHAR(8);  t/* STRUCTURE TO RECEIVE JOB PROCESS INFORMATION */ DCL 1 JPI_LIST STATIC EXTERNAL, < 2 JPI_PRCNAM,  3 LNGTH FIXED BIN(15) INIT(15),  3 CODE FIXED BIN(15) INIT(JPI$_PRCNAM), h 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0), 0 2 JPI_IMAGNAME,  3 LNGTH FIXED BIN(15) INIT(64),  3 CODE FIXED BIN(15) INIT(JPI$_IMAGNAME), \ 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0), $ 2 JPI_CPUTIM,  3 LNGTH FIXED BIN(15) INIT(4),  3 CODE FIXED BIN(15) INIT(JPI$_CPUTIM), P 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0),  2 JPI_BUFIO, | 3 LNGTH FIXED BIN(15) INIT(4),  3 CODE FIXED BIN(15) INIT(JPI$_BUFIO), D 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0),  2 JPI_DIRIO, p 3 LNGTH FIXED BIN(15) INIT(4),  3 CODE FIXED BIN(15) INIT(JPI$_DIRIO), 8 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0),  2 JPI_PAGEFLTS, d 3 LNGTH FIXED BIN(15) INIT(4),  3 CODE FIXED BIN(15) INIT(JPI$_PAGEFLTS), , 3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0),  2 JPI_WSSIZE, X 3 LNGTH FIXED BIN(15) INIT(4),  3 CODE FIXED BIN(15) INIT(JPI$_WSSIZE),  3 ADDRESS PTR,  3 RETURN_LNGTH FIXED BIN(31) INIT(0),  2 ENDLIST FIXED BIN(31) INIT(0); L JPI_PRCNAM.ADDRESS=ADDR(PRCNAM); JPI_IMAGNAME.ADDRESS=ADDR(IMAGNAME); xJPI_CPUTIM.ADDRESS=ADDR(CPUTIM); JPI_BUFIO.ADDRESS=ADDR(BUFIO); @JPI_DIRIO.ADDRESS=ADDR(DIRIO); JPI_PAGEFLTS.ADDRESS=ADDR(PAGEFLTS);  JPI_WSSIZE.ADDRESS=ADDR(WSSIZE); l DCL (P,Q,HEADER) POINTER; 4!DCL 1 NODE BASED(P), ! 2 LEFT POINTER, ! 2 RIGHT POINTER, `" 2 BALANCE_BYTE CHAR(1), " 2 KEY_PRCNAM CHAR(15), (# 2 LAST_IMAGNAME CHAR(9), # 2 LAST_CLOCK_TIME CHAR(8), # 2 LAST_CPUTIM FIXED BINARY(31), T$ 2 LAST_BUFIO FIXED BINARY(31), $ 2 LAST_DIRIO FIXED BINARY(31), % 2 LAST_PAGEFLTS FIXED BINARY(31); % %DCL (DELTA_PAGEFLTS,DELTA_BUFIO,DELTA_DIRIO,DELTA_CPUTIM,DELTA_CLOCK_TIME) H& FIXED BINARY(31); &DCL (RATE_PAGEFLTS,RATE_BUFIO,RATE_DIRIO,RATE_CPUTIM) ' FIXED BINARY(31); t' 'DCL PROCESS_FOUND BIT(1); dCALL INIT; ,DO WHILE(NUM_RESETS<10);   STS$VALUE=SYS$GETJPI(6,PROCESS_ADDRESS,,JPI_LIST,,,); X RETURN_VALUE=SYS$WAITFR(6);   IF STS$VALUE=SS$_NORMAL THEN DO;  CLOCK_TIME=TIME();  CALL CALCULATE; L IF PROCESS_FOUND & DELTA_CLOCK_TIME>0 THEN  CALL PUT_PROCESS_INFO;  END; x  ELSE IF STS$VALUE=SS$_NOMOREPROC THEN DO; @ CALL SCREEN_RESET;  NUM_RESETS=NUM_RESETS+1;  PROCESS_ADDRESS=-1; l END;  4END; dINIT: PROC; , NUM_RESETS=0;  PROCESS_ADDRESS=-1;  HEADER=NULL(); X CALL VTCLEAR();  CALL VTPUT(1,1,  CENTER(  'WESTAT Process Resource Use Monitor',80));  CALL VTPUT(5,1,''); L CYCLE_TIME=GETFIX('Cycle Time (in seconds)?: ','1-60');  CALL VTPUT(10,1,'');  IF GETWORD('Do you wish a page fault alarm?: ','YES NO')='YES' THEN x FAULT_THRESHOLD=  GETFIX('Page fault alarm threshold (number per second)?: ','1-1000'); @ ELSE FAULT_THRESHOLD=0;  CALL VTPUT(2,1,'');  CALL QIOWPUT(BYTE(27)||'[J'); l CALL VTPUT(2,1,'Process');  CALL VTPUT(3,1,'Name'); 4 CALL VTPUT(2,16,'Image');  CALL VTPUT(3,16,'Name');  CALL VTPUT(2,27,'% Avail.'); ` CALL VTPUT(3,27,'CPU Time'); CALL VTPUT(2,37,'Buffered'); ( CALL VTPUT(3,37,'IO''s/sec.'); CALL VTPUT(2,47,'Direct'); CALL VTPUT(3,47,'IO''s/sec.'); T CALL VTPUT(2,57,'Page'); CALL VTPUT(3,57,'Flts/sec.');  CALL VTPUT(2,67,'Working'); CALL VTPUT(3,67,'Set Size'); H END INIT; dPUT_PROCESS_INFO: PROC; , IF I>23 THEN CALL SCREEN_RESET;  IF FAULT_THRESHOLD>0 & RATE_PAGEFLTS>=FAULT_THRESHOLD  THEN CALL QIOWPUT(COPY(BYTE(7),3)); X IF RATE_CPUTIM>=10 | RATE_BUFIO>=10 | RATE_DIRIO>=10 |  RATE_PAGEFLTS>=10 | WSSIZE>=600  THEN CALL VTBRIGHT();  CALL VTPUT(I,1,VPRCNAM);  CALL VTPUT(I,16,VIMAGNAME); L CALL VTFPUT(I,27,RATE_CPUTIM);  CALL VTFPUT(I,37,RATE_BUFIO);  CALL VTFPUT(I,47,RATE_DIRIO); x CALL VTFPUT(I,57,RATE_PAGEFLTS);  CALL VTFPUT(I,67,WSSIZE); @ CALL VTRESET();  I=I+1;  lEND PUT_PROCESS_INFO;  dCALCULATE: PROC; ,Q=NULL(); ALLOCATE NODE SET(P); VIMAGNAME=IMAGNAME; XVIMAGNAME=SCAN(VIMAGNAME,2,']'); VIMAGNAME=SCAN(VIMAGNAME,1,'.'); VPRCNAM=PRCNAM; VPRCNAM=TRIM(VPRCNAM); KEY_PRCNAM=PRCNAM; L CALL TREE(HEADER,P,15,9,Q);  xIF P^=Q THEN DO;  FREE P->NODE; @ P=Q;  DELTA_CLOCK_TIME=CLOCK_DIF(CLOCK_TIME,LAST_CLOCK_TIME);  DELTA_CPUTIM=CPUTIM-LAST_CPUTIM; l DELTA_BUFIO=BUFIO-LAST_BUFIO;  DELTA_DIRIO=DIRIO-LAST_DIRIO; 4 DELTA_PAGEFLTS=PAGEFLTS-LAST_PAGEFLTS;  IF DELTA_CLOCK_TIME>0 THEN DO;  RATE_CPUTIM=DIVIDE(DELTA_CPUTIM*100,DELTA_CLOCK_TIME,31); ` RATE_BUFIO=DIVIDE(DELTA_BUFIO*100,DELTA_CLOCK_TIME,31); RATE_DIRIO=DIVIDE(DELTA_DIRIO*100,DELTA_CLOCK_TIME,31); ( RATE_PAGEFLTS=DIVIDE(DELTA_PAGEFLTS*100,DELTA_CLOCK_TIME,31); END; PROCESS_FOUND='1'B; T END; ELSE PROCESS_FOUND='0'B;  LAST_CLOCK_TIME=CLOCK_TIME; LAST_CPUTIM=CPUTIM; H LAST_BUFIO=BUFIO; LAST_DIRIO=DIRIO; LAST_PAGEFLTS=PAGEFLTS; t IF VIMAGNAME='' THEN DO; < VIMAGNAME=LAST_IMAGNAME;  LAST_IMAGNAME=''; END; hELSE LAST_IMAGNAME=VIMAGNAME;  0END CALCULATE;   dCLOCK_DIF: PROC(TIME2,TIME1) RETURNS(FIXED BINARY(31)); ,DCL (TIME1,TIME2) CHAR(8); DCL (FTIME1,FTIME2) FIXED BINARY(31);  XFTIME1=(FIXED(SUBSTR(TIME1,5,4),31))  +(FIXED(SUBSTR(TIME1,3,2),31)*6000)  +(FIXED(SUBSTR(TIME1,1,2),31)*360000);  FTIME2=(FIXED(SUBSTR(TIME2,5,4),31)) L +(FIXED(SUBSTR(TIME2,3,2),31)*6000)  +(FIXED(SUBSTR(TIME2,1,2),31)*360000);  xRETURN(FTIME2-FTIME1);  @END;   dVTFPUT: PROC(ROW,COLUMN,VALUE); ,DCL PVALUE CHAR(5) VARYING; DCL (ROW,COLUMN,VALUE) FIXED BINARY(31);  XIF VALUE<=0 THEN RETURN; IF VALUE>99999 THEN CALL VTPUT(ROW,COLUMN,'******'); ELSE DO;  PVALUE=TRIM(CHAR(VALUE));  CALL VTPUT(ROW,COLUMN,PVALUE); LEND;  END VTFPUT; x dSCREEN_RESET: PROC; , CALL WAIT(CYCLE_TIME);  CALL VTPUT(4,1,'');  CALL QIOWPUT(BYTE(27)||'[J'); X I=4;  END SCREEN_RESET;  END HOG;