	.title	'Get Job Statistics via XCALL LIB$STAT_TIMER'
;
;
;		G E T S T . S B L
;
;

SUBROUTINE	GETST
FUNCTION	,D	;Function to perform
			;	0 - Initialize Timer
			;		** Must always do first **
			;	1 - Obtain Statistics
			;		Elapsed Time
			;		CPU Time
			;		Buffered I/O
			;		Direct I/O
			;		Page Faults
	; $DBD GETST.DBD
	; 12-May-1987
	; MRS Development

COMMON	STATS
				,A1,'|'
ZONED_ELAPSED_TIME		,D10	;Zoned Decimal Value of Elapsed Time
				,A1,'|'
ZONED_CPU_TIME			,D10	;Zoned Decimal Value of CPU Time
				,A1,'|'
ZONED_BUFFERED_IO		,D10	;Zoned Decimal Value of Buffered I/O
				,A1,'|'
ZONED_DIRECT_IO			,D10	;Zoned Decimal Value of Direct I/O
				,A1,'|'
ZONED_PAGE_FAULTS		,D10	;Zoned Decimal Value of Page Faults
				,A1,'|'
ELAPSED_TIME_STRING		,A11	;Elapsed Time as a formatted
					;ASCII string "hh:mm:ss.cc"
				,A1,'|'
CURRENT_TIME_STRING		,A23	;Current Date & Time as a formatted
					;ASCII string "dd-mmm-yyyy hh:mm:ss.cc"
				,A1,'|'

	;$End of Definition
	.page
	; $SBL GETST.SBL
	; 12-May-1987
	; MRS Development

RECORD
INT_VAL_1	,I4,1	;Longword Integer Value of Decimal "1"
INT_VAL_2	,I4,2	;Longword Integer Value of Decimal "2"
INT_VAL_3	,I4,3	;Longword Integer Value of Decimal "3"
INT_VAL_4	,I4,4	;Longword Integer Value of Decimal "4"
INT_VAL_5	,I4,5	;Longword Integer Value of Decimal "5"

RECORD
INT_ELAPSED_TIME	,I8	;Address of a Quadword that
				;contains Elapsed Real Time.
INT_CPU_TIME		,I4	;Address of a Longword that
				;contains elapsed CPU Time.
INT_BUFFERED_IO		,I4	;Address of a Longword that
				;contains count of Buffered I/O.
INT_DIRECT_IO		,I4	;Address of a Longword that
				;contains count of Direct I/O.
INT_PAGE_FAULTS		,I4	;Address of a Longword that
				;contains count of Page Faults.

RECORD
INT_TIME_LENGTH		,I2	;Address of a Word containing
				;the length of "ELAPSED_TIME_STRING"
ZONED_TIME_LENGTH	,D2	;Zoned Decimal Value of length of
				;"ELAPSED_TIME_STRING" returned.

	PROC

BEGIN_SUBROUTINE,

	;Always Obtain current Date and Time.
	XCALL SYS$ASCTIM (%REF(INT_TIME_LENGTH)
&			,%DESCR(CURRENT_TIME_STRING),,)

	;Check Length of Current Time String Returned, it should be 23.
	ZONED_TIME_LENGTH = INT_TIME_LENGTH

	IF (FUNCTION) THEN
	BEGIN
	;Obtain Elapsed Real Time.
	XCALL LIB$STAT_TIMER (%REF(INT_VAL_1),%REF(INT_ELAPSED_TIME))
	ZONED_ELAPSED_TIME = INT_ELAPSED_TIME

	;Re-format Elapsed Time as "hh:mm:ss.cc".
	XCALL SYS$ASCTIM (%REF(INT_ELAPSED_TIME)
&			,%DESCR(ELAPSED_TIME_STRING)
&			,%REF(INT_ELAPSED_TIME)
&			,%VAL(1))

	;Check Length of Elapsed Time String Returned, it should be 11.
	ZONED_TIME_LENGTH = INT_TIME_LENGTH

	;Obtain Elapsed CPU Time.
	XCALL LIB$STAT_TIMER (%REF(INT_VAL_2),%REF(INT_CPU_TIME))
	ZONED_CPU_TIME = INT_CPU_TIME

	;Obtain Count of Buffered I/O Operations.
	XCALL LIB$STAT_TIMER (%REF(INT_VAL_3),%REF(INT_BUFFERED_IO))
	ZONED_BUFFERED_IO = INT_BUFFERED_IO

	;Obtain Count of Direct I/I Operations.
	XCALL LIB$STAT_TIMER (%REF(INT_VAL_4),%REF(INT_DIRECT_IO))
	ZONED_DIRECT_IO = INT_DIRECT_IO

	;Obtain Count of Page Faults.
	XCALL LIB$STAT_TIMER (%REF(INT_VAL_5),%REF(INT_PAGE_FAULTS))
	ZONED_PAGE_FAULTS = INT_PAGE_FAULTS
	END
	ELSE
	BEGIN
	XCALL LIB$INIT_TIMER
	END

SUB_RETURN,

	RETURN
	;$End
