[comp.os.vms] Code needed to obtain system metrics

RAND@merrimack.EDU ("Rand P. Hall") (10/27/87)

Internals Gurus -

Can anyone lend ideas/source code on how to obtain the following:

  o system page fault rate
  o overall page fault rate
  o hard page fault rate
  o inswap rate

Running Monitor and sorting through its output is not a desirable solution.
Actually, what I'm looking for is some insight as to how Monitor's code
works with respect to these metrics. The VMS internals manual only 
briefly mentions the monitor data structures.

Thanks in advance,

Rand P. Hall
rand@merrimack.edu (csnet)

jeh@crash.CTS.COM (Jamie Hanrahan) (11/03/87)

In article <8710302027.AA03313@ucbvax.Berkeley.EDU> RAND@merrimack.EDU 
("Rand P. Hall") writes [paraphrased]:
> How do I get [various page and swap rate data] from VMS?

VMS keeps most all performance data as longword counts of events.  
You sample the count and note the time; sometime later you sample
the count and note the time again, subtract old count from new
count, and divide by the elapsed time to get the rate.  The time
is in VMS 64-bit binary time format (100-nanosecond ticks), so
quadword subtraction (SUBL followed by SBWC) and the EDIV instruction 
are recommended to determine the elapsed time.  

Here's some code excerpted from a rather fancy ReGIS color performance 
monitor I wrote some time ago.  (No, I don't want to ship it over the net
unless there's a lot of requests for it; it's about 110K bytes of source.  
I only mention it to establish that this code actually works!  The program
may appear on the next Symposium tape.)  It must be executed in kernel 
mode due to the DSBINT/ENBINT calls.  

Note that I have changed the target operands for the MOVs to metavariables.  
All of them should be longwords except the one for the data collection time.

	DSBINT	#IPL$_SYNCH			; ensure no changes during
						;  data coll.  

	MOVQ	G^EXE$GQ_SYSTIME, sample_time	; get current time

	MOVL	G^PMS$GL_FAULTS, total_faults

	MOVL	G^PMS$GL_PREADIO, hard_faults	; this is actually "the number
						;  of page faults resulting in
						;  page reads".  This is approx-
						;  imately equal to the number
						;  of reads from disk due to 
						;  page faults -- the exceptions
						;  will be if the page fault 
						;  cluster on disk is split  
						;  across extents.  Note that 
						;  the number of pages read in 
						;  will be greater than one per 
						;  fault due to page fault 
						;  clustering.

	; system pagefaults are tricky.  There is a process header for something
	; called the "system process".  The system process is not really a 
	; process (in that it's never scheduled), but its data structures are
	; a convenient place to put things.  For instance, the system and 
	; global page tables are in fact the P0 page table of the system 
	; process.  And, just as pagefaults for real processes are counted in
	; their respective PHDs, pagefaults to system space are counted in 
	; the "system process's" PHD!

	; get number of system page faults from system "process" header

	MOVAL	G^MMG$AL_SYSPCB, R4		; R4 -> system PCB
	MOVL	PCB$L_PHD(R4), R4		; R4 -> system PHD
	MOVL	PHD$L_PAGEFLTS(R4), faults_to_system_space	; get pf count

	MOVL	G^SWP$GL_ISWPCNT, inswaps_performed

	ENBINT

There you go.  Reduction of the data is left as an exercise for the reader
(half :-); can anyone recommend a good short-term averaging method for this 
sort of thing?).  Let me know if you want any others.  

	--- Jamie Hanrahan
	jeh@crash.cts.com ; sdcsvax!crash!jeh