home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / itrcsum.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  111 lines

  1. ############################################################################
  2. #
  3. #    File:     itrcsum.icn
  4. #
  5. #    Subject:  Program to give summary of trace output
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     July 14, 1997
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This program provides a summary of Icon trace output.
  18. #
  19. ############################################################################
  20. #
  21. #  Links: itrcline, numbers
  22. #
  23. ############################################################################
  24.  
  25. link itrcline
  26. link numbers
  27.  
  28. $define CountWidth 10
  29.  
  30. procedure main()
  31.    local line, file_tbl, call_tbl, return_tbl, fail_tbl, suspend_tbl
  32.    local resume_tbl, max, ave, count, file, bars, depth, keys, width
  33.  
  34.    file_tbl := table(0)
  35.    call_tbl := table(0)
  36.    return_tbl := table(0)
  37.    suspend_tbl := table(0)
  38.    fail_tbl := table(0)
  39.    resume_tbl := table(0)
  40.  
  41.    max := 0
  42.    ave := 0
  43.    count := 0
  44.  
  45.    while line := itrcline(&input) do {
  46.       line ? {
  47.          file := move(13) | break        # line after trace output?
  48.          count +:= 1
  49.          if trim(file) == "" then file := "(none)       "
  50.          file_tbl[file] +:= 1
  51.          move(8)                # line number field
  52.          if bars := tab(many('| ')) then {    # depth bars
  53.             depth := *bars / 2            # recursion depth
  54.             max <:= depth            # maximum depth
  55.             ave +:= depth            # cumulative depth
  56.             }
  57.          name := tab(upto('( '))        # procedure name
  58.          tab(bal(' ') | 0)            # skip arguments (faulty)
  59.          if pos(0) then {
  60.             call_tbl[name] +:= 1
  61.             next
  62.             }
  63.          if =" returned" then return_tbl[name] +:= 1
  64.          else if =" failed" then fail_tbl[name] +:= 1
  65.          else if =" suspended" then suspend_tbl[name] +:= 1
  66.          else if =" resumed" then resume_tbl[name] +:= 1 
  67.          }
  68.       }
  69.  
  70.    if count = 0 then {
  71.       write("no trace output")
  72.       exit()
  73.       }
  74.  
  75.    write("maximum recursion depth = ", max)
  76.    write("average recursion depth = ", fix(ave, count, 5, 3))
  77.    write()
  78.    write("File references:\n")
  79.    file_tbl := sort(file_tbl, 3)
  80.    while write(get(file_tbl), right(get(file_tbl), 10))
  81.    write("\nprocedure activity:\n")
  82.  
  83.    keys := []
  84.    every put(keys, key(call_tbl))
  85.  
  86.    width := 0
  87.    every width <:= *!keys
  88.    width +:= 2
  89.  
  90.    write(
  91.       left("name", width),
  92.       right("call", CountWidth),
  93.       right("return", CountWidth),
  94.       right("suspend", CountWidth),
  95.       right("fail", CountWidth),
  96.       right("resume", CountWidth),
  97.       "\n"
  98.       )
  99.  
  100.    every name := !sort(keys) do
  101.       write(
  102.          left(name, width),
  103.          right(call_tbl[name], CountWidth),
  104.          right(return_tbl[name], CountWidth),
  105.          right(suspend_tbl[name], CountWidth),
  106.          right(fail_tbl[name], CountWidth),
  107.          right(resume_tbl[name], CountWidth)
  108.       )
  109.    
  110. end
  111.