home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rox.zip / roxprof.cmd < prev    next >
OS/2 REXX Batch file  |  1994-04-13  |  4KB  |  165 lines

  1. /*------------------------------------------------------------------
  2.  * roxprof.cmd :
  3.  *------------------------------------------------------------------
  4.  * 04-12-94 originally by Patrick J. Mueller
  5.  *------------------------------------------------------------------*/
  6.  
  7. numeric digits 15
  8.  
  9. parse arg iFile kind .
  10. if (iFile = "") | (iFile = "?") then
  11.    Usage()
  12.  
  13. kind = translate(kind)
  14.  
  15. if (kind = "") then kind = "TIME"
  16.  
  17. if (kind = "TIME") then signal TimeStats
  18.  
  19. if (kind = "FLOW") then signal FlowStats
  20.  
  21. /*------------------------------------------------------------------
  22.  * execution time stats
  23.  *------------------------------------------------------------------*/
  24. TimeStats:
  25.  
  26. table.  = ""
  27. table.0 = 0
  28.  
  29. stack   = 0
  30. stack.0 = 0
  31.  
  32. /*------------------------------------------------------------------
  33.  * collect info
  34.  *------------------------------------------------------------------*/
  35. do while (lines(iFile) <> 0)
  36.    line = linein(iFile)
  37.    if (word(line,1) <> "stat:") then
  38.       iterate
  39.  
  40.    parse var line . which method time
  41.  
  42.    if (which = "entry") then
  43.       do
  44.       push method time
  45.       stack = stack + 1
  46.       stack.stack = 0
  47.       iterate
  48.       end
  49.  
  50.    parse pull bMethod bTime
  51.  
  52.    if (method <> bMethod) then
  53.       do
  54.       say "invalid stat sequence!"
  55.       exit
  56.       end
  57.  
  58.    elapsed = time - bTime
  59.  
  60.    if (table.method = "") then
  61.       do
  62.       o = table.0 + 1
  63.       table.0 = o
  64.       table.o = method
  65.       table.method = o
  66.  
  67.       table.o.!count = 0
  68.       table.o.!total = 0
  69.       table.o.!atime = 0
  70.       table.o.!max   = 0
  71.       table.o.!min   = 0
  72.       end
  73.  
  74.     index = table.method
  75.  
  76.     table.index.!count = table.index.!count + 1
  77.     table.index.!total = table.index.!total + elapsed
  78.  
  79.     if (table.index.!max = 0) | (table.index.!max < elapsed) then
  80.        table.index.!max = elapsed
  81.  
  82.     if (table.index.!min = 0) | (table.index.!min > elapsed) then
  83.        table.index.!min = elapsed
  84.  
  85.     prevStack = stack - 1
  86.     stack.prevStack = stack.prevStack + elapsed
  87.  
  88.     table.index.!atime = table.index.!atime + elapsed - stack.stack
  89.  
  90.     stack = stack - 1
  91. end
  92.  
  93. rc = stream(iFile,"C","CLOSE")
  94.  
  95. /*------------------------------------------------------------------
  96.  * print info
  97.  *------------------------------------------------------------------*/
  98.  
  99. say "   calls tot.time act.time      avg      max      min  method "
  100. say "-------- -------- -------- --------  ------- --------  ------------------"
  101. do i = 1 to table.0
  102.    count = right(table.i.!count,8)
  103.    total = r8(table.i.!total)
  104.    atime = r8(table.i.!atime)
  105.    max   = r8(table.i.!max)
  106.    min   = r8(table.i.!min)
  107.    avg   = r8(total / count)
  108.  
  109.    say count total atime avg max min " "table.i
  110. end
  111.  
  112. exit
  113.  
  114. /*------------------------------------------------------------------
  115.  *
  116.  *------------------------------------------------------------------*/
  117. FlowStats:
  118.  
  119. indent = 0
  120.  
  121. /*------------------------------------------------------------------
  122.  * collect info
  123.  *------------------------------------------------------------------*/
  124. do while (lines(iFile) <> 0)
  125.    line = linein(iFile)
  126.    if (word(line,1) <> "stat:") then
  127.       iterate
  128.  
  129.    parse var line . which method time
  130.  
  131.    if (which = "entry") then
  132.       do
  133.       say copies(" ",indent) || method
  134.       indent = indent + 1
  135.       end
  136.  
  137.    else
  138.       indent = indent - 1
  139. end
  140.  
  141. rc = stream(iFile,"C","CLOSE")
  142.  
  143. exit
  144.  
  145. /*------------------------------------------------------------------
  146.  * lrl
  147.  *------------------------------------------------------------------*/
  148. r8:
  149.    return format(arg(1),4,3)
  150.  
  151. /*------------------------------------------------------------------
  152.  * some simple help
  153.  *------------------------------------------------------------------*/
  154. Usage: procedure
  155.    parse source os . me .
  156.    if (os = "OS/2") then parse value filespec("name",me) with me "." .
  157.  
  158.    say "usage:"
  159.    say "   " me "<inputFile> [TIME | FLOW]"
  160.    say "is used to print ROX profile information collected by turning"
  161.    say "on the RoxStats() function.  Timing information or flow information"
  162.    say "will be printed depending on the second parameter (default=TIME)"
  163.  
  164.    exit
  165.