From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  7-DEC-1989 06:38
To:	MRGATE::"ARISIA::EVERHART"
Subj:	SMP version of SHOMOD.COM

Message-Id:  <8912071126.AA15652@crdgw1.ge.com>
Received: From CUNYVM.CUNY.EDU by CRVAX.SRI.COM with TCP; Thu,  7 DEC 89 02:47:48 PDT
Received: from DGOGWDG5.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.2.2MX) with BSMTP id 8172; Thu, 07 Dec 89 05:45:08 EDT
Date:    Thu,  7 Dec 1989 11:20:53  +0100
From: "GWDGV1::MOELLER"  <U0012%DGOGWDG5.BITNET@CUNYVM.CUNY.EDU>
To: info-vax@sri.COM
Subject: SMP version of SHOMOD.COM

Given the interest in the recently posted MONMODE.COM, I think I'll post
the latest version of the old SHOMOD.COM .
This command procedure gives a summary of CPU usage since last boot.
I think it now works for VMS V4.4 thru V5.2 and probably beyond,
and it does support SMP machines [except for the 11/782 - no idea how
times are kept there - anyone wishing to comment?].

A side note re MONMODE.COM: It does indeed demonstrate a DCL problem
in VMS 5.0 and 5.1, which is fixed in V5.2 .
As it stands, MONMODE.COM does not work on a VAXstation 3520, since it assumes
that CPUs are numbered starting from 0 - the "firefox" has CPUs #8 and #11 !

Anyway - enjoy,
        -wjm

Wolfgang J. Moeller, GWDG, D-3400 Goettingen, F.R.Germany | Disclaimer ...
Bitnet/Earn: U0012@DGOGWDG5         Phone: +49 551 201516 | No claim intended

