24
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
120
|
13 |
Object subclass:#ProfileTree
|
236
|
14 |
instanceVariableNames:'receiver selector class leafTally totalTally called isBlock'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Debugging-Support'
|
22
|
18 |
!
|
|
19 |
|
23
|
20 |
!ProfileTree class methodsFor:'documentation'!
|
|
21 |
|
24
|
22 |
copyright
|
|
23 |
"
|
|
24 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
25 |
All Rights Reserved
|
|
26 |
|
|
27 |
This software is furnished under a license and may be used
|
|
28 |
only in accordance with the terms of that license and with the
|
|
29 |
inclusion of the above copyright notice. This software may not
|
|
30 |
be provided or otherwise made available to, or used by, any
|
|
31 |
other person. No title to or ownership of the software is
|
|
32 |
hereby transferred.
|
|
33 |
"
|
22
|
34 |
!
|
|
35 |
|
88
|
36 |
documentation
|
|
37 |
"
|
|
38 |
This is is used as a companion to MessageTally.
|
|
39 |
Instances of it are used to represent the calling tree.
|
236
|
40 |
|
|
41 |
[author:]
|
|
42 |
Claus Gittinger
|
88
|
43 |
"
|
22
|
44 |
! !
|
|
45 |
|
|
46 |
!ProfileTree methodsFor:'accessing'!
|
|
47 |
|
88
|
48 |
called
|
|
49 |
^ called
|
22
|
50 |
!
|
|
51 |
|
|
52 |
called:aCollection
|
|
53 |
called := aCollection
|
|
54 |
!
|
|
55 |
|
88
|
56 |
isBlock
|
|
57 |
^ isBlock
|
22
|
58 |
!
|
|
59 |
|
|
60 |
isBlock:aBoolean
|
|
61 |
isBlock := aBoolean
|
|
62 |
!
|
|
63 |
|
88
|
64 |
leafTally
|
|
65 |
^ leafTally
|
22
|
66 |
!
|
|
67 |
|
88
|
68 |
methodClass
|
|
69 |
^ class
|
22
|
70 |
!
|
|
71 |
|
88
|
72 |
receiver
|
|
73 |
^ receiver
|
22
|
74 |
!
|
|
75 |
|
|
76 |
receiver:r selector:s class:cls
|
|
77 |
receiver := r.
|
|
78 |
selector := s.
|
|
79 |
class := cls
|
|
80 |
!
|
|
81 |
|
88
|
82 |
selector
|
|
83 |
^ selector
|
|
84 |
!
|
|
85 |
|
22
|
86 |
totalTally
|
|
87 |
^ totalTally
|
|
88 |
! !
|
|
89 |
|
|
90 |
!ProfileTree methodsFor:'adding info'!
|
|
91 |
|
|
92 |
addChain:aCallChain
|
|
93 |
|node found subTree chain called|
|
|
94 |
|
|
95 |
node := self.
|
|
96 |
chain := aCallChain.
|
|
97 |
|
|
98 |
[chain notNil] whileTrue:[
|
|
99 |
node incrementTotalTally.
|
|
100 |
|
|
101 |
found := false.
|
|
102 |
(called := node called) notNil ifTrue:[
|
|
103 |
called do:[:subTree |
|
|
104 |
found ifFalse:[
|
|
105 |
(chain = subTree) ifTrue:[
|
|
106 |
node := subTree.
|
|
107 |
chain := chain rest.
|
|
108 |
found := true
|
|
109 |
].
|
|
110 |
].
|
|
111 |
].
|
|
112 |
] ifFalse:[
|
|
113 |
node called:(OrderedCollection new)
|
|
114 |
].
|
|
115 |
found ifFalse:[
|
|
116 |
subTree := ProfileTree new.
|
|
117 |
subTree receiver:chain receiver
|
|
118 |
selector:chain selector
|
|
119 |
class:chain methodClass.
|
|
120 |
subTree isBlock:(chain isBlock).
|
|
121 |
|
|
122 |
node called add:subTree.
|
|
123 |
node := subTree.
|
|
124 |
chain := chain rest
|
|
125 |
]
|
|
126 |
|
|
127 |
].
|
|
128 |
|
|
129 |
node incrementTotalTally.
|
|
130 |
node incrementLeafTally.
|
|
131 |
!
|
|
132 |
|
88
|
133 |
computePercentage:total
|
|
134 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
135 |
leafTally notNil ifTrue:[
|
|
136 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
|
137 |
].
|
|
138 |
|
|
139 |
called notNil ifTrue:[
|
|
140 |
called do:[:subTree |
|
|
141 |
subTree computePercentage:total
|
|
142 |
]
|
|
143 |
].
|
|
144 |
!
|
|
145 |
|
|
146 |
incrementLeafTally
|
|
147 |
leafTally isNil ifTrue:[
|
|
148 |
leafTally := 1
|
|
149 |
] ifFalse:[
|
|
150 |
leafTally := leafTally + 1.
|
|
151 |
].
|
|
152 |
!
|
|
153 |
|
22
|
154 |
incrementTotalTally
|
|
155 |
totalTally isNil ifTrue:[
|
|
156 |
totalTally := 1
|
|
157 |
] ifFalse:[
|
|
158 |
totalTally := totalTally + 1.
|
|
159 |
].
|
|
160 |
!
|
|
161 |
|
|
162 |
leafTally:aCount
|
|
163 |
leafTally := aCount
|
|
164 |
!
|
|
165 |
|
|
166 |
totalTally:aCount
|
|
167 |
totalTally := aCount
|
|
168 |
! !
|
|
169 |
|
88
|
170 |
!ProfileTree methodsFor:'prettyPrinting'!
|
|
171 |
|
|
172 |
printLeafsOn:aStream
|
|
173 |
|leafNodes|
|
|
174 |
|
|
175 |
leafNodes := OrderedCollection new.
|
|
176 |
self addLeafNodesTo:leafNodes.
|
|
177 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
|
178 |
a leafTally < b leafTally].
|
|
179 |
leafNodes do:[:aNode |
|
|
180 |
aNode printSingleOn:aStream.
|
|
181 |
aStream cr.
|
|
182 |
].
|
|
183 |
!
|
|
184 |
|
|
185 |
printOn:aStream
|
|
186 |
|s|
|
|
187 |
|
|
188 |
"/ self printOn:aStream indent:0
|
|
189 |
s := WriteStream on:String new.
|
|
190 |
self printOn:s indent:0.
|
|
191 |
|
|
192 |
aStream nextPutAll:s contents
|
|
193 |
!
|
|
194 |
|
|
195 |
printOn:aStream indent:i
|
|
196 |
selector notNil ifTrue:[
|
|
197 |
aStream spaces:i.
|
|
198 |
self printSingleOn:aStream.
|
|
199 |
aStream cr.
|
|
200 |
].
|
|
201 |
|
|
202 |
called notNil ifTrue:[
|
|
203 |
called do:[:sub|
|
|
204 |
sub printOn:aStream indent:(i + 1)
|
|
205 |
].
|
|
206 |
].
|
|
207 |
!
|
|
208 |
|
|
209 |
printSingleOn:aStream
|
|
210 |
selector notNil ifTrue:[
|
|
211 |
isBlock == true ifTrue:[
|
|
212 |
'[] in ' printOn:aStream
|
|
213 |
].
|
|
214 |
receiver name printOn:aStream.
|
|
215 |
(class notNil and:[class ~~ receiver class]) ifTrue:[
|
|
216 |
'>>' printOn:aStream.
|
|
217 |
class name printOn:aStream
|
|
218 |
].
|
|
219 |
aStream space.
|
|
220 |
selector printOn:aStream.
|
|
221 |
aStream space.
|
|
222 |
|
|
223 |
aStream nextPutAll:'(total '.
|
|
224 |
totalTally printOn:aStream.
|
|
225 |
aStream nextPutAll:'%)'.
|
|
226 |
|
|
227 |
leafTally notNil ifTrue:[
|
|
228 |
aStream nextPutAll:'(leaf '.
|
|
229 |
leafTally printOn:aStream.
|
|
230 |
aStream nextPutAll:'%)'.
|
|
231 |
].
|
|
232 |
].
|
|
233 |
! !
|
|
234 |
|
22
|
235 |
!ProfileTree methodsFor:'private'!
|
|
236 |
|
88
|
237 |
= aProfileTreeNode
|
|
238 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
|
239 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
240 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
241 |
^ true
|
|
242 |
!
|
|
243 |
|
22
|
244 |
addLeafNodesTo:aCollection
|
|
245 |
|idx|
|
|
246 |
|
|
247 |
leafTally notNil ifTrue:[
|
23
|
248 |
idx := aCollection indexOf:self.
|
|
249 |
idx == 0 ifTrue:[
|
|
250 |
aCollection add:self copy
|
|
251 |
] ifFalse:[
|
|
252 |
|nd|
|
22
|
253 |
|
23
|
254 |
nd := aCollection at:idx.
|
|
255 |
nd leafTally:(nd leafTally + leafTally).
|
|
256 |
nd totalTally:(nd totalTally max: totalTally)
|
|
257 |
]
|
22
|
258 |
].
|
|
259 |
called notNil ifTrue:[
|
23
|
260 |
called do:[:aNode |
|
|
261 |
aNode addLeafNodesTo:aCollection
|
|
262 |
]
|
22
|
263 |
]
|
88
|
264 |
! !
|
22
|
265 |
|
98
|
266 |
!ProfileTree class methodsFor:'documentation'!
|
|
267 |
|
|
268 |
version
|
236
|
269 |
^ '$Header: /cvs/stx/stx/libbasic3/ProfileTree.st,v 1.11 1996-04-25 17:11:26 cg Exp $'
|
98
|
270 |
! !
|