home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: SysTools / SysTools.zip / thes3000.exe / workset2.cmd < prev   
OS/2 REXX Batch file  |  1999-06-04  |  8KB  |  234 lines

  1. /* This REXX command file does the working set computation on a specified
  2.    process or the entire system.  It is kicked off by workset.cmd so that the
  3.    exit list processing can clean up the working set primatives. */
  4.  
  5. parse upper arg All
  6. All = All' terminator'
  7. parse var All Pre '/PLOT' After
  8. if After \= '' then
  9.   PlotSpecified = TRUE
  10. else
  11.   PlotSpecified = FALSE
  12. /*say 'Pre = "'Pre'", After = "'After'", PlotSpecified = 'PlotSpecified*/
  13. parse upper arg Pre '/PLOT' After
  14. All = Pre' 'After
  15.  
  16. parse var All Pre 'FOR ' After
  17. ForSpecified = FALSE
  18. UntilSpecified = FALSE
  19. if After \= '' then
  20.     ForSpecified = TRUE
  21. else
  22.   do
  23.     parse var All Pre 'UNTIL ' After
  24.     if After \= '' then
  25.       UntilSpecified = TRUE
  26.   end
  27. /*say 'Pre = "'Pre'", After = "'After'", ForSpecified = 'ForSpecified', UntilSpecified = 'UntilSpecified*/
  28.  
  29. parse var Pre ProcessName Interval WSIntervals junk
  30. if datatype( ProcessName) = 'NUM' then
  31.   do
  32.     WSIntervals = Interval
  33.     Interval = ProcessName
  34.     ProcessName = 'SYSTEM'
  35.   end
  36. if ProcessName = '' then
  37.   ProcessName = 'SYSTEM'
  38. if datatype( Interval) \= 'NUM' then
  39.   do
  40.     Interval = 5
  41.     WSIntervals = 12
  42.   end
  43. if datatype( WSIntervals) \= 'NUM' then
  44.   WSIntervals = 12
  45.  
  46. if ((ForSpecified = TRUE) & (UntilSpecified = TRUE)) then
  47.   do
  48.     say 'FOR and UNTIL cannot both be specified.'
  49.     ProcessName = '?'
  50.   end
  51.  
  52. if (ForSpecified = TRUE) then
  53.   do
  54.     parse var After Duration ' HOURS'
  55.     if datatype( Duration) \= 'NUM' then
  56.       do
  57.         say '"Duration" is not a number.'
  58.         ProcessName = '?'
  59.       end
  60.     say 'Working set computation will run for 'Duration' hours.'
  61.   end
  62. if (UntilSpecified = TRUE) then
  63.   do
  64.     parse var After ATime AmPm junk
  65.     if datatype( ATime) \= 'NUM' then
  66.       do
  67.         say '"ATime" is not a number.'
  68.         ProcessName = '?'
  69.       end
  70.     if AmPm = 'PM' then
  71.       ATime = ATime + 12
  72.     say 'Working set computation will run until 'ATime':00:00.'
  73.   end
  74. /*say 'ProcessName = "'ProcessName'", Interval = 'Interval', WSIntervals = 'WSIntervals*/
  75.  
  76. if ProcessName = '?' then
  77.   do
  78.     say 'This REXX command file does working set calculation on either the entire system'
  79.     say '  or a specified process.  It uses THESEUS0.DLL.'
  80.     say 'Syntax:'
  81.     say '  "WORKSET [Process] [Interval [WSIntervals]] [FOR n [HOURS] | UNTIL n AM|PM]'
  82.     say '           /PLOT"'
  83.     say 'Where:'
  84.     say '  Process is the name of the process to compute the working set.  If the'
  85.     say '    process is not active, the command file will wait for it to start.  The'
  86.     say '    command file terminates when the program terminates.  If there are multiple'
  87.     say '    processes with the same name, the last one started is used.  If the name'
  88.     say '    "system" is used (or if the name is omitted), the entire system is done.'
  89.     say '  Interval is the sample time in seconds.  Default is 5 seconds.'
  90.     say '  WSIntervals is the number of intervals which constitue the "working set".'
  91.     say '    Default is 12.'
  92.     say '  "FOR n [HOURS]" means to do the run for "n" hours.'
  93.     say '  "UNTIL n AM|PM" means to do the run until "n am" or "n pm".'
  94.     say '  "/PLOT" means to output the data ready for plotting.'
  95.     say 'The inputs are not case sensitive.'
  96.     say 'The command file can be terminated with either Ctrl-C or Ctrl-Break.'
  97.     say 'Example: workset for 5 hours'
  98.     say '  Do working set on the whole system every 5 seconds for 5 hours.'
  99.     say 'Example: workset myprog 10 6 until 10 pm'
  100.     say '  Do working set on the process "myprog" every 10 seconds, with 6 intervals'
  101.     say '   making up the working set, until 10 PM.'
  102.     exit
  103.   end
  104.  
  105. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  106. call RxFuncAdd 'RT2LoadFuncs', 'THESEUS0', 'RT2LoadFuncs'
  107. rc = RT2LoadFuncs()
  108. if rc \= 0 then
  109.   do
  110.     say 'There was an error.'
  111.     exit
  112.   end
  113.  
  114. ProcessPid = 0
  115. LookCount = 0
  116. if ProcessName = 'SYSTEM' then
  117.   do
  118.     say 'Computing the working set of the entire system.'
  119.     rc = RT2WSStart('ws_handle')
  120.     if rc \= 0 then
  121.     do
  122.       say 'Working set start did not occur.  rc = 'rc
  123.       if rc = 2 then
  124.          SAY 'The SYSTEM workset is already running.'
  125.       exit rc
  126.     end
  127.   end
  128. else
  129.   do
  130.     say 'Computing the working set of the process "'ProcessName'".'
  131.     do until ProcessPid \= 0
  132.       call RT2FindProcesses 'pTable'
  133.       do i = 1 to pTable.0
  134.         parse value pTable.i with pid parent threads name
  135.         if name = ProcessName then
  136.           ProcessPid = pid
  137.       end
  138.       if ProcessPid = 0 then
  139.         do
  140.           if LookCount = 0 then
  141.             say 'Waiting until the process is active.  (Will look each second.)'
  142.           LookCount = LookCount + 1
  143.           call SysSleep 1
  144.         end
  145.     end
  146.     say 'The process was found with PID = 'D2X(ProcessPid,4)'.'
  147.     rc = RT2WSStart('ws_handle', ProcessPid);
  148.   end
  149.  
  150. say 'Working set run started at 'time()' on 'date(Language)'.'
  151. say 'Interval is 'Interval' seconds, with 'WSIntervals' intervals in the working set.'
  152. if PlotSpecified = TRUE then
  153.   if ProcessName = 'SYSTEM' then
  154.     say ' time(no colons) RIGHT(now,6,0) RIGHT(ws,6,0) RIGHT(free,6,0)(in Mbytes)'
  155.   else
  156.     say ' time(no colons) RIGHT(now,6,0) RIGHT(ws,6,0) (in Mbytes)'
  157. else
  158.   if ProcessName = 'SYSTEM' then do
  159.     say ' '
  160.     say '        <       Output in pages          >    Number of Processes'
  161.     say '  time     now    ws   accessed free   idle  contributing    Total '
  162.     end
  163.   else
  164.     say '  time     now    ws   accessed  totalRam (in pages)'
  165.  
  166. if (ForSpecified = TRUE) then
  167.   do
  168.     CurrentTime = time('R')
  169.     Duration = Duration * 3600   /* Convert from hours to seconds. */
  170.   end
  171.  
  172. do until always = never
  173.   call SysSleep Interval
  174.   if ProcessName = 'SYSTEM' then
  175.     do
  176.       return = RT2WSSystemTick('ws_handle', WSIntervals)
  177.       parse var return rc now ws accessed free idle pu pt resident total
  178.       if PlotSpecified = TRUE then
  179.         do
  180.           parse value time() with Hours ':' Minutes ':' Seconds
  181.           say Hours''Minutes''Seconds RIGHT(now/256,6,0) RIGHT(ws/256,6,0) RIGHT(free/256,6,0)
  182.         end
  183.       else
  184.         say time() RIGHT(now,6,0) RIGHT(ws,6,0)'  'RIGHT(accessed,6,0) RIGHT(free,6,0) RIGHT(idle,6,0)'    'RIGHT(pu,6,0)'      'RIGHT(pt,6,0)
  185.       DROP now accessed ws free idle pu pt
  186.     end
  187.   else
  188.     do
  189.       return = RT2WSProcessTick('ws_handle', WSIntervals)
  190.       parse var return rc now ws accessed total
  191.       if rc = 5 then
  192.         do
  193.           say 'The process has terminated.  The time is 'time()', the date is 'date(Language)'.'
  194.           call terminate
  195.         end
  196.       else
  197.         if PlotSpecified = TRUE then
  198.           do
  199.             parse value time() with Hours ':' Minutes ':' Seconds
  200.             say Hours''Minutes''Seconds RIGHT(now/256,6,0) RIGHT(ws/256,6,0)
  201.           end
  202.         else
  203.           say time() RIGHT(now,6,0) RIGHT(ws,6,0) RIGHT(accessed,6,0)'     'RIGHT(total,6,0)
  204.     end
  205.  
  206.   if (ForSpecified = TRUE) then
  207.     do
  208.       if (time('E') >= Duration) then
  209.         do
  210.           say 'The run duration has expired.  The time is 'time()', the date is 'date(Language)'.'
  211.           call terminate
  212.         end
  213.     end
  214.   if (UntilSpecified = TRUE) then
  215.     do
  216.       parse value time() with Hours ':' Minutes ':' Seconds
  217.       if (Hours >= ATime) then
  218.         do
  219.           say 'The end run time has occured.  The time is 'time()', the date is 'date(Language)'.'
  220.           call terminate
  221.         end
  222.     end
  223. end
  224.  
  225. terminate:
  226.   return = RT2WSStop('ws_handle')
  227.   parse var return rc count minimum recommended accessed
  228.   say 'There were 'count' samples taken.'
  229.   say 'Absolute minimum number of pages is 'minimum'.'
  230.   say 'Recommended number of pages is      'recommended'.'
  231.   say 'Total number of accessed pages is   'accessed'.'
  232.   exit
  233. return
  234.