	.TITLE	DUMPSTATS
	.IDENT	/01/

;+++
; Functional Description:
;
;
; Author:
;
;	A. Frank Hattyar		14-Aug-1981
;	
; Input Parameters:
;
;	20(ap)		Dummy variable
;
; Output Parameters:
;
;	
;
; Status returned:
;
;
; Calling method:
;
;	    DUMMY(arg1,arg2)
;
;	arg1
;
;		Desc
;
;
;---
	.PAGE
	.PSECT	DUMPSTATS		LONG,PIC,CON,REL,SHR,LCL,EXE,RD,WRT

statbufold:
	.blkl	128			; stat totals from last time
statbufnew:
	.blkl	128			; stat totals from this time
kernelbuf:
	.blkl				; buffer for kernel mode routines
kernelbuf2:
	.blkl

	.LIBRARY "SYS$LIBRARY:LIB.MLB"
	$PHDDEF GLOBAL

	.ENTRY	DUMPSTATS	^M<R2,R3,R4,R5,R6,R7,R8,R9,R10,R11>

	$cmkrnl_s get_null
	moval	statbufnew,r0		; set up for collection
	movl	kernelbuf,(r0)+		; and get null jop cpu time
	movl	exe$gl_abstim,(r0)+	; system uptime in secs
	movl	pms$gl_dirio,(r0)+	; number of direct I/O's
	movl	pms$gl_bufio,(r0)+	; number of buffered I/O's
	movl	pms$gl_lognam,(r0)+	; number of logical name translations
	movl	pms$gl_mbreads,(r0)+	; number of mailbox reads
	movl	pms$gl_mbwrites,(r0)+	; number of mailbox writes
	movl	pms$gl_iopfmseq,(r0)+	; last I/O Packet mes seq number
	addl2	#36,r0			; skip next 15 longwords
	movl	pms$gl_switch,(r0)+	; number of switches from current proc
					; the difference between the last two
					; params reflects the number of context
					; switches due to waits
	movl	pms$gl_faults,(r0)+	; number of page faults
	movl	pms$gl_preads,(r0)+	; number of page reads
	movl	pms$gl_preadio,(r0)+	; number of page read I/O's
	movl	pms$gl_pwrites,(r0)+	; number of modified pages written
	movl	pms$gl_pwritio,(r0)+	; number of I/O's to write mod pages
	movl	pms$gl_dzroflts,(r0)+	; number of demand zero page faults
	moval	pms$gl_kernel,r1	; pointer to processor mode table
	movl	(r1)+,(r0)+		; cpu time in kernel mode
	movl	(r1)+,(r0)+		; cpu time in exec mode
	movl	(r1)+,(r0)+		; cpu time in super mode
	movl	(r1)+,(r0)+		; cpu time in user mode
	movl	(r1)+,(r0)+		; cpu time on interrupt stack
	movl	pms$gl_compat,(r0)+	; cpu time in compatibility mode
	movl	kernelbuf2,(r0)+	; system page faults
	movl	pms$gl_turn,(r0)+	; number of window turns
	movl	pms$gl_opens,(r0)+	; number of file opens
	movl	pms$gl_fcp2,r1		; get pointer to FCP database
	movl	#70,r2			; set up the counter
10$:	movl	(r1)+,(r0)+		; get the database a longword at a time
	sobgtr	r2,10$

	movl	4(ap),r0		; address of buffer descriptor
	movl	4(r0),r0		; address of buffer
	moval	statbufnew,r1		; address of buffer we just filled
	moval	statbufold,r2		; addr of buff with data from last time
	movl	#8,r3			; do the first eleven longwords
40$:	subl3	(r2)+,(r1)+,(r0)+	; calculate the difference
	sobgtr	r3,40$
	addl2	#36,r0			; skip the next 9 longwords
	addl2	#36,r1
	addl2	#36,r2
	movl	#86,r3			; now do the rest
50$:	subl3	(r2)+,(r1)+,(r0)+
	sobgtr	r3,50$
	movc3	#512,statbufnew,statbufold
					; save current data for next time
x:	ret

	.ENTRY	GETSTATS	^M<R2,R3,R4,R5,R6,R7,R8,R9,R10,R11>

	movl	sch$gl_freecnt,@4(ap)	; current free pages
	movl	sch$gl_mfycnt,@8(ap)	; current modified pages
	movl	pms$gl_open,@12(ap)	; current open files
	ret

get_null:
	.word	^M<R2,R3>
	
	movl	sch$gl_nullpcb,r1	; addr of ptr to pcb
	movl	(r1),r1			; addr of pcb
	movl	pcb$l_phd(r1),r1	; addr of phd
	movl	phd$l_cputim(r1),kernelbuf

	movl	mmg$gl_sysphd,r1	; system header address
	movl	phd$l_pageflts(r1),kernelbuf2
	ret
	
	.end
