program MSYS option type = explicit %include "$JPIDEF" %from %library %include "$PSCANDEF" %from %library declare string constant ulon = esc + "[4m", & rvon = esc + "[7m", & atof = esc + "[m", & gon = esc + "(0", & gof = esc + "(B", & home = esc + "[H", & cls = esc + "[2J", & deol = esc + "[K" declare long constant SCH$C_COM = 12 external long constant CLI$_PRESENT, & CLI$_DEFAULTED, & SS$_NOMOREPROC external long function SYS$GETJPIW, & SYS$PROCESS_SCAN, & CLI$PRESENT record process long pid long cputime end record record item word itemlen word itemcode long address long lenaddress end record record summary string acc = 15 long cpu long totcpu end record declare process prc(256) declare item jpi_itmlst(5), pscan_itmlst(1) declare summary summ(255), tsum declare long summsize, summno, deltacpu, comcount declare long n, sts, totcpu, cpu, pid, x, passes, ticks, totticks declare word iosb(3), nt(7) declare double c, tc declare string s map (jpistuff) long jpi.summfield_l map (jpistuff) string jpi.summfield = 256, & long jpi.summsize, & long jpi.pid, & long jpi.cputime, & long jpi.index, & long jpi.state, & string jpi.summtext = 15, & string jpi.nodename = 6 declare long summlen, summitm declare string summname record quadword long lo long hi end record declare quadword start_q, end_q, interval_q declare string start_time, current_time declare long idle, totidle, idleticks, cpus set no prompt sts = CLI$PRESENT("ACCOUNT") if sts = CLI$_PRESENT or sts = CLI$_DEFAULTED then summlen = 8 summitm = JPI$_ACCOUNT summname = "account" end if if CLI$PRESENT("USERNAME") = CLI$_PRESENT then summlen = 12 summitm = JPI$_USERNAME summname = "username" end if if CLI$PRESENT("IMAGE") = CLI$_PRESENT then summlen = 255 summitm = JPI$_IMAGNAME summname = "image" end if if CLI$PRESENT("PROCESS") = CLI$_PRESENT then summlen = 15 summitm = JPI$_PRCNAM summname = "process name" end if if CLI$PRESENT("PRIORITY") = CLI$_PRESENT then summlen = 4 summitm = JPI$_PRIB summname = "priority level" end if if CLI$PRESENT("MODE") = CLI$_PRESENT then summlen = 255 summitm = JPI$_MODE summname = "mode" end if if CLI$PRESENT("MODE") = CLI$_PRESENT then summlen = 255 summitm = JPI$_MODE summname = "mode" end if pscan_itmlst(0)::itemlen = 0 pscan_itmlst(0)::itemcode = 0 jpi.nodename = "" if CLI$PRESENT("NODE")=CLI$_PRESENT then call CLI$GET_VALUE("NODE", jpi.nodename) pscan_itmlst(0)::itemlen = 6 pscan_itmlst(0)::itemcode = PSCAN$_NODENAME pscan_itmlst(0)::address = loc(jpi.nodename) pscan_itmlst(0)::lenaddress = PSCAN$M_CASE_BLIND pscan_itmlst(1)::itemlen = 0 pscan_itmlst(1)::itemcode = 0 end if jpi_itmlst(0)::itemlen = 4 jpi_itmlst(0)::itemcode = JPI$_PID jpi_itmlst(0)::address = loc(jpi.pid) jpi_itmlst(0)::lenaddress = 0 jpi_itmlst(1)::itemlen = summlen jpi_itmlst(1)::itemcode = summitm jpi_itmlst(1)::address = loc(jpi.summfield) jpi_itmlst(1)::lenaddress = loc(jpi.summsize) jpi_itmlst(2)::itemlen = 4 jpi_itmlst(2)::itemcode = JPI$_CPUTIM jpi_itmlst(2)::address = loc(jpi.cputime) jpi_itmlst(2)::lenaddress = 0 jpi_itmlst(3)::itemlen = 4 jpi_itmlst(3)::itemcode = JPI$_PROC_INDEX jpi_itmlst(3)::address = loc(jpi.index) jpi_itmlst(3)::lenaddress = 0 jpi_itmlst(4)::itemlen = 4 jpi_itmlst(4)::itemcode = JPI$_STATE jpi_itmlst(4)::address = loc(jpi.state) jpi_itmlst(4)::lenaddress = 0 jpi_itmlst(5)::itemlen = 0 jpi_itmlst(5)::itemcode = 0 prc(n)::pid = 0 for n = 1 to 255 totcpu = 0 totticks = 0 x = ctrlc on error goto errtrap start_time = string$(20%, 0%) call SYS$ASCTIM(, start_time,,) gosub showheader summsize = 0 idleticks = 0 call SYS$GETTIM(end_q) while -1 start_q = end_q call SYS$GETTIM(end_q) call LIB$SUB_TIMES(end_q, start_q, interval_q) call SYS$NUMTIM(nt(0), interval_q) current_time = string$(20%, 0%) call SYS$ASCTIM(, current_time, end_q,) ticks = nt(2%) * 24%*60%*60%*100% & + nt(3%) * 60%*60%*100% & + nt(4%) * 60%*100% & + nt(5%) * 100% & + nt(6%) totticks = totticks + ticks call CPUIDLE(x, cpus) idleticks = x if idleticks = 0% idle = x - idleticks totidle = totidle + idle idleticks = x summ(n)::cpu = 0 for n = 1 to summsize cpu = 0% comcount = 0% sts = SYS$PROCESS_SCAN(pid, pscan_itmlst(0)) exit program sts unless sts and 1% l1: while -1 sts = SYS$GETJPIW(,pid,, jpi_itmlst(0%), iosb(0%), ,) exit l1 if sts = SS$_NOMOREPROC iterate l1 unless sts and 1% iterate l1 unless iosb(0%) and 1% comcount = comcount + 1% if jpi.state = SCH$C_COM select summitm case JPI$_ACCOUNT jpi.summtext = edit$(left(jpi.summfield, & jpi.summsize), 4%) jpi.summtext = "SYSTEM" if jpi.summtext= "" & or left(jpi.summtext, 1%) = "<" case JPI$_USERNAME jpi.summtext = edit$(left(jpi.summfield, & jpi.summsize), 4%) case JPI$_IMAGNAME x = instr(0%, jpi.summfield, "]") x = instr(x + 1%, jpi.summfield, "]") & if mid$(jpi.summfield, x, 2) = "][" n = instr(x, jpi.summfield, ".") jpi.summtext = seg$(jpi.summfield, x+1%, n-1%) jpi.summtext = "(none)" if jpi.summtext = "" case JPI$_PRCNAM jpi.summtext = edit$(left(jpi.summfield, & jpi.summsize), 1% + 4%) case JPI$_PRIB jpi.summtext = num1$(jpi.summfield_l) case JPI$_MODE select jpi.summfield_l case 1% \ jpi.summtext = "Network" case 2% \ jpi.summtext = "Batch" case 3% \ jpi.summtext = "Interactive" case else \ jpi.summtext = "Other" end select end select n = jpi.index if prc(n)::pid <> jpi.pid then prc(n)::pid = jpi.pid prc(n)::cputime = jpi.cputime end if deltacpu = jpi.cputime - prc(n)::cputime prc(n)::cputime = jpi.cputime summno = -1 summno = x if summ(x)::acc = jpi.summtext & for x = 1 to summsize if summno = -1 then summsize = summsize + 1 summno = summsize summ(summno)::totcpu = 0 summ(summno)::cpu = 0 summ(summno)::acc = jpi.summtext end if summ(summno)::cpu = summ(summno)::cpu + deltacpu summ(summno)::totcpu = summ(summno)::totcpu + deltacpu totcpu = totcpu + deltacpu cpu = cpu + deltacpu next print esc; "[;61H"; current_time print esc; "[3;73HCOM: "+ format$(comcount, "###") print esc; "[5H"; for summno = 1 to min(summsize, 17%) for x = summno + 1% to summsize if summ(summno)::totcpu < summ(x)::totcpu then tsum = summ(summno) summ(summno) = summ(x) summ(x) = tsum end if next x if summ(summno)::totcpu > 0% then tc = (summ(summno)::totcpu + 0.0) / totticks c = (summ(summno)::cpu + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(50%, 32%) lset s = string$(c * 50%, 113%) + "u" s = "t" + right(s, 2%) unless left(s, 1%) = "u" s = "x" + right(s, 2%) if left(s, 1%) = "u" x = tc * 50% s = summ(summno)::acc & + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " " & + gon + rvon & + left(s, x) + atof + right(s, x+1%) print trm$(s); gof; deol end if next summno if passes > 0% then if jpi.nodename = "" then tc = (totticks-totcpu-totidle + 0.0) / totticks c = (ticks - cpu - idle + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(50%, 32%) lset s = string$(c * 50 - 1%, 113%) + "u" s = "t" + right(s, 2%) unless left(s, 1) = "u" s = "x" + right(s, 2%) if left(s, 1) = "u" x = tc * 50 s = "System overhead" & + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " " & + gon + rvon & + left(s, x) + atof + right(s, x+1%) print trm$(s); gof; deol tc = (totidle + 0.0) / totticks c = (idle + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(50%, 32%) lset s = string$(c * 50 - 1%, 113%) + "u" s = "t" + right(s, 2%) unless left(s, 1) = "u" s = "x" + right(s, 2%) if left(s, 1) = "u" x = tc * 50 s = "Idle " & + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " " & + gon + rvon & + left(s, x) + atof + right(s, x+1%) print trm$(s); gof; deol else tc = (totticks - totcpu + 0.0) / totticks c = (ticks - cpu + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(50%, 32%) lset s = string$(c * 50 - 1%, 113%) + "u" s = "t" + right(s, 2%) unless left(s, 1) = "u" s = "x" + right(s, 2%) if left(s, 1) = "u" x = tc * 50 s = "Idle/overhead " & + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " " & + gon + rvon & + left(s, x) + atof + right(s, x+1%) print trm$(s); gof; deol end if end if s = "" when error in s = inkey$(0%, wait 5%) use exit handler if err = 28% continue end when select ascii(s) case 23% gosub showheader case 26% goto quit case 16% gosub savefile if passes > 0 end select passes = passes + 1 next savefile: print esc + "[1;22r" + esc + "[24H" + deol linput "Save file name: "; s print esc + "[r" + esc + "[24H" + deol; open s for output as file #1, recordsize 32767, defaultname "MSYS.LIS" print #1, "CPU time by ";summname; ":"; tab(31%); "From "; & start_time; " to "; current_time print #1 print #1, edit$(left(summname, 1),-1) + right(summname, 2); tab(16); & "Ave % Cur % Graph (|### = average, |--| = current) "; & "COM: " + format$(comcount, "###") print #1, "-----------------------------+" + string$(50%, 45%) for summno = 1 to min(summsize, 17%) if summ(summno)::totcpu > 0% then tc = (summ(summno)::totcpu + 0.0) / totticks c = (summ(summno)::cpu + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(tc * 50, ascii("#")) s = s + string$((c - tc) * 50, ascii("-")) if c > tc x = c * 50% s = left(s, x - 1) + "|" + right(s, x + 1) if x > 0% s = summ(summno)::acc & + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " |" + s print #1, s end if next summno if jpi.nodename = "" then tc = (totticks - totcpu - totidle + 0.0) / totticks c = (ticks - cpu - idle + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(tc * 50, ascii("#")) s = s + string$((c - tc) * 50, ascii("-")) if c > tc x = c * 50% s = left(s, x - 1) + "|" + right(s, x + 1) if x > 0% s = "System overhead" + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " |" + s print #1, s tc = (totidle + 0.0) / totticks c = (idle + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(tc * 50, ascii("#")) s = s + string$((c - tc) * 50, ascii("-")) if c > tc x = c * 50% s = left(s, x - 1) + "|" + right(s, x + 1) if x > 0% s = "Idle " + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " |" + s print #1, s close #1 print esc + "[24;58H(Press Ctrl/Z to exit)"; else tc = (totticks - totcpu + 0.0) / totticks c = (ticks - cpu + 0.0) / ticks tc = 0. if tc < 0. c = 0. if c < 0. s = string$(tc * 50, ascii("#")) s = s + string$((c - tc) * 50, ascii("-")) if c > tc x = c * 50% s = left(s, x - 1) + "|" + right(s, x + 1) if x > 0% s = "Idle/overhead " + format$(tc * 100,"###.##") + " " & + format$(c * 100,"###.##") + " |" + s print #1, s end if return showheader: print home; cls; cr; "CPU time by "; summname; ":"; tab(31%); "From "; & start_time; " to " print print edit$(left(summname, 1),-1) + right(summname, 2); tab(16); print "Ave % Cur % Graph (" + rvon + gon + "x " + atof + gof & + " = average, " + gon + "tqqu" + gof + " = current)" print gon + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqw" + string$(50%, 113%) print esc + "[" + num1$(n) + ";30Hx"; for n = 5% to 23% print gof; esc + "[24;58H(Press Ctrl/Z to exit)"; return errtrap: resume quit if err = 28% resume quit if err = 11% on error go back quit: print atof + gof + esc + esc + "[r" + esc + "[24H" + deol + esc + "[23H" exit program end program