summaryrefslogtreecommitdiff
path: root/ipl/mprogs/callcnt.icn
blob: c4063cf52d703f34d52b6d7c33fe10665483c9cd (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
111
112
113
114
115
116
117
118
119
120
121
122
############################################################################
#
#	File:     callcnt.icn
#
#	Subject:  Program to count calls
#
#	Author:   Ralph E. Griswold
#
#	Date:     June 8, 1994
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  This program tabulates calls in a monitored program.
#
############################################################################
#
#  Links:  evinit, opsyms
#
############################################################################
#
#  Requires:  MT Icon and event monitoring
#
############################################################################
#
#  Includes:  evdefs.icn
#
############################################################################

link evinit
link opsyms

$include "evdefs.icn"

procedure main(args)
   local opertable, fnctable, rectable, proctable, opmap, output, mask, oper
   local count, fnc

   EvInit(args)

   opertable := table(0)
   fnctable := table(0)
   proctable := table(0)

   opmap := opsyms()

   output := open("callcnt", "x", "height=800",	# If this fails, output goes to
      "width=200")				# standard output

   write(output, " Tabulating calls for ", args[1])

   mask := E_Ocall ++ E_Fcall ++ E_Pcall

   while EvGet(mask) do
      case &eventcode of {
         E_Ocall:  opertable[&eventvalue] +:= 1
         E_Fcall:  fnctable[&eventvalue] +:= 1
         E_Pcall:  proctable[&eventvalue] +:= 1
         }

   opertable := sort(opertable,3)
   fnctable := sort(fnctable,3)
   rectable :=copy(fnctable)
   proctable := sort(proctable,3)

   write(output, "\n operation calls\n")
   while oper := get(opertable) do {
      count := get(opertable)
      write(output, " ", left(\opmap[oper], 20), right(count, 7))
      }

   write(output, "\n function calls\n")
   while fnc := get(fnctable) do {
      count := get(fnctable)
      write(output, " ", left(fname(fnc), 20), right(count, 7))
      }

   write(output, "\n record constructor calls\n")
   while fnc := get(rectable) do {
      count := get(rectable)
      write(output, " ", left(cname(fnc), 20), right(count, 7))
      }

   write(output, "\n procedure calls\n")
   while write(output, " ", left(pname(get(proctable)), 20),
      right(get(proctable), 7))

   Event(\output)				# wait for event if window

end

procedure cname(f)

   return image(f) ? {
      ="function "
      if ="record constructor " then return tab(0)
      else fail
      }

end

procedure fname(f)

   return image(f) ? {
      ="function "
      if ="record constructor " then fail
      else tab(0)
      }

end

procedure pname(p)

   return image(p) ? {
      ="procedure "
      tab(0)
      }

end