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.
|
261
|
39 |
Instances of it are used to represent a calling chain.
|
|
40 |
(MessageTally could have used the contexts themself, but these
|
|
41 |
may create more overhead)
|
236
|
42 |
|
|
43 |
[author:]
|
|
44 |
Claus Gittinger
|
261
|
45 |
|
|
46 |
[see also:]
|
|
47 |
MessageTally CallChain
|
|
48 |
MessageTracer
|
|
49 |
AbstractTime
|
88
|
50 |
"
|
22
|
51 |
! !
|
|
52 |
|
|
53 |
!ProfileTree methodsFor:'accessing'!
|
|
54 |
|
88
|
55 |
called
|
261
|
56 |
"return the trees of the called methods/blocks"
|
|
57 |
|
88
|
58 |
^ called
|
261
|
59 |
|
|
60 |
"Modified: 18.5.1996 / 19:00:59 / cg"
|
22
|
61 |
!
|
|
62 |
|
|
63 |
called:aCollection
|
261
|
64 |
"set the trees of the called methods/blocks"
|
|
65 |
|
22
|
66 |
called := aCollection
|
261
|
67 |
|
|
68 |
"Modified: 18.5.1996 / 19:01:08 / cg"
|
22
|
69 |
!
|
|
70 |
|
88
|
71 |
isBlock
|
261
|
72 |
"return true, if this is a tree for a block-context"
|
22
|
73 |
|
261
|
74 |
^ isBlock
|
|
75 |
|
|
76 |
"Modified: 18.5.1996 / 18:59:12 / cg"
|
22
|
77 |
!
|
|
78 |
|
88
|
79 |
leafTally
|
261
|
80 |
"return true, if this is a leaf"
|
|
81 |
|
88
|
82 |
^ leafTally
|
261
|
83 |
|
|
84 |
"Modified: 18.5.1996 / 19:01:27 / cg"
|
22
|
85 |
!
|
|
86 |
|
88
|
87 |
methodClass
|
261
|
88 |
"return the contexts methods class"
|
|
89 |
|
|
90 |
^ class
|
|
91 |
|
|
92 |
"Modified: 18.5.1996 / 19:01:40 / cg"
|
22
|
93 |
!
|
|
94 |
|
88
|
95 |
receiver
|
261
|
96 |
"return the contexts receiver"
|
|
97 |
|
88
|
98 |
^ receiver
|
261
|
99 |
|
|
100 |
"Modified: 18.5.1996 / 19:01:45 / cg"
|
22
|
101 |
!
|
|
102 |
|
|
103 |
receiver:r selector:s class:cls
|
261
|
104 |
"private tally interface - set receiver, selector and class.
|
|
105 |
the block flag is cleared."
|
|
106 |
|
22
|
107 |
receiver := r.
|
|
108 |
selector := s.
|
|
109 |
class := cls
|
261
|
110 |
|
|
111 |
"Modified: 18.5.1996 / 19:01:52 / cg"
|
|
112 |
!
|
|
113 |
|
|
114 |
receiver:r selector:s class:cls isBlock:blk
|
|
115 |
"private tally interface - set receiver, selector, class
|
|
116 |
and the block flag."
|
|
117 |
|
|
118 |
receiver := r.
|
|
119 |
selector := s.
|
|
120 |
class := cls.
|
|
121 |
isBlock := blk
|
|
122 |
|
|
123 |
"Modified: 18.5.1996 / 19:01:57 / cg"
|
22
|
124 |
!
|
|
125 |
|
88
|
126 |
selector
|
261
|
127 |
"return the contexts selector"
|
|
128 |
|
88
|
129 |
^ selector
|
261
|
130 |
|
|
131 |
"Modified: 18.5.1996 / 19:02:04 / cg"
|
88
|
132 |
!
|
|
133 |
|
22
|
134 |
totalTally
|
261
|
135 |
"return the total tally counter"
|
|
136 |
|
22
|
137 |
^ totalTally
|
261
|
138 |
|
|
139 |
"Modified: 18.5.1996 / 19:02:15 / cg"
|
22
|
140 |
! !
|
|
141 |
|
|
142 |
!ProfileTree methodsFor:'adding info'!
|
|
143 |
|
|
144 |
addChain:aCallChain
|
263
|
145 |
"{ Pragma: +optSpeed }"
|
|
146 |
|
261
|
147 |
"merge a chain into the receviers tree"
|
|
148 |
|
22
|
149 |
|node found subTree chain called|
|
|
150 |
|
|
151 |
node := self.
|
|
152 |
chain := aCallChain.
|
|
153 |
|
|
154 |
[chain notNil] whileTrue:[
|
261
|
155 |
node incrementTotalTally.
|
22
|
156 |
|
261
|
157 |
found := false.
|
|
158 |
(called := node called) notNil ifTrue:[
|
|
159 |
called do:[:subTree |
|
|
160 |
found ifFalse:[
|
|
161 |
(chain = subTree) ifTrue:[
|
|
162 |
node := subTree.
|
|
163 |
chain := chain rest.
|
|
164 |
found := true
|
|
165 |
].
|
|
166 |
].
|
|
167 |
].
|
|
168 |
] ifFalse:[
|
|
169 |
node called:(OrderedCollection new)
|
|
170 |
].
|
|
171 |
found ifFalse:[
|
|
172 |
subTree := ProfileTree new.
|
|
173 |
subTree receiver:chain receiver
|
|
174 |
selector:chain selector
|
|
175 |
class:chain methodClass
|
|
176 |
isBlock:chain isBlock.
|
22
|
177 |
|
261
|
178 |
node called add:subTree.
|
|
179 |
node := subTree.
|
|
180 |
chain := chain rest
|
|
181 |
]
|
22
|
182 |
|
|
183 |
].
|
|
184 |
|
|
185 |
node incrementTotalTally.
|
|
186 |
node incrementLeafTally.
|
261
|
187 |
|
|
188 |
"Modified: 18.5.1996 / 19:02:28 / cg"
|
22
|
189 |
!
|
|
190 |
|
88
|
191 |
computePercentage:total
|
261
|
192 |
"compute percentages"
|
|
193 |
|
88
|
194 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
195 |
leafTally notNil ifTrue:[
|
261
|
196 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
88
|
197 |
].
|
|
198 |
|
|
199 |
called notNil ifTrue:[
|
261
|
200 |
called do:[:subTree |
|
|
201 |
subTree computePercentage:total
|
|
202 |
]
|
88
|
203 |
].
|
261
|
204 |
|
|
205 |
"Modified: 18.5.1996 / 19:02:45 / cg"
|
88
|
206 |
!
|
|
207 |
|
|
208 |
incrementLeafTally
|
263
|
209 |
"{ Pragma: +optSpeed }"
|
|
210 |
|
261
|
211 |
"count as leaf"
|
|
212 |
|
88
|
213 |
leafTally isNil ifTrue:[
|
261
|
214 |
leafTally := 1
|
88
|
215 |
] ifFalse:[
|
261
|
216 |
leafTally := leafTally + 1.
|
88
|
217 |
].
|
261
|
218 |
|
|
219 |
"Modified: 18.5.1996 / 19:02:59 / cg"
|
88
|
220 |
!
|
|
221 |
|
22
|
222 |
incrementTotalTally
|
263
|
223 |
"{ Pragma: +optSpeed }"
|
|
224 |
|
261
|
225 |
"count"
|
|
226 |
|
22
|
227 |
totalTally isNil ifTrue:[
|
261
|
228 |
totalTally := 1
|
22
|
229 |
] ifFalse:[
|
261
|
230 |
totalTally := totalTally + 1.
|
22
|
231 |
].
|
261
|
232 |
|
|
233 |
"Modified: 18.5.1996 / 19:03:06 / cg"
|
22
|
234 |
!
|
|
235 |
|
|
236 |
leafTally:aCount
|
261
|
237 |
"set the leafTally count"
|
|
238 |
|
22
|
239 |
leafTally := aCount
|
261
|
240 |
|
|
241 |
"Modified: 18.5.1996 / 19:03:22 / cg"
|
22
|
242 |
!
|
|
243 |
|
|
244 |
totalTally:aCount
|
261
|
245 |
"set the totalTally count"
|
|
246 |
|
22
|
247 |
totalTally := aCount
|
261
|
248 |
|
|
249 |
"Modified: 18.5.1996 / 19:03:30 / cg"
|
22
|
250 |
! !
|
|
251 |
|
88
|
252 |
!ProfileTree methodsFor:'prettyPrinting'!
|
|
253 |
|
|
254 |
printLeafsOn:aStream
|
261
|
255 |
"print all leafNodes statistics on aStream"
|
|
256 |
|
88
|
257 |
|leafNodes|
|
|
258 |
|
|
259 |
leafNodes := OrderedCollection new.
|
|
260 |
self addLeafNodesTo:leafNodes.
|
|
261 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
261
|
262 |
a leafTally < b leafTally].
|
88
|
263 |
leafNodes do:[:aNode |
|
261
|
264 |
aNode printSingleOn:aStream.
|
|
265 |
aStream cr.
|
88
|
266 |
].
|
261
|
267 |
|
|
268 |
"Modified: 18.5.1996 / 19:04:03 / cg"
|
88
|
269 |
!
|
|
270 |
|
559
|
271 |
printMethodLeafsOn:aStream
|
|
272 |
"print all method leafNodes statistics on aStream"
|
|
273 |
|
|
274 |
|leafNodes|
|
|
275 |
|
|
276 |
leafNodes := OrderedCollection new.
|
|
277 |
self addMethodLeafNodesTo:leafNodes.
|
|
278 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
|
279 |
a leafTally < b leafTally].
|
|
280 |
leafNodes do:[:aNode |
|
|
281 |
aNode printSingleMethodOn:aStream.
|
|
282 |
aStream cr.
|
|
283 |
].
|
|
284 |
|
|
285 |
"Created: 19.3.1997 / 12:19:31 / cg"
|
|
286 |
"Modified: 19.3.1997 / 12:34:39 / cg"
|
|
287 |
!
|
|
288 |
|
88
|
289 |
printOn:aStream
|
261
|
290 |
"print statistics on aStream"
|
|
291 |
|
88
|
292 |
|s|
|
|
293 |
|
|
294 |
"/ self printOn:aStream indent:0
|
|
295 |
s := WriteStream on:String new.
|
|
296 |
self printOn:s indent:0.
|
|
297 |
|
|
298 |
aStream nextPutAll:s contents
|
261
|
299 |
|
|
300 |
"Modified: 18.5.1996 / 19:03:55 / cg"
|
88
|
301 |
!
|
|
302 |
|
|
303 |
printOn:aStream indent:i
|
261
|
304 |
"print statistics indented on aStream"
|
|
305 |
|
88
|
306 |
selector notNil ifTrue:[
|
261
|
307 |
aStream spaces:i.
|
|
308 |
self printSingleOn:aStream.
|
|
309 |
aStream cr.
|
88
|
310 |
].
|
|
311 |
|
|
312 |
called notNil ifTrue:[
|
261
|
313 |
called do:[:sub|
|
|
314 |
sub printOn:aStream indent:(i + 1)
|
|
315 |
].
|
88
|
316 |
].
|
261
|
317 |
|
|
318 |
"Modified: 18.5.1996 / 19:04:12 / cg"
|
88
|
319 |
!
|
|
320 |
|
559
|
321 |
printSingleMethodOn:aStream
|
|
322 |
"print a single nodes statistic on aStream"
|
|
323 |
|
|
324 |
|cls|
|
|
325 |
|
|
326 |
selector notNil ifTrue:[
|
|
327 |
isBlock == true ifTrue:[
|
|
328 |
'[] in ' printOn:aStream
|
|
329 |
].
|
|
330 |
(class notNil and:[class ~~ receiver class]) ifTrue:[
|
|
331 |
cls := class
|
|
332 |
] ifFalse:[
|
|
333 |
cls := receiver.
|
|
334 |
].
|
|
335 |
cls name printOn:aStream.
|
|
336 |
aStream space.
|
|
337 |
selector printOn:aStream.
|
|
338 |
aStream space.
|
|
339 |
|
|
340 |
leafTally notNil ifTrue:[
|
|
341 |
aStream nextPutAll:'(leaf '.
|
|
342 |
leafTally printOn:aStream.
|
|
343 |
aStream nextPutAll:'%)'.
|
|
344 |
] ifFalse:[
|
|
345 |
aStream nextPutAll:'(total '.
|
|
346 |
totalTally printOn:aStream.
|
|
347 |
aStream nextPutAll:'%)'.
|
|
348 |
]
|
|
349 |
].
|
|
350 |
|
|
351 |
"Created: 19.3.1997 / 12:33:46 / cg"
|
|
352 |
"Modified: 19.3.1997 / 12:36:44 / cg"
|
|
353 |
!
|
|
354 |
|
88
|
355 |
printSingleOn:aStream
|
261
|
356 |
"print a single nodes statistic on aStream"
|
|
357 |
|
88
|
358 |
selector notNil ifTrue:[
|
261
|
359 |
isBlock == true ifTrue:[
|
|
360 |
'[] in ' printOn:aStream
|
|
361 |
].
|
|
362 |
receiver name printOn:aStream.
|
|
363 |
(class notNil and:[class ~~ receiver class]) ifTrue:[
|
|
364 |
'>>' printOn:aStream.
|
|
365 |
class name printOn:aStream
|
|
366 |
].
|
|
367 |
aStream space.
|
|
368 |
selector printOn:aStream.
|
|
369 |
aStream space.
|
88
|
370 |
|
261
|
371 |
aStream nextPutAll:'(total '.
|
|
372 |
totalTally printOn:aStream.
|
|
373 |
aStream nextPutAll:'%)'.
|
88
|
374 |
|
261
|
375 |
leafTally notNil ifTrue:[
|
|
376 |
aStream nextPutAll:'(leaf '.
|
|
377 |
leafTally printOn:aStream.
|
|
378 |
aStream nextPutAll:'%)'.
|
|
379 |
].
|
88
|
380 |
].
|
261
|
381 |
|
|
382 |
"Modified: 18.5.1996 / 19:04:28 / cg"
|
88
|
383 |
! !
|
|
384 |
|
22
|
385 |
!ProfileTree methodsFor:'private'!
|
|
386 |
|
88
|
387 |
= aProfileTreeNode
|
261
|
388 |
"return true, if the argument tree is for the same method invocation"
|
|
389 |
|
88
|
390 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
391 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
559
|
392 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
88
|
393 |
^ true
|
261
|
394 |
|
559
|
395 |
"Modified: 19.3.1997 / 12:23:41 / cg"
|
88
|
396 |
!
|
|
397 |
|
22
|
398 |
addLeafNodesTo:aCollection
|
261
|
399 |
"add all leaf nodes to aCollection"
|
|
400 |
|
22
|
401 |
|idx|
|
|
402 |
|
|
403 |
leafTally notNil ifTrue:[
|
559
|
404 |
idx := aCollection indexOf:self.
|
261
|
405 |
idx == 0 ifTrue:[
|
|
406 |
aCollection add:self copy
|
|
407 |
] ifFalse:[
|
|
408 |
|nd|
|
22
|
409 |
|
261
|
410 |
nd := aCollection at:idx.
|
|
411 |
nd leafTally:(nd leafTally + leafTally).
|
|
412 |
nd totalTally:(nd totalTally max: totalTally)
|
|
413 |
]
|
22
|
414 |
].
|
|
415 |
called notNil ifTrue:[
|
261
|
416 |
called do:[:aNode |
|
|
417 |
aNode addLeafNodesTo:aCollection
|
|
418 |
]
|
22
|
419 |
]
|
261
|
420 |
|
559
|
421 |
"Modified: 19.3.1997 / 12:23:49 / cg"
|
|
422 |
!
|
|
423 |
|
|
424 |
addMethodLeafNodesTo:aCollection
|
|
425 |
"add all method leaf nodes to aCollection"
|
|
426 |
|
|
427 |
|idx|
|
|
428 |
|
|
429 |
leafTally notNil ifTrue:[
|
|
430 |
idx := aCollection findFirst:[:el | el sameMethodAsIn:self].
|
|
431 |
idx == 0 ifTrue:[
|
|
432 |
aCollection add:self copy
|
|
433 |
] ifFalse:[
|
|
434 |
|nd|
|
|
435 |
|
|
436 |
nd := aCollection at:idx.
|
|
437 |
nd leafTally:(nd leafTally + leafTally).
|
|
438 |
nd totalTally:(nd totalTally max: totalTally)
|
|
439 |
]
|
|
440 |
].
|
|
441 |
called notNil ifTrue:[
|
|
442 |
called do:[:aNode |
|
|
443 |
aNode addMethodLeafNodesTo:aCollection
|
|
444 |
]
|
|
445 |
]
|
|
446 |
|
|
447 |
"Modified: 19.3.1997 / 12:26:05 / cg"
|
|
448 |
!
|
|
449 |
|
|
450 |
sameMethodAsIn:aProfileTreeNode
|
|
451 |
"return true, if the argument tree is for the same method invocation"
|
|
452 |
|
|
453 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
454 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
455 |
^ true
|
|
456 |
|
|
457 |
"Created: 19.3.1997 / 12:23:24 / cg"
|
88
|
458 |
! !
|
22
|
459 |
|
98
|
460 |
!ProfileTree class methodsFor:'documentation'!
|
|
461 |
|
|
462 |
version
|
559
|
463 |
^ '$Header: /cvs/stx/stx/libbasic3/ProfileTree.st,v 1.14 1997-03-19 11:40:49 cg Exp $'
|
98
|
464 |
! !
|