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

  1. /* Do leak detection on the specified process. */
  2. parse upper arg Pre 'FOR ' After
  3. ForSpecified = FALSE
  4. UntilSpecified = FALSE
  5. if After \= '' then
  6.   ForSpecified = TRUE
  7. else
  8.   do
  9.     parse upper arg Pre 'UNTIL ' After
  10.     if After \= '' then
  11.       UntilSpecified = TRUE
  12.   end
  13. /*say 'Pre = 'Pre', After = 'After', ForSpecified = 'ForSpecified', UntilSpecified = 'UntilSpecified*/
  14.  
  15. parse var Pre ProcessName DelayValue junk
  16. /*
  17. if datatype( ProcessName) = 'NUM' then
  18.   do
  19.     DelayValue = ProcessName
  20.     ProcessName = 'SYSTEM'
  21.   end
  22.   */
  23. if ProcessName = '' then
  24.   ProcessName = 'SYSTEM'
  25.  
  26. if datatype( DelayValue) \= 'NUM' then
  27.   DelayValue = 30
  28.  
  29. if ((ForSpecified = TRUE) & (UntilSpecified = TRUE)) then
  30.   do
  31.     say 'FOR and UNTIL cannot both be specified.'
  32.     ProcessName = '?'
  33.   end
  34.  
  35. if (ForSpecified = TRUE) then
  36.   do
  37.     parse var After Duration ' HOURS'
  38.     if datatype( Duration) \= 'NUM' then
  39.       do
  40.         say '"Duration" is not a number.'
  41.         ProcessName = '?'
  42.       end
  43.     say 'Leak detection will run for 'Duration' hours.'
  44.   end
  45. if (UntilSpecified = TRUE) then
  46.   do
  47.     parse var After ATime AmPm junk
  48.     if datatype( ATime) \= 'NUM' then
  49.       do
  50.         say '"ATime" is not a number.'
  51.         ProcessName = '?'
  52.       end
  53.     if AmPm = 'PM' then
  54.       ATime = ATime + 12
  55.     say 'Leak detection will run until 'ATime':00:00.'
  56.   end
  57.  
  58. if ProcessName = '?' then
  59.   do
  60.     say 'This REXX command file does memory leak detection on either the entire system'
  61.     say '  or a specified process.  It uses both THESEUS0.DLL and THESEUS1.DLL.'
  62.     say 'Syntax: "LEAKDET ProcessName [DelayValue] [FOR n [HOURS] | UNTIL n AM|PM]"'
  63.     say 'Where:'
  64.     say '  ProcessName is the name of the process to check for memory leaks.  If the'
  65.     say '    process is not active, the command file will wait for it to start.  The'
  66.     say '    command file terminates when the program terminates.  If there are multiple'
  67.     say '    processes with the same name, the last one started is used.  If the name'
  68.     say '    "system" is used (or if the name is omitted), the entire system is checked.'
  69.     say '  DelayValue is the number of seconds to delay between leak detection passes.'
  70.     say '    If no value is specified, the default is 30 seconds.'
  71.     say '  "FOR n [HOURS]" means to do the run for "n" hours.'
  72.     say '  "UNTIL n AM|PM" means to do the run until "n am" or "n pm".'
  73.     say 'The inputs are not case sensitive.'
  74.     say 'The command file can be terminated with either Ctrl-C or Ctrl-Break.'
  75.     say 'Example: leakdet for 5 hours'
  76.     say '  Do leak detection on the whole system at a 30 second rate for 5 hours.'
  77.     say 'Example: leakdet myprog 60 until 10 pm'
  78.     say '  Do leak detection on the process "myprog" every 60 seconds until 10 PM.'
  79.     exit
  80.   end
  81.  
  82. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  83. call RxFuncAdd 'RT2LoadFuncs', 'THESEUS0', 'RT2LoadFuncs'
  84. rc = RT2LoadFuncs()
  85. if rc \= 0 then
  86.   do
  87.     say 'There was an error.'
  88.     exit
  89.   end
  90. call RxFuncAdd 'RT2LoadFuncs1', 'THESEUS1', 'RT2LoadFuncs1'
  91. rc = RT2LoadFuncs1()
  92. if rc \= 0 then
  93.   do
  94.     say 'There was an error.'
  95.     exit
  96.   end
  97.  
  98. ProcessPid = 0
  99. LookCount = 0
  100. if ProcessName = 'SYSTEM' then
  101.   do
  102.     say 'Leak detecting the entire system at 'DelayValue' second rate.'
  103.     rc = RT2LeakStart('leak_handle');
  104.   end
  105. else
  106.   do
  107.     do until ProcessPid \= 0
  108.       call RT2FindProcesses 'pTable'
  109.       if datatype( ProcessName) = 'NUM' then
  110.          do i= 1 to pTable.0
  111.            parse value pTable.i with pid parent threads name
  112.            if ProcessName = pid then
  113.              do
  114.                 ProcessPid = pid
  115.                 ProcessName = name
  116.                 leave
  117.              end
  118.          end
  119.       else
  120.          do i = 1 to pTable.0
  121.            parse value pTable.i with pid parent threads name
  122.            if name = ProcessName then
  123.              ProcessPid = pid
  124.          end
  125.       if ProcessPid = 0 then
  126.         do
  127.           if LookCount = 0 then
  128.             say 'Waiting until the process is active.  (Will look each second.)'
  129.           LookCount = LookCount + 1
  130.           call SysSleep 1
  131.         end
  132.     end
  133.     say 'Leak detecting process "'ProcessName'", at 'DelayValue' second rate.'
  134. /*  say 'The process was found with PID = 'ProcessPid'.'*/
  135.     rc = RT2LeakStart('leak_handle', ProcessPid);
  136.   end
  137.  
  138. say 'Leak detection run started at 'time()' on 'date(Language)'.'
  139.  
  140. if (ForSpecified = TRUE) then
  141.   do
  142.     CurrentTime = time('R')
  143.     Duration = Duration * 3600   /* Convert from hours to seconds. */
  144.   end
  145.  
  146. do until always = never
  147.   call SysSleep DelayValue
  148.   say
  149.   /* In the RT2LeakTick call, the second parameter is a boolean as to whether
  150.      or not to use the previous data as the base data.  0 = no, 1 = yes. */
  151.   rc = RT2LeakTick('leak_handle', 1)
  152.   if (ForSpecified = TRUE) then
  153.     do
  154.       if (time('E') >= Duration) then
  155.         do
  156.           say 'The run duration has expired.  The time is 'time()', the date is 'date(Language)'.'
  157.           exit
  158.         end
  159.     end
  160.   if (UntilSpecified = TRUE) then
  161.     do
  162.       parse value time() with Hours ':' Minutes ':' Seconds
  163.       if (Hours >= ATime) then
  164.         do
  165.           say 'The end run time has occured.  The time is 'time()', the date is 'date(Language)'.'
  166.           exit
  167.         end
  168.     end
  169.   if rc = -2 then
  170.     do
  171.       say 'The process has terminated.  The time is 'time()', the date is 'date(Language)'.'
  172.       exit
  173.     end
  174.   else
  175.     say 'Leak detection run at 'time()' on 'date(Language)'.'
  176. end
  177.