$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user MOELLER
$! on  7-DEC-1989 10:48:34.09.
$!
$! It contains the following 1 file:
$!        SHOMOD.COM
$!
$!============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part
) ); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER
( 1 ); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT;
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START:
$ FILE_IS = "SHOMOD.COM"
$ CHECKSUM_IS = 2018206046
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$! output MONITOR's cpu time counters
X$! wjm 21-nov-1986 (VMS V4)
X$! mod 26-apr-1989 wjm: (VMS 5.02, uniprocessor only)
X$! mod 27-nov-1989 wjm: support VMS V4.4 thru V5.x
X$!
X$!*****
X$!
X$ say="write SYS$OUTPUT"
X$!
X$ vmsv=f$element(0,".",f$getsyi("version"))`009! major ...
X$ vmsv=f$extract(1,f$length(vmsv)-1,vmsv)`009! ... w/o initial letter
X$ vmsv5=vmsv.ge.5
X$!
X$ firstpass=1
X$!
X$!*****`009definitions & HARDWARE name
X$!
X$ if vmsv5 then goto define_v5
X$!
X$!
X$!* VMS V4
X$!
X$ pms$gl_kernel=%x80002b20
X$! +00 ... kernel`009`009! ticks
X$! +04 ... exec
X$! +08 ... super
X$! +0c ... user
X$! +10 ... intstk
X$! +14 ... compat`009`009! a.k.a. ...
X$ pms$gl_compat=%x80002b34
X$! +18 ... abstim`009`009! seconds, a.k.a. ...
X$ exe$gl_abstim=%x80002b38
X$!
X$ sch$gl_nullpcb=%x800024a8
X$ pcb$l_phd=%x6c
X$ phd$l_cputim=%x38
X$!
X$ machine=f$element(f$getsyi("cpu"),"\",-
X`009"\VAX 11/780"+-
X`009"\VAX 11/750"+-
X`009"\VAX 11/730"+-
X`009"\VAX *"+-`009! \VAX 86nn
X`009"\VAX *"+-`009! \VAX 82nn,83nn
X`009"\VAX *"+-`009! \?VAX 8800?VAX 8700?n2?n3?n4?n5?VAX 8550?VAX 8500
X`009"\microVAX I"+-
X`009"\?*?microVAX II?*?*?microVAX *"+-
X`009"\*"+-`009`009! undefined
X`009"\microVAX *")`009! \?CV_650?CV_9CC?CV_3FF
X$ if f$extract(0,1,machine).eqs."?" then`009-
X`009machine=f$element(f$getsyi("xcpu")+1,"?",machine)`009! VMS V4.4++
X$ if f$element(1,"*",machine).eqs."" then`009-
X`009machine=f$element(0,"*",machine)+f$getsyi("node_hwtype")
X$!
X$ goto define_end
X$!
X$!
X$!* VMS V5
X$!
X$define_v5:
X$ smp$gl_active_cpus=%x800045A8`009`009!bitmask
X$ smp$gl_cpu_data=%x800045DC`009`009!pointer array
X$ cpu$l_kernel=%x278
X$! +00 ... kernel`009`009`009! 10ms
X$! +04 ... exec
X$! +08 ... super
X$! +0c ... user
X$! +10 ... intstk`009`009`009! ... includes idle time
X$! +14 ... compat
X$! +18 ... (kernel busy wait)
X$! +1c ... idle
X$ exe$gl_abstim_tics=%x800046f8`009`009! 10ms
X$!
X$ machine=f$getsyi("hw_name")
X$!
X$!
X$define_end:
X$!
X$!
X$!*****`009header line
X$!
X$ say f$fao("!10AS!%D (!AS)",`009`009-
X`009f$logical("SYS$NODE")-"_"-"::",`009-
X`0090,`009`009`009`009-
X`009machine)
X$!
X$!
X$!*****`009get performance data
X$!
X$ if vmsv5 then goto getdata_v5
X$!
X$!
X$!* VMS V4
X$!
X$ nullphd=f$cvui(0,32,f$fao("!AD",4,sch$gl_nullpcb+pcb$l_phd))
X$ data=f$fao("!AD",exe$gl_abstim+4-pms$gl_kernel,pms$gl_kernel)
X$!
X$ nullticks=f$cvui(0,32,f$fao("!AD",4,nullphd+phd$l_cputim))
X$ k_ticks=f$cvui(0*32,32,data)-nullticks
X$ e_ticks=f$cvui(1*32,32,data)
X$ s_ticks=f$cvui(2*32,32,data)
X$ u_ticks=f$cvui(3*32,32,data)
X$ i_ticks=f$cvui(4*32,32,data)
X$ c_ticks=f$cvui(8*(pms$gl_compat-pms$gl_kernel),32,data)
X$ abstim=f$cvui(8*(exe$gl_abstim-pms$gl_kernel),32,data)
X$!
X$ absticks=100*abstim`009! for V5 compatibility ...
X$ bw_ticks=0
X$ smpcpumask=1`009`009! fake CPU 0 only
X$ cpuno=0
X$ mymask=0`009`009! fake all done
X$!
X$ goto getdata_end
X$!
X$!
X$!* VMS V5
X$!
X$getdata_v5:
X$ smpcpumask=f$cvui(0,32,f$fao("!AD",4,smp$gl_active_cpus))
X$ mymask=smpcpumask`009`009! no CPU handled yet
X$ if mymask.eq.0 then exit 4`009! NO CPU at all? - that's fatal
X$ cpuno=-1
X$!
X$nextcpu:`009! re-enter here for SMP (mymask .ne. 0)
X$cpuloop:
X$ cpuno=cpuno+1
X$ if mymask.and.1 then goto cpufound
X$ mymask=mymask/2
X$ goto cpuloop
X$cpufound:
X$ mymask=mymask/2`009! always shift out low bit
X$
X$ smpcpudata=f$cvui(0,32,f$fao("!AD",4,smp$gl_cpu_data+4*cpuno))
X$ data=f$fao("!AD",4*8,smpcpudata+cpu$l_kernel)
X$ absticks=f$cvui(0,32,f$fao("!AD",4,exe$gl_abstim_tics))
X$ abstim=absticks/100
X$ k_ticks=f$cvui(0*32,32,data)
X$ e_ticks=f$cvui(1*32,32,data)
X$ s_ticks=f$cvui(2*32,32,data)
X$ u_ticks=f$cvui(3*32,32,data)
X$ c_ticks=f$cvui(5*32,32,data)
X$ nullticks=f$cvui(7*32,32,data)
X$ i_ticks=f$cvui(4*32,32,data)-nullticks
X$ bw_ticks=f$cvui(6*32,32,data)
X$!
X$!
X$getdata_end:
X$!
X$!
X$!*****`009edit
X$!
X$ ticks=absticks
X$ gosub ed
X$ say ""
X$ say "Up time          ",f$ext(0,16,edline),"  = 100.0 %"
X$!
X$ if smpcpumask.ne.1 then goto displaycpu`009! if not only CPU 0
X$ say ""
X$ goto displaycpu_end
X$displaycpu:
X$ say f$fao("!45*- CPU !SL",cpuno)
X$displaycpu_end:
X$!
X$ ticks=nullticks
X$ gosub ed
X$ say "Idle             ",edline
X$!
X$ ticks=i_ticks
X$ gosub ed
X$ say "Interrupt stack  ",edline
X$!
X$ if bw_ticks.eq.0 then goto bwtick_end
X$ ticks=bw_ticks
X$ gosub ed
X$ say "SMP busywait     ",edline
X$bwtick_end:
X$!
X$ ticks=k_ticks+e_ticks+s_ticks+u_ticks+c_ticks
X$ gosub ed
X$ say "Process time     ",edline
X$!
X$ say " "
X$!
X$ ticks=k_ticks
X$ gosub ed
X$ say "Kernel mode      ",edline
X$!
X$ ticks=e_ticks
X$ gosub ed
X$ say "Executive mode   ",edline
X$!
X$ ticks=s_ticks
X$ gosub ed
X$ say "Supervisor mode  ",edline
X$!
X$ ticks=u_ticks
X$ gosub ed
X$ if c_ticks.ne.0 then`009-
X  say "Native user mode ",edline
X$ if c_ticks.eq.0 then`009-
X  say "User mode        ",edline
X$ if c_ticks.eq.0 then goto edit_end`009! assume no compatibility mode
X$!
X$ ticks=c_ticks
X$ gosub ed
X$ say "PDP-11 user mode ",edline
X$!
X$edit_end:
X$ if mymask.eq.0 then exit 1
X$ firstpass=0
X$ goto nextcpu
X$!
X$!
X$!*****`009SUBroutine ED (in: ticks & abstim; out: edline)
X$!
X$ed:
X$ if ticks.gt.100000000 then goto ed_p1`009! avoid overflow
X$ ed_prom=(10*ticks+abstim/2)/abstim`009! rounded
X$ goto ed_p2
X$ed_p1:
X$ ed_prom=(ticks+abstim/20)/(abstim/10)`009! rounded
X$ed_p2:
X$!
X$ ed_ss=ticks/100
X$ ed_xx=ticks-100*ed_ss
X$ ed_mm=ed_ss/60
X$ ed_ss=ed_ss-60*ed_mm
X$ ed_hh=ed_mm/60
X$ ed_mm=ed_mm-60*ed_hh
X$ ed_dd=ed_hh/24
X$ ed_hh=ed_hh-24*ed_dd
X$!
X$ edline=f$fao("!4SL !2ZL:!2ZL:!2ZL.!2ZL  =  !2UL.!1UL %",-
X`009ed_dd,ed_hh,ed_mm,ed_ss,ed_xx,ed_prom/10,ed_prom-10*(ed_prom/10))
X$ return
$ GOSUB UNPACK_FILE
$ EXIT

