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