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