From:	CSBVAX::MRGATE!U0012%DGOGWDG5.BITNET@CUNYVM.CUNY.EDU@SMTP  4-APR-1988 03:03
To:	ARISIA::EVERHART
Subj:	display of CPU usage


Received: from CUNYVM.CUNY.EDU by KL.SRI.COM with TCP; Thu 31 Mar 88 02:41:51-PST
Received: from DGOGWDG5.BITNET by CUNYVM.CUNY.EDU (IBM VM SMTP R1.1) with BSMTP id 3892; Thu, 31 Mar 88 05:42:20 EST
Date:    Thu, 31-MAR-1988 10:59  +0200
From:    "GWDGV1::MOELLER"  <U0012%DGOGWDG5.BITNET@CUNYVM.CUNY.EDU>
To:      INFO-VAX@KL.SRI.COM
Subject: display of CPU usage

I'd like to contribute the following command procedure, which outputs
the long-term "monitor" statistics normallly displayed by MONITOR MODES.

The procedure does not need privileges, but runs faster with WORLD priv.
(How do YOU find the system idle time?). VMS V4.4 ... V4.7 is required.

....................... Cut between dotted lines and save ......................
$!..............................................................................
$! VAX/VMS archive file created by VMS_SHAR V-5.01 01-Oct-1987
$! which was written by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au)
$! To unpack, simply save and execute (@) this file.
$!
$! This archive was created by MOELLER
$! on Thursday 31-MAR-1988 10:44:39.09
$!
$! It contains the following 1 file:
$! SHOMOD.COM
$!==============================================================================
$ Set Symbol/Scope=(NoLocal,NoGlobal)
$ Version=F$GetSYI("VERSION") ! See what VMS version we have here:
$ If Version.ges."V4.4" then goto Version_OK
$ Write SYS$Output "Sorry, you are running VMS ",Version, -
                ", but this procedure requires V4.4 or higher."
$ Exit 44
$Version_OK: CR[0,8]=13
$ Pass_or_Failed="failed!,passed."
$ Goto Start
$Convert_File:
$ Read/Time_Out=0/Error=No_Error1/Prompt="creating ''File_is'" SYS$Command ddd
$No_Error1: Define/User_Mode SYS$Output NL:
$ Edit/TPU/NoSection/NoDisplay/Command=SYS$Input/Output='File_is' -
        VMS_SHAR_DUMMY.DUMMY
f:=Get_Info(Command_Line,"File_Name");b:=Create_Buffer("",f);
o:=Get_Info(Command_Line,"Output_File");Set(Output_File,b,o);
Position(Beginning_of(b));Loop x:=Erase_Character(1);Loop ExitIf x<>"V";
Move_Vertical(1);x:=Erase_Character(1);Append_Line;
Move_Horizontal(-Current_Offset);EndLoop;Move_Vertical(1);
ExitIf Mark(None)=End_of(b) EndLoop;Position(Beginning_of(b));Loop
x:=Search("`",Forward,Exact);ExitIf x=0;Position(x);Erase_Character(1);
If Current_Character='`' then Move_Horizontal(1);else
Copy_Text(ASCII(INT(Erase_Character(3))));EndIf;EndLoop;Exit;
$ Delete VMS_SHAR_DUMMY.DUMMY;*
$ Checksum 'File_is
$ Success=F$Element(Check_Sum_is.eq.CHECKSUM$CHECKSUM,",",Pass_or_Failed)+CR
$ Read/Time_Out=0/Error=No_Error2/Prompt=" CHECKSUM ''Success'" SYS$Command ddd
$No_Error2: Return
$Start:
$ File_is="SHOMOD.COM"
$ Check_Sum_is=226128704
$ Copy SYS$Input VMS_SHAR_DUMMY.DUMMY
X$! output MONITOR's cpu time counters
X$! wjm 21-nov-1986 (VMS V4)
X$! change 7-may-1987 wjm: use XCPU for proctype (only VMS V4.4++)
X$! mod 2-jun-1987 wjm: handle case of no file access
X$! mod 7-jul-1987 wjm: use GOSUB
X$! mod 10-aug-1987 wjm: use NODE_HWTYPE
X$! mod 22-jan-1988 wjm: new cpu types (from 4.6)
X$! mod 08-feb-1988 wjm: minor edits
X$!
X$!*****
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$ say="write SYS$OUTPUT"
X$!
X$!
X$!*****`009find idle time = cputime of NULLproc
X$!
X$ oldpriv=f$setprv("world")
X$ if .not.f$privilege("world") then goto null_slowly
X$ nullpid=f$pid(nullctx)`009! NULLproc comes first if we have WORLD priv
X$ nullticks=f$getjpi(nullpid,"cputim")
X$ delete/symbol nullctx
X$ temp=f$setprv(oldpriv)
X$ goto null_ok
X$!
X$null_slowly:`009! use SHOW SYSTEM
X$ nullticks=0`009`009`009! assume error
X$ tmpfile="SYS$SCRATCH:SHOMOD_"+f$string(f$getjpi(0,"pid"))+".TMP;"
X$ on warning then goto null_ok
X$ show system/out='tmpfile'
X$ set noon
X$ open/read SHOMOD_TMP 'tmpfile'
X$ read SHOMOD_TMP tmpline
X$ read SHOMOD_TMP tmpline
X$ read SHOMOD_TMP tmpline`009! 3rd line has NULLPROC
X$ close SHOMOD_TMP
X$ delete 'tmpfile'
X$ set on
X$ on error then exit $status
X$ nullticks=(((f$int(f$ext(44,4,tmpline))*24+`009-
X`009`009f$int(f$ext(49,2,tmpline)))*60+`009-
X`009`009f$int(f$ext(52,2,tmpline)))*60+`009-
X`009`009f$int(f$ext(55,2,tmpline)))*100+-
X`009`009f$int(f$ext(58,2,tmpline))
X$null_ok:
X$!
X$!
X$!*****`009get performance data
X$!
X$ data=f$fao("!AD",exe$gl_abstim+4-pms$gl_kernel,pms$gl_kernel)
X$!
X$!
X$!*****`009get CPU type (just for fun)
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$!
X$!*****`009edit
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$ say " "
X$!
X$ abstim=f$cvui(8*(exe$gl_abstim-pms$gl_kernel),32,data)
X$ ticks=100*abstim
X$ gosub ed
X$ say "Up time          ",f$ext(0,16,edline),"  = 100.0 %"
X$ say " "
X$!
X$ ticks=nullticks
X$ gosub ed
X$ say "Idle             ",edline
X$!
X$ ticks=f$cvui(4*32,32,data)
X$ gosub ed
X$ say "Interrupt stack  ",edline
X$!
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$ c_ticks=f$cvui(8*(pms$gl_compat-pms$gl_kernel),32,data)
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 done`009! assume no compatibility mode
X$!
X$ ticks=c_ticks
X$ gosub ed
X$ say "PDP-11 user mode ",edline
X$!
X$done:
X$ exit
X$!
X$!
X$!*****`009SUBroutine ED
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 Convert_File
$ Exit

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