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 |
|
261
|
103 |
receiver:r selector:s class:cls isBlock:blk
|
|
104 |
"private tally interface - set receiver, selector, class
|
|
105 |
and the block flag."
|
|
106 |
|
|
107 |
receiver := r.
|
|
108 |
selector := s.
|
|
109 |
class := cls.
|
563
|
110 |
isBlock := blk.
|
|
111 |
leafTally := totalTally := 0.
|
261
|
112 |
|
563
|
113 |
"Modified: 20.3.1997 / 20:46:19 / cg"
|
22
|
114 |
!
|
|
115 |
|
88
|
116 |
selector
|
261
|
117 |
"return the contexts selector"
|
|
118 |
|
88
|
119 |
^ selector
|
261
|
120 |
|
|
121 |
"Modified: 18.5.1996 / 19:02:04 / cg"
|
88
|
122 |
!
|
|
123 |
|
22
|
124 |
totalTally
|
261
|
125 |
"return the total tally counter"
|
|
126 |
|
22
|
127 |
^ totalTally
|
261
|
128 |
|
|
129 |
"Modified: 18.5.1996 / 19:02:15 / cg"
|
22
|
130 |
! !
|
|
131 |
|
|
132 |
!ProfileTree methodsFor:'adding info'!
|
|
133 |
|
|
134 |
addChain:aCallChain
|
263
|
135 |
"{ Pragma: +optSpeed }"
|
|
136 |
|
562
|
137 |
"merge a chain into the receivers tree"
|
261
|
138 |
|
22
|
139 |
|node found subTree chain called|
|
|
140 |
|
|
141 |
node := self.
|
|
142 |
chain := aCallChain.
|
|
143 |
|
|
144 |
[chain notNil] whileTrue:[
|
261
|
145 |
node incrementTotalTally.
|
22
|
146 |
|
261
|
147 |
found := false.
|
|
148 |
(called := node called) notNil ifTrue:[
|
|
149 |
called do:[:subTree |
|
|
150 |
found ifFalse:[
|
|
151 |
(chain = subTree) ifTrue:[
|
|
152 |
node := subTree.
|
|
153 |
chain := chain rest.
|
|
154 |
found := true
|
|
155 |
].
|
|
156 |
].
|
|
157 |
].
|
|
158 |
] ifFalse:[
|
562
|
159 |
node called:(called := OrderedCollection new)
|
261
|
160 |
].
|
|
161 |
found ifFalse:[
|
|
162 |
subTree := ProfileTree new.
|
|
163 |
subTree receiver:chain receiver
|
|
164 |
selector:chain selector
|
|
165 |
class:chain methodClass
|
|
166 |
isBlock:chain isBlock.
|
22
|
167 |
|
562
|
168 |
called add:subTree.
|
261
|
169 |
node := subTree.
|
|
170 |
chain := chain rest
|
|
171 |
]
|
22
|
172 |
].
|
|
173 |
|
562
|
174 |
node incrementTotalAndLeafTally.
|
261
|
175 |
|
563
|
176 |
"Modified: 20.3.1997 / 20:45:50 / cg"
|
22
|
177 |
!
|
|
178 |
|
88
|
179 |
computePercentage:total
|
261
|
180 |
"compute percentages"
|
|
181 |
|
88
|
182 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
183 |
leafTally notNil ifTrue:[
|
261
|
184 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
88
|
185 |
].
|
|
186 |
|
|
187 |
called notNil ifTrue:[
|
261
|
188 |
called do:[:subTree |
|
|
189 |
subTree computePercentage:total
|
|
190 |
]
|
88
|
191 |
].
|
261
|
192 |
|
566
|
193 |
"Modified: 20.3.1997 / 21:32:01 / cg"
|
88
|
194 |
!
|
|
195 |
|
|
196 |
incrementLeafTally
|
263
|
197 |
"{ Pragma: +optSpeed }"
|
|
198 |
|
261
|
199 |
"count as leaf"
|
|
200 |
|
563
|
201 |
leafTally := leafTally + 1.
|
261
|
202 |
|
563
|
203 |
"Modified: 20.3.1997 / 20:46:27 / cg"
|
88
|
204 |
!
|
|
205 |
|
562
|
206 |
incrementTotalAndLeafTally
|
|
207 |
"{ Pragma: +optSpeed }"
|
|
208 |
|
|
209 |
"count as leaf and total"
|
|
210 |
|
563
|
211 |
leafTally := leafTally + 1.
|
|
212 |
totalTally := totalTally + 1.
|
562
|
213 |
|
563
|
214 |
"Modified: 20.3.1997 / 20:46:36 / cg"
|
562
|
215 |
!
|
|
216 |
|
22
|
217 |
incrementTotalTally
|
263
|
218 |
"{ Pragma: +optSpeed }"
|
|
219 |
|
261
|
220 |
"count"
|
|
221 |
|
563
|
222 |
totalTally := totalTally + 1.
|
261
|
223 |
|
563
|
224 |
"Modified: 20.3.1997 / 20:46:41 / cg"
|
22
|
225 |
!
|
|
226 |
|
|
227 |
leafTally:aCount
|
261
|
228 |
"set the leafTally count"
|
|
229 |
|
22
|
230 |
leafTally := aCount
|
261
|
231 |
|
|
232 |
"Modified: 18.5.1996 / 19:03:22 / cg"
|
22
|
233 |
!
|
|
234 |
|
|
235 |
totalTally:aCount
|
261
|
236 |
"set the totalTally count"
|
|
237 |
|
22
|
238 |
totalTally := aCount
|
261
|
239 |
|
|
240 |
"Modified: 18.5.1996 / 19:03:30 / cg"
|
22
|
241 |
! !
|
|
242 |
|
88
|
243 |
!ProfileTree methodsFor:'prettyPrinting'!
|
|
244 |
|
|
245 |
printLeafsOn:aStream
|
261
|
246 |
"print all leafNodes statistics on aStream"
|
|
247 |
|
88
|
248 |
|leafNodes|
|
|
249 |
|
|
250 |
leafNodes := OrderedCollection new.
|
|
251 |
self addLeafNodesTo:leafNodes.
|
|
252 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
261
|
253 |
a leafTally < b leafTally].
|
88
|
254 |
leafNodes do:[:aNode |
|
563
|
255 |
aNode leafTally ~= 0 ifTrue:[
|
|
256 |
aNode printSingleLeafOn:aStream.
|
|
257 |
aStream cr.
|
|
258 |
]
|
88
|
259 |
].
|
261
|
260 |
|
563
|
261 |
"Modified: 20.3.1997 / 21:08:09 / cg"
|
88
|
262 |
!
|
|
263 |
|
559
|
264 |
printMethodLeafsOn:aStream
|
|
265 |
"print all method leafNodes statistics on aStream"
|
|
266 |
|
|
267 |
|leafNodes|
|
|
268 |
|
|
269 |
leafNodes := OrderedCollection new.
|
|
270 |
self addMethodLeafNodesTo:leafNodes.
|
|
271 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
|
272 |
a leafTally < b leafTally].
|
|
273 |
leafNodes do:[:aNode |
|
563
|
274 |
aNode leafTally ~= 0 ifTrue:[
|
|
275 |
aNode printSingleMethodLeafOn:aStream.
|
|
276 |
aStream cr.
|
|
277 |
].
|
559
|
278 |
].
|
|
279 |
|
|
280 |
"Created: 19.3.1997 / 12:19:31 / cg"
|
563
|
281 |
"Modified: 20.3.1997 / 21:07:39 / cg"
|
559
|
282 |
!
|
|
283 |
|
88
|
284 |
printOn:aStream
|
261
|
285 |
"print statistics on aStream"
|
|
286 |
|
88
|
287 |
|s|
|
|
288 |
|
|
289 |
"/ self printOn:aStream indent:0
|
|
290 |
s := WriteStream on:String new.
|
|
291 |
self printOn:s indent:0.
|
|
292 |
|
|
293 |
aStream nextPutAll:s contents
|
261
|
294 |
|
|
295 |
"Modified: 18.5.1996 / 19:03:55 / cg"
|
88
|
296 |
!
|
|
297 |
|
|
298 |
printOn:aStream indent:i
|
261
|
299 |
"print statistics indented on aStream"
|
|
300 |
|
88
|
301 |
selector notNil ifTrue:[
|
261
|
302 |
aStream spaces:i.
|
|
303 |
self printSingleOn:aStream.
|
|
304 |
aStream cr.
|
88
|
305 |
].
|
|
306 |
|
|
307 |
called notNil ifTrue:[
|
261
|
308 |
called do:[:sub|
|
|
309 |
sub printOn:aStream indent:(i + 1)
|
|
310 |
].
|
88
|
311 |
].
|
261
|
312 |
|
|
313 |
"Modified: 18.5.1996 / 19:04:12 / cg"
|
88
|
314 |
!
|
|
315 |
|
560
|
316 |
printSingleLeafOn:aStream
|
|
317 |
"print a single nodes statistic on aStream"
|
|
318 |
|
|
319 |
selector notNil ifTrue:[
|
|
320 |
isBlock == true ifTrue:[
|
|
321 |
'[] in ' printOn:aStream
|
|
322 |
].
|
|
323 |
receiver name printOn:aStream.
|
|
324 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
|
325 |
'>>' printOn:aStream.
|
|
326 |
class name printOn:aStream
|
|
327 |
].
|
|
328 |
aStream space.
|
|
329 |
selector printOn:aStream.
|
|
330 |
aStream space.
|
|
331 |
|
|
332 |
leafTally notNil ifTrue:[
|
|
333 |
aStream nextPutAll:'('.
|
|
334 |
leafTally printOn:aStream.
|
|
335 |
aStream nextPutAll:'%)'.
|
|
336 |
] ifFalse:[
|
|
337 |
aStream nextPutAll:'(total '.
|
|
338 |
totalTally printOn:aStream.
|
|
339 |
aStream nextPutAll:'%)'.
|
|
340 |
].
|
|
341 |
].
|
|
342 |
|
|
343 |
"Created: 19.3.1997 / 19:10:13 / cg"
|
|
344 |
"Modified: 19.3.1997 / 19:17:05 / cg"
|
|
345 |
!
|
|
346 |
|
|
347 |
printSingleMethodLeafOn:aStream
|
559
|
348 |
"print a single nodes statistic on aStream"
|
|
349 |
|
|
350 |
|cls|
|
|
351 |
|
|
352 |
selector notNil ifTrue:[
|
|
353 |
isBlock == true ifTrue:[
|
|
354 |
'[] in ' printOn:aStream
|
|
355 |
].
|
560
|
356 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
559
|
357 |
cls := class
|
|
358 |
] ifFalse:[
|
|
359 |
cls := receiver.
|
|
360 |
].
|
|
361 |
cls name printOn:aStream.
|
|
362 |
aStream space.
|
|
363 |
selector printOn:aStream.
|
|
364 |
aStream space.
|
|
365 |
|
|
366 |
leafTally notNil ifTrue:[
|
560
|
367 |
aStream nextPutAll:'('.
|
559
|
368 |
leafTally printOn:aStream.
|
|
369 |
aStream nextPutAll:'%)'.
|
|
370 |
] ifFalse:[
|
|
371 |
aStream nextPutAll:'(total '.
|
|
372 |
totalTally printOn:aStream.
|
|
373 |
aStream nextPutAll:'%)'.
|
|
374 |
]
|
|
375 |
].
|
|
376 |
|
560
|
377 |
"Created: 19.3.1997 / 19:10:32 / cg"
|
|
378 |
"Modified: 19.3.1997 / 19:17:13 / cg"
|
559
|
379 |
!
|
|
380 |
|
88
|
381 |
printSingleOn:aStream
|
261
|
382 |
"print a single nodes statistic on aStream"
|
|
383 |
|
88
|
384 |
selector notNil ifTrue:[
|
261
|
385 |
isBlock == true ifTrue:[
|
|
386 |
'[] in ' printOn:aStream
|
|
387 |
].
|
|
388 |
receiver name printOn:aStream.
|
560
|
389 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
261
|
390 |
'>>' printOn:aStream.
|
|
391 |
class name printOn:aStream
|
|
392 |
].
|
|
393 |
aStream space.
|
|
394 |
selector printOn:aStream.
|
|
395 |
aStream space.
|
88
|
396 |
|
560
|
397 |
(leafTally isNil or:[leafTally ~= totalTally]) ifTrue:[
|
|
398 |
aStream nextPutAll:'(total '.
|
|
399 |
totalTally printOn:aStream.
|
|
400 |
aStream nextPutAll:'%)'.
|
|
401 |
].
|
88
|
402 |
|
261
|
403 |
leafTally notNil ifTrue:[
|
560
|
404 |
aStream nextPutAll:'(here '.
|
261
|
405 |
leafTally printOn:aStream.
|
|
406 |
aStream nextPutAll:'%)'.
|
|
407 |
].
|
88
|
408 |
].
|
261
|
409 |
|
560
|
410 |
"Modified: 19.3.1997 / 19:14:32 / cg"
|
88
|
411 |
! !
|
|
412 |
|
22
|
413 |
!ProfileTree methodsFor:'private'!
|
|
414 |
|
88
|
415 |
= aProfileTreeNode
|
261
|
416 |
"return true, if the argument tree is for the same method invocation"
|
|
417 |
|
88
|
418 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
419 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
559
|
420 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
88
|
421 |
^ true
|
261
|
422 |
|
559
|
423 |
"Modified: 19.3.1997 / 12:23:41 / cg"
|
88
|
424 |
!
|
|
425 |
|
22
|
426 |
addLeafNodesTo:aCollection
|
261
|
427 |
"add all leaf nodes to aCollection"
|
|
428 |
|
22
|
429 |
|idx|
|
|
430 |
|
|
431 |
leafTally notNil ifTrue:[
|
559
|
432 |
idx := aCollection indexOf:self.
|
261
|
433 |
idx == 0 ifTrue:[
|
|
434 |
aCollection add:self copy
|
|
435 |
] ifFalse:[
|
|
436 |
|nd|
|
22
|
437 |
|
261
|
438 |
nd := aCollection at:idx.
|
|
439 |
nd leafTally:(nd leafTally + leafTally).
|
|
440 |
nd totalTally:(nd totalTally max: totalTally)
|
|
441 |
]
|
22
|
442 |
].
|
|
443 |
called notNil ifTrue:[
|
261
|
444 |
called do:[:aNode |
|
|
445 |
aNode addLeafNodesTo:aCollection
|
|
446 |
]
|
22
|
447 |
]
|
261
|
448 |
|
559
|
449 |
"Modified: 19.3.1997 / 12:23:49 / cg"
|
|
450 |
!
|
|
451 |
|
|
452 |
addMethodLeafNodesTo:aCollection
|
|
453 |
"add all method leaf nodes to aCollection"
|
|
454 |
|
|
455 |
|idx|
|
|
456 |
|
|
457 |
leafTally notNil ifTrue:[
|
|
458 |
idx := aCollection findFirst:[:el | el sameMethodAsIn:self].
|
|
459 |
idx == 0 ifTrue:[
|
|
460 |
aCollection add:self copy
|
|
461 |
] ifFalse:[
|
|
462 |
|nd|
|
|
463 |
|
|
464 |
nd := aCollection at:idx.
|
|
465 |
nd leafTally:(nd leafTally + leafTally).
|
|
466 |
nd totalTally:(nd totalTally max: totalTally)
|
|
467 |
]
|
|
468 |
].
|
|
469 |
called notNil ifTrue:[
|
|
470 |
called do:[:aNode |
|
|
471 |
aNode addMethodLeafNodesTo:aCollection
|
|
472 |
]
|
|
473 |
]
|
|
474 |
|
|
475 |
"Modified: 19.3.1997 / 12:26:05 / cg"
|
|
476 |
!
|
|
477 |
|
563
|
478 |
hash
|
|
479 |
"return true, if the argument tree is for the same method invocation"
|
|
480 |
|
|
481 |
class notNil ifTrue:[
|
|
482 |
^ selector identityHash + class identityHash
|
|
483 |
].
|
|
484 |
^ selector identityHash + receiver identityHash
|
|
485 |
|
|
486 |
"Created: 20.3.1997 / 20:27:15 / cg"
|
|
487 |
!
|
|
488 |
|
559
|
489 |
sameMethodAsIn:aProfileTreeNode
|
|
490 |
"return true, if the argument tree is for the same method invocation"
|
|
491 |
|
|
492 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
493 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
494 |
^ true
|
|
495 |
|
|
496 |
"Created: 19.3.1997 / 12:23:24 / cg"
|
88
|
497 |
! !
|
22
|
498 |
|
98
|
499 |
!ProfileTree class methodsFor:'documentation'!
|
|
500 |
|
|
501 |
version
|
566
|
502 |
^ '$Header: /cvs/stx/stx/libbasic3/ProfileTree.st,v 1.18 1997-03-20 20:47:08 cg Exp $'
|
98
|
503 |
! !
|