summaryrefslogtreecommitdiff
path: root/ipl/progs/itrcsum.icn
blob: 04df21753b603e593203a8266a5717c7abe95309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
############################################################################
#
#	File:     itrcsum.icn
#
#	Subject:  Program to give summary of trace output
#
#	Author:   Ralph E. Griswold
#
#	Date:     July 14, 1997
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program provides a summary of Icon trace output.
#
############################################################################
#
#  Links: itrcline, numbers
#
############################################################################

link itrcline
link numbers

$define CountWidth 10

procedure main()
   local line, file_tbl, call_tbl, return_tbl, fail_tbl, suspend_tbl
   local resume_tbl, max, ave, count, file, bars, depth, keys, width

   file_tbl := table(0)
   call_tbl := table(0)
   return_tbl := table(0)
   suspend_tbl := table(0)
   fail_tbl := table(0)
   resume_tbl := table(0)

   max := 0
   ave := 0
   count := 0

   while line := itrcline(&input) do {
      line ? {
         file := move(13) | break		# line after trace output?
         count +:= 1
         if trim(file) == "" then file := "(none)       "
         file_tbl[file] +:= 1
         move(8)				# line number field
         if bars := tab(many('| ')) then {	# depth bars
            depth := *bars / 2			# recursion depth
            max <:= depth			# maximum depth
            ave +:= depth			# cumulative depth
            }
         name := tab(upto('( '))		# procedure name
         tab(bal(' ') | 0)			# skip arguments (faulty)
         if pos(0) then {
            call_tbl[name] +:= 1
            next
            }
         if =" returned" then return_tbl[name] +:= 1
         else if =" failed" then fail_tbl[name] +:= 1
         else if =" suspended" then suspend_tbl[name] +:= 1
         else if =" resumed" then resume_tbl[name] +:= 1 
         }
      }

   if count = 0 then {
      write("no trace output")
      exit()
      }

   write("maximum recursion depth = ", max)
   write("average recursion depth = ", fix(ave, count, 5, 3))
   write()
   write("File references:\n")
   file_tbl := sort(file_tbl, 3)
   while write(get(file_tbl), right(get(file_tbl), 10))
   write("\nprocedure activity:\n")

   keys := []
   every put(keys, key(call_tbl))

   width := 0
   every width <:= *!keys
   width +:= 2

   write(
      left("name", width),
      right("call", CountWidth),
      right("return", CountWidth),
      right("suspend", CountWidth),
      right("fail", CountWidth),
      right("resume", CountWidth),
      "\n"
      )

   every name := !sort(keys) do
      write(
         left(name, width),
         right(call_tbl[name], CountWidth),
         right(return_tbl[name], CountWidth),
         right(suspend_tbl[name], CountWidth),
         right(fail_tbl[name], CountWidth),
         right(resume_tbl[name], CountWidth)
      )
   
end