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 / mprogs / numsum.icn < prev    next >
Text File  |  2000-07-29  |  3KB  |  104 lines

  1. ############################################################################
  2. #
  3. #    File:     numsum.icn
  4. #
  5. #    Subject:  Program to tabulate numerical computation
  6. #
  7. #    Author:   Ralph E. Griswold
  8. #
  9. #    Date:     September 20, 1994
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  This tool tabulates numerical-computation activity.  It is called as
  18. #
  19. #    numsum prog
  20. #
  21. #  where prog is a program compiled under MT Icon whose events are to
  22. #  be tabulated.
  23. #    
  24. #  The options supported are:
  25. #
  26. #    -o s    write output to file s; default &output.
  27. #
  28. #    -t    record time spent in monitoring.
  29. #
  30. ############################################################################
  31. #
  32. #  Requires:  MT Icon and event monitoring.
  33. #
  34. ############################################################################
  35. #
  36. #  Links:  evinit, options, procname
  37. #
  38. ############################################################################
  39. #
  40. #  Includes:  evdefs.icn
  41. #
  42. ############################################################################
  43.  
  44. link evinit
  45. link options
  46. link procname
  47.  
  48. $include "evdefs.icn"
  49.  
  50. procedure main(args)
  51.    local opts, itime, output, inttbl, reltbl, cmask, rmask, numlist, op
  52.    local pos, neg, plus, minus, mpy, div, pwr, mod, count
  53.  
  54.    opts := options(args, "o:t")
  55.  
  56.    output := open(\opts["o"], "w") | &output
  57.  
  58.    if \opts["t"] then itime := &time
  59.  
  60.    EvInit(args) | stop("*** cannot load program")    # initialize interface
  61.  
  62.    inttbl := table(0)
  63.    reltbl := table(0)
  64.  
  65.    cmask := E_Fcall ++ E_Ocall
  66.    rmask := E_Fret ++ E_Oret ++ E_Ffail ++ E_Ofail
  67.  
  68.    pos := proc("+", 1)
  69.    neg := proc("-", 1)
  70.    plus := proc("+", 2)
  71.    minus := proc("-", 2)
  72.    mpy := proc("*", 2)
  73.    div := proc("/", 2)
  74.    mod := proc("%", 2)
  75.    pwr := proc("^", 2)
  76.  
  77.    while EvGet(cmask) do {
  78.       if (op := &eventvalue) === (
  79.          plus | minus | mpy | div | neg | pwr | mod |
  80.          iand | ior | ixor | icom | ishift | pos
  81.          )  then {
  82.             EvGet(rmask)
  83.             if &eventcode === (E_Ofail | E_Ffail) then next
  84.             case type(&eventvalue) of {
  85.                "integer":  inttbl[op] +:= 1
  86.                "real":     reltbl[op] +:= 1
  87.                }
  88.             }
  89.       }
  90.  
  91.    write(output, "\nInteger computation:\n")
  92.    numlist := sort(inttbl, 4)
  93.    while count := pull(numlist) do
  94.       write(output, left(procname(pull(numlist)), 6), right(count, 9))
  95.  
  96.    write(output, "\nReal computation:\n")
  97.    numlist := sort(reltbl, 4)
  98.    while count := pull(numlist) do
  99.       while write(output, left(procname(pull(numlist)), 6), right(count, 9))
  100.  
  101.    write(output, "\nelapsed time: ", &time - \itime, "ms")
  102.  
  103. end
  104.