4099
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
24
|
3 |
"
|
|
4 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
3965
|
14 |
"{ Package: 'stx:libbasic3' }"
|
24
|
15 |
|
3965
|
16 |
"{ NameSpace: Smalltalk }"
|
957
|
17 |
|
120
|
18 |
Object subclass:#ProfileTree
|
236
|
19 |
instanceVariableNames:'receiver selector class leafTally totalTally called isBlock'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'System-Debugging-Support'
|
22
|
23 |
!
|
|
24 |
|
23
|
25 |
!ProfileTree class methodsFor:'documentation'!
|
|
26 |
|
24
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
22
|
39 |
!
|
|
40 |
|
88
|
41 |
documentation
|
|
42 |
"
|
|
43 |
This is is used as a companion to MessageTally.
|
261
|
44 |
Instances of it are used to represent a calling chain.
|
|
45 |
(MessageTally could have used the contexts themself, but these
|
|
46 |
may create more overhead)
|
236
|
47 |
|
|
48 |
[author:]
|
|
49 |
Claus Gittinger
|
261
|
50 |
|
|
51 |
[see also:]
|
|
52 |
MessageTally CallChain
|
|
53 |
MessageTracer
|
|
54 |
AbstractTime
|
88
|
55 |
"
|
22
|
56 |
! !
|
|
57 |
|
|
58 |
!ProfileTree methodsFor:'accessing'!
|
|
59 |
|
88
|
60 |
called
|
261
|
61 |
"return the trees of the called methods/blocks"
|
|
62 |
|
88
|
63 |
^ called
|
261
|
64 |
|
|
65 |
"Modified: 18.5.1996 / 19:00:59 / cg"
|
22
|
66 |
!
|
|
67 |
|
|
68 |
called:aCollection
|
261
|
69 |
"set the trees of the called methods/blocks"
|
|
70 |
|
22
|
71 |
called := aCollection
|
261
|
72 |
|
|
73 |
"Modified: 18.5.1996 / 19:01:08 / cg"
|
22
|
74 |
!
|
|
75 |
|
88
|
76 |
isBlock
|
261
|
77 |
"return true, if this is a tree for a block-context"
|
22
|
78 |
|
261
|
79 |
^ isBlock
|
|
80 |
|
|
81 |
"Modified: 18.5.1996 / 18:59:12 / cg"
|
22
|
82 |
!
|
|
83 |
|
88
|
84 |
leafTally
|
261
|
85 |
"return true, if this is a leaf"
|
|
86 |
|
88
|
87 |
^ leafTally
|
261
|
88 |
|
|
89 |
"Modified: 18.5.1996 / 19:01:27 / cg"
|
22
|
90 |
!
|
|
91 |
|
88
|
92 |
methodClass
|
261
|
93 |
"return the contexts methods class"
|
|
94 |
|
|
95 |
^ class
|
|
96 |
|
|
97 |
"Modified: 18.5.1996 / 19:01:40 / cg"
|
22
|
98 |
!
|
|
99 |
|
88
|
100 |
receiver
|
261
|
101 |
"return the contexts receiver"
|
|
102 |
|
88
|
103 |
^ receiver
|
261
|
104 |
|
|
105 |
"Modified: 18.5.1996 / 19:01:45 / cg"
|
22
|
106 |
!
|
|
107 |
|
261
|
108 |
receiver:r selector:s class:cls isBlock:blk
|
|
109 |
"private tally interface - set receiver, selector, class
|
|
110 |
and the block flag."
|
|
111 |
|
|
112 |
receiver := r.
|
|
113 |
selector := s.
|
|
114 |
class := cls.
|
563
|
115 |
isBlock := blk.
|
|
116 |
leafTally := totalTally := 0.
|
261
|
117 |
|
563
|
118 |
"Modified: 20.3.1997 / 20:46:19 / cg"
|
22
|
119 |
!
|
|
120 |
|
88
|
121 |
selector
|
261
|
122 |
"return the contexts selector"
|
|
123 |
|
88
|
124 |
^ selector
|
261
|
125 |
|
|
126 |
"Modified: 18.5.1996 / 19:02:04 / cg"
|
88
|
127 |
!
|
|
128 |
|
22
|
129 |
totalTally
|
261
|
130 |
"return the total tally counter"
|
|
131 |
|
22
|
132 |
^ totalTally
|
261
|
133 |
|
|
134 |
"Modified: 18.5.1996 / 19:02:15 / cg"
|
22
|
135 |
! !
|
|
136 |
|
|
137 |
!ProfileTree methodsFor:'adding info'!
|
|
138 |
|
|
139 |
addChain:aCallChain
|
263
|
140 |
"{ Pragma: +optSpeed }"
|
|
141 |
|
3965
|
142 |
"merge a chain into the receiver's tree"
|
261
|
143 |
|
22
|
144 |
|node found subTree chain called|
|
|
145 |
|
|
146 |
node := self.
|
|
147 |
chain := aCallChain.
|
|
148 |
|
|
149 |
[chain notNil] whileTrue:[
|
261
|
150 |
node incrementTotalTally.
|
22
|
151 |
|
261
|
152 |
found := false.
|
|
153 |
(called := node called) notNil ifTrue:[
|
|
154 |
called do:[:subTree |
|
|
155 |
found ifFalse:[
|
|
156 |
(chain = subTree) ifTrue:[
|
|
157 |
node := subTree.
|
|
158 |
chain := chain rest.
|
|
159 |
found := true
|
|
160 |
].
|
|
161 |
].
|
|
162 |
].
|
|
163 |
] ifFalse:[
|
562
|
164 |
node called:(called := OrderedCollection new)
|
261
|
165 |
].
|
|
166 |
found ifFalse:[
|
|
167 |
subTree := ProfileTree new.
|
|
168 |
subTree receiver:chain receiver
|
|
169 |
selector:chain selector
|
|
170 |
class:chain methodClass
|
|
171 |
isBlock:chain isBlock.
|
22
|
172 |
|
562
|
173 |
called add:subTree.
|
261
|
174 |
node := subTree.
|
|
175 |
chain := chain rest
|
|
176 |
]
|
22
|
177 |
].
|
|
178 |
|
562
|
179 |
node incrementTotalAndLeafTally.
|
261
|
180 |
|
563
|
181 |
"Modified: 20.3.1997 / 20:45:50 / cg"
|
22
|
182 |
!
|
|
183 |
|
88
|
184 |
computePercentage:total
|
261
|
185 |
"compute percentages"
|
|
186 |
|
88
|
187 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
188 |
leafTally notNil ifTrue:[
|
261
|
189 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
88
|
190 |
].
|
|
191 |
|
|
192 |
called notNil ifTrue:[
|
261
|
193 |
called do:[:subTree |
|
|
194 |
subTree computePercentage:total
|
|
195 |
]
|
88
|
196 |
].
|
261
|
197 |
|
566
|
198 |
"Modified: 20.3.1997 / 21:32:01 / cg"
|
88
|
199 |
!
|
|
200 |
|
|
201 |
incrementLeafTally
|
263
|
202 |
"{ Pragma: +optSpeed }"
|
|
203 |
|
261
|
204 |
"count as leaf"
|
|
205 |
|
563
|
206 |
leafTally := leafTally + 1.
|
261
|
207 |
|
563
|
208 |
"Modified: 20.3.1997 / 20:46:27 / cg"
|
88
|
209 |
!
|
|
210 |
|
562
|
211 |
incrementTotalAndLeafTally
|
|
212 |
"{ Pragma: +optSpeed }"
|
|
213 |
|
|
214 |
"count as leaf and total"
|
|
215 |
|
563
|
216 |
leafTally := leafTally + 1.
|
|
217 |
totalTally := totalTally + 1.
|
562
|
218 |
|
563
|
219 |
"Modified: 20.3.1997 / 20:46:36 / cg"
|
562
|
220 |
!
|
|
221 |
|
22
|
222 |
incrementTotalTally
|
263
|
223 |
"{ Pragma: +optSpeed }"
|
|
224 |
|
261
|
225 |
"count"
|
|
226 |
|
563
|
227 |
totalTally := totalTally + 1.
|
261
|
228 |
|
563
|
229 |
"Modified: 20.3.1997 / 20:46:41 / cg"
|
22
|
230 |
!
|
|
231 |
|
|
232 |
leafTally:aCount
|
261
|
233 |
"set the leafTally count"
|
|
234 |
|
22
|
235 |
leafTally := aCount
|
261
|
236 |
|
|
237 |
"Modified: 18.5.1996 / 19:03:22 / cg"
|
22
|
238 |
!
|
|
239 |
|
|
240 |
totalTally:aCount
|
261
|
241 |
"set the totalTally count"
|
|
242 |
|
22
|
243 |
totalTally := aCount
|
261
|
244 |
|
|
245 |
"Modified: 18.5.1996 / 19:03:30 / cg"
|
22
|
246 |
! !
|
|
247 |
|
88
|
248 |
!ProfileTree methodsFor:'prettyPrinting'!
|
|
249 |
|
|
250 |
printLeafsOn:aStream
|
261
|
251 |
"print all leafNodes statistics on aStream"
|
|
252 |
|
88
|
253 |
|leafNodes|
|
|
254 |
|
|
255 |
leafNodes := OrderedCollection new.
|
|
256 |
self addLeafNodesTo:leafNodes.
|
|
257 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
261
|
258 |
a leafTally < b leafTally].
|
88
|
259 |
leafNodes do:[:aNode |
|
563
|
260 |
aNode leafTally ~= 0 ifTrue:[
|
|
261 |
aNode printSingleLeafOn:aStream.
|
|
262 |
aStream cr.
|
|
263 |
]
|
88
|
264 |
].
|
261
|
265 |
|
563
|
266 |
"Modified: 20.3.1997 / 21:08:09 / cg"
|
88
|
267 |
!
|
|
268 |
|
559
|
269 |
printMethodLeafsOn:aStream
|
|
270 |
"print all method leafNodes statistics on aStream"
|
|
271 |
|
|
272 |
|leafNodes|
|
|
273 |
|
|
274 |
leafNodes := OrderedCollection new.
|
|
275 |
self addMethodLeafNodesTo:leafNodes.
|
|
276 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
|
277 |
a leafTally < b leafTally].
|
|
278 |
leafNodes do:[:aNode |
|
563
|
279 |
aNode leafTally ~= 0 ifTrue:[
|
|
280 |
aNode printSingleMethodLeafOn:aStream.
|
|
281 |
aStream cr.
|
|
282 |
].
|
559
|
283 |
].
|
|
284 |
|
|
285 |
"Created: 19.3.1997 / 12:19:31 / cg"
|
563
|
286 |
"Modified: 20.3.1997 / 21:07:39 / cg"
|
559
|
287 |
!
|
|
288 |
|
88
|
289 |
printOn:aStream
|
261
|
290 |
"print statistics on aStream"
|
|
291 |
|
88
|
292 |
|s|
|
|
293 |
|
|
294 |
"/ self printOn:aStream indent:0
|
4099
|
295 |
s := WriteStream on:''.
|
88
|
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 |
|
560
|
321 |
printSingleLeafOn:aStream
|
|
322 |
"print a single nodes statistic on aStream"
|
|
323 |
|
|
324 |
selector notNil ifTrue:[
|
|
325 |
isBlock == true ifTrue:[
|
|
326 |
'[] in ' printOn:aStream
|
|
327 |
].
|
|
328 |
receiver name printOn:aStream.
|
|
329 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
|
330 |
'>>' printOn:aStream.
|
|
331 |
class name printOn:aStream
|
|
332 |
].
|
|
333 |
aStream space.
|
|
334 |
selector printOn:aStream.
|
|
335 |
aStream space.
|
|
336 |
|
|
337 |
leafTally notNil ifTrue:[
|
|
338 |
aStream nextPutAll:'('.
|
|
339 |
leafTally printOn:aStream.
|
|
340 |
aStream nextPutAll:'%)'.
|
|
341 |
] ifFalse:[
|
|
342 |
aStream nextPutAll:'(total '.
|
|
343 |
totalTally printOn:aStream.
|
|
344 |
aStream nextPutAll:'%)'.
|
|
345 |
].
|
|
346 |
].
|
|
347 |
|
|
348 |
"Created: 19.3.1997 / 19:10:13 / cg"
|
|
349 |
"Modified: 19.3.1997 / 19:17:05 / cg"
|
|
350 |
!
|
|
351 |
|
|
352 |
printSingleMethodLeafOn:aStream
|
559
|
353 |
"print a single nodes statistic on aStream"
|
|
354 |
|
|
355 |
|cls|
|
|
356 |
|
|
357 |
selector notNil ifTrue:[
|
|
358 |
isBlock == true ifTrue:[
|
|
359 |
'[] in ' printOn:aStream
|
|
360 |
].
|
560
|
361 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
559
|
362 |
cls := class
|
|
363 |
] ifFalse:[
|
|
364 |
cls := receiver.
|
|
365 |
].
|
|
366 |
cls name printOn:aStream.
|
|
367 |
aStream space.
|
|
368 |
selector printOn:aStream.
|
|
369 |
aStream space.
|
|
370 |
|
|
371 |
leafTally notNil ifTrue:[
|
560
|
372 |
aStream nextPutAll:'('.
|
559
|
373 |
leafTally printOn:aStream.
|
|
374 |
aStream nextPutAll:'%)'.
|
|
375 |
] ifFalse:[
|
|
376 |
aStream nextPutAll:'(total '.
|
|
377 |
totalTally printOn:aStream.
|
|
378 |
aStream nextPutAll:'%)'.
|
|
379 |
]
|
|
380 |
].
|
|
381 |
|
560
|
382 |
"Created: 19.3.1997 / 19:10:32 / cg"
|
|
383 |
"Modified: 19.3.1997 / 19:17:13 / cg"
|
559
|
384 |
!
|
|
385 |
|
88
|
386 |
printSingleOn:aStream
|
261
|
387 |
"print a single nodes statistic on aStream"
|
|
388 |
|
88
|
389 |
selector notNil ifTrue:[
|
261
|
390 |
isBlock == true ifTrue:[
|
|
391 |
'[] in ' printOn:aStream
|
|
392 |
].
|
|
393 |
receiver name printOn:aStream.
|
560
|
394 |
(class notNil and:[class ~~ receiver]) ifTrue:[
|
261
|
395 |
'>>' printOn:aStream.
|
|
396 |
class name printOn:aStream
|
|
397 |
].
|
|
398 |
aStream space.
|
|
399 |
selector printOn:aStream.
|
|
400 |
aStream space.
|
88
|
401 |
|
560
|
402 |
(leafTally isNil or:[leafTally ~= totalTally]) ifTrue:[
|
|
403 |
aStream nextPutAll:'(total '.
|
|
404 |
totalTally printOn:aStream.
|
|
405 |
aStream nextPutAll:'%)'.
|
|
406 |
].
|
88
|
407 |
|
261
|
408 |
leafTally notNil ifTrue:[
|
560
|
409 |
aStream nextPutAll:'(here '.
|
261
|
410 |
leafTally printOn:aStream.
|
|
411 |
aStream nextPutAll:'%)'.
|
|
412 |
].
|
88
|
413 |
].
|
261
|
414 |
|
560
|
415 |
"Modified: 19.3.1997 / 19:14:32 / cg"
|
88
|
416 |
! !
|
|
417 |
|
22
|
418 |
!ProfileTree methodsFor:'private'!
|
|
419 |
|
88
|
420 |
= aProfileTreeNode
|
261
|
421 |
"return true, if the argument tree is for the same method invocation"
|
|
422 |
|
88
|
423 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
424 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
559
|
425 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
88
|
426 |
^ true
|
261
|
427 |
|
559
|
428 |
"Modified: 19.3.1997 / 12:23:41 / cg"
|
88
|
429 |
!
|
|
430 |
|
22
|
431 |
addLeafNodesTo:aCollection
|
261
|
432 |
"add all leaf nodes to aCollection"
|
|
433 |
|
22
|
434 |
|idx|
|
|
435 |
|
|
436 |
leafTally notNil ifTrue:[
|
559
|
437 |
idx := aCollection indexOf:self.
|
261
|
438 |
idx == 0 ifTrue:[
|
|
439 |
aCollection add:self copy
|
|
440 |
] ifFalse:[
|
|
441 |
|nd|
|
22
|
442 |
|
261
|
443 |
nd := aCollection at:idx.
|
|
444 |
nd leafTally:(nd leafTally + leafTally).
|
|
445 |
nd totalTally:(nd totalTally max: totalTally)
|
|
446 |
]
|
22
|
447 |
].
|
|
448 |
called notNil ifTrue:[
|
261
|
449 |
called do:[:aNode |
|
|
450 |
aNode addLeafNodesTo:aCollection
|
|
451 |
]
|
22
|
452 |
]
|
261
|
453 |
|
559
|
454 |
"Modified: 19.3.1997 / 12:23:49 / cg"
|
|
455 |
!
|
|
456 |
|
|
457 |
addMethodLeafNodesTo:aCollection
|
|
458 |
"add all method leaf nodes to aCollection"
|
|
459 |
|
|
460 |
|idx|
|
|
461 |
|
|
462 |
leafTally notNil ifTrue:[
|
|
463 |
idx := aCollection findFirst:[:el | el sameMethodAsIn:self].
|
|
464 |
idx == 0 ifTrue:[
|
|
465 |
aCollection add:self copy
|
|
466 |
] ifFalse:[
|
|
467 |
|nd|
|
|
468 |
|
|
469 |
nd := aCollection at:idx.
|
|
470 |
nd leafTally:(nd leafTally + leafTally).
|
|
471 |
nd totalTally:(nd totalTally max: totalTally)
|
|
472 |
]
|
|
473 |
].
|
|
474 |
called notNil ifTrue:[
|
|
475 |
called do:[:aNode |
|
|
476 |
aNode addMethodLeafNodesTo:aCollection
|
|
477 |
]
|
|
478 |
]
|
|
479 |
|
|
480 |
"Modified: 19.3.1997 / 12:26:05 / cg"
|
|
481 |
!
|
|
482 |
|
563
|
483 |
hash
|
|
484 |
"return true, if the argument tree is for the same method invocation"
|
|
485 |
|
|
486 |
class notNil ifTrue:[
|
568
|
487 |
^ selector identityHash bitXor: class identityHash
|
563
|
488 |
].
|
568
|
489 |
^ selector identityHash bitXor: receiver identityHash
|
563
|
490 |
|
|
491 |
"Created: 20.3.1997 / 20:27:15 / cg"
|
568
|
492 |
"Modified: 21.3.1997 / 14:02:27 / cg"
|
563
|
493 |
!
|
|
494 |
|
559
|
495 |
sameMethodAsIn:aProfileTreeNode
|
|
496 |
"return true, if the argument tree is for the same method invocation"
|
|
497 |
|
|
498 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
499 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
500 |
^ true
|
|
501 |
|
|
502 |
"Created: 19.3.1997 / 12:23:24 / cg"
|
88
|
503 |
! !
|
22
|
504 |
|
98
|
505 |
!ProfileTree class methodsFor:'documentation'!
|
|
506 |
|
|
507 |
version
|
3965
|
508 |
^ '$Header$'
|
98
|
509 |
! !
|
3965
|
510 |
|