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
|
261
|
145 |
"merge a chain into the receviers tree"
|
|
146 |
|
22
|
147 |
|node found subTree chain called|
|
|
148 |
|
|
149 |
node := self.
|
|
150 |
chain := aCallChain.
|
|
151 |
|
|
152 |
[chain notNil] whileTrue:[
|
261
|
153 |
node incrementTotalTally.
|
22
|
154 |
|
261
|
155 |
found := false.
|
|
156 |
(called := node called) notNil ifTrue:[
|
|
157 |
called do:[:subTree |
|
|
158 |
found ifFalse:[
|
|
159 |
(chain = subTree) ifTrue:[
|
|
160 |
node := subTree.
|
|
161 |
chain := chain rest.
|
|
162 |
found := true
|
|
163 |
].
|
|
164 |
].
|
|
165 |
].
|
|
166 |
] ifFalse:[
|
|
167 |
node called:(OrderedCollection new)
|
|
168 |
].
|
|
169 |
found ifFalse:[
|
|
170 |
subTree := ProfileTree new.
|
|
171 |
subTree receiver:chain receiver
|
|
172 |
selector:chain selector
|
|
173 |
class:chain methodClass
|
|
174 |
isBlock:chain isBlock.
|
22
|
175 |
|
261
|
176 |
node called add:subTree.
|
|
177 |
node := subTree.
|
|
178 |
chain := chain rest
|
|
179 |
]
|
22
|
180 |
|
|
181 |
].
|
|
182 |
|
|
183 |
node incrementTotalTally.
|
|
184 |
node incrementLeafTally.
|
261
|
185 |
|
|
186 |
"Modified: 18.5.1996 / 19:02:28 / cg"
|
22
|
187 |
!
|
|
188 |
|
88
|
189 |
computePercentage:total
|
261
|
190 |
"compute percentages"
|
|
191 |
|
88
|
192 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
193 |
leafTally notNil ifTrue:[
|
261
|
194 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
88
|
195 |
].
|
|
196 |
|
|
197 |
called notNil ifTrue:[
|
261
|
198 |
called do:[:subTree |
|
|
199 |
subTree computePercentage:total
|
|
200 |
]
|
88
|
201 |
].
|
261
|
202 |
|
|
203 |
"Modified: 18.5.1996 / 19:02:45 / cg"
|
88
|
204 |
!
|
|
205 |
|
|
206 |
incrementLeafTally
|
261
|
207 |
"count as leaf"
|
|
208 |
|
88
|
209 |
leafTally isNil ifTrue:[
|
261
|
210 |
leafTally := 1
|
88
|
211 |
] ifFalse:[
|
261
|
212 |
leafTally := leafTally + 1.
|
88
|
213 |
].
|
261
|
214 |
|
|
215 |
"Modified: 18.5.1996 / 19:02:59 / cg"
|
88
|
216 |
!
|
|
217 |
|
22
|
218 |
incrementTotalTally
|
261
|
219 |
"count"
|
|
220 |
|
22
|
221 |
totalTally isNil ifTrue:[
|
261
|
222 |
totalTally := 1
|
22
|
223 |
] ifFalse:[
|
261
|
224 |
totalTally := totalTally + 1.
|
22
|
225 |
].
|
261
|
226 |
|
|
227 |
"Modified: 18.5.1996 / 19:03:06 / 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 |
|
261
|
258 |
aNode printSingleOn:aStream.
|
|
259 |
aStream cr.
|
88
|
260 |
].
|
261
|
261 |
|
|
262 |
"Modified: 18.5.1996 / 19:04:03 / cg"
|
88
|
263 |
!
|
|
264 |
|
|
265 |
printOn:aStream
|
261
|
266 |
"print statistics on aStream"
|
|
267 |
|
88
|
268 |
|s|
|
|
269 |
|
|
270 |
"/ self printOn:aStream indent:0
|
|
271 |
s := WriteStream on:String new.
|
|
272 |
self printOn:s indent:0.
|
|
273 |
|
|
274 |
aStream nextPutAll:s contents
|
261
|
275 |
|
|
276 |
"Modified: 18.5.1996 / 19:03:55 / cg"
|
88
|
277 |
!
|
|
278 |
|
|
279 |
printOn:aStream indent:i
|
261
|
280 |
"print statistics indented on aStream"
|
|
281 |
|
88
|
282 |
selector notNil ifTrue:[
|
261
|
283 |
aStream spaces:i.
|
|
284 |
self printSingleOn:aStream.
|
|
285 |
aStream cr.
|
88
|
286 |
].
|
|
287 |
|
|
288 |
called notNil ifTrue:[
|
261
|
289 |
called do:[:sub|
|
|
290 |
sub printOn:aStream indent:(i + 1)
|
|
291 |
].
|
88
|
292 |
].
|
261
|
293 |
|
|
294 |
"Modified: 18.5.1996 / 19:04:12 / cg"
|
88
|
295 |
!
|
|
296 |
|
|
297 |
printSingleOn:aStream
|
261
|
298 |
"print a single nodes statistic on aStream"
|
|
299 |
|
88
|
300 |
selector notNil ifTrue:[
|
261
|
301 |
isBlock == true ifTrue:[
|
|
302 |
'[] in ' printOn:aStream
|
|
303 |
].
|
|
304 |
receiver name printOn:aStream.
|
|
305 |
(class notNil and:[class ~~ receiver class]) ifTrue:[
|
|
306 |
'>>' printOn:aStream.
|
|
307 |
class name printOn:aStream
|
|
308 |
].
|
|
309 |
aStream space.
|
|
310 |
selector printOn:aStream.
|
|
311 |
aStream space.
|
88
|
312 |
|
261
|
313 |
aStream nextPutAll:'(total '.
|
|
314 |
totalTally printOn:aStream.
|
|
315 |
aStream nextPutAll:'%)'.
|
88
|
316 |
|
261
|
317 |
leafTally notNil ifTrue:[
|
|
318 |
aStream nextPutAll:'(leaf '.
|
|
319 |
leafTally printOn:aStream.
|
|
320 |
aStream nextPutAll:'%)'.
|
|
321 |
].
|
88
|
322 |
].
|
261
|
323 |
|
|
324 |
"Modified: 18.5.1996 / 19:04:28 / cg"
|
88
|
325 |
! !
|
|
326 |
|
22
|
327 |
!ProfileTree methodsFor:'private'!
|
|
328 |
|
88
|
329 |
= aProfileTreeNode
|
261
|
330 |
"return true, if the argument tree is for the same method invocation"
|
|
331 |
|
88
|
332 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
|
333 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
334 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
335 |
^ true
|
261
|
336 |
|
|
337 |
"Modified: 18.5.1996 / 19:04:40 / cg"
|
88
|
338 |
!
|
|
339 |
|
22
|
340 |
addLeafNodesTo:aCollection
|
261
|
341 |
"add all leaf nodes to aCollection"
|
|
342 |
|
22
|
343 |
|idx|
|
|
344 |
|
|
345 |
leafTally notNil ifTrue:[
|
261
|
346 |
idx := aCollection indexOf:self.
|
|
347 |
idx == 0 ifTrue:[
|
|
348 |
aCollection add:self copy
|
|
349 |
] ifFalse:[
|
|
350 |
|nd|
|
22
|
351 |
|
261
|
352 |
nd := aCollection at:idx.
|
|
353 |
nd leafTally:(nd leafTally + leafTally).
|
|
354 |
nd totalTally:(nd totalTally max: totalTally)
|
|
355 |
]
|
22
|
356 |
].
|
|
357 |
called notNil ifTrue:[
|
261
|
358 |
called do:[:aNode |
|
|
359 |
aNode addLeafNodesTo:aCollection
|
|
360 |
]
|
22
|
361 |
]
|
261
|
362 |
|
|
363 |
"Modified: 18.5.1996 / 19:04:56 / cg"
|
88
|
364 |
! !
|
22
|
365 |
|
98
|
366 |
!ProfileTree class methodsFor:'documentation'!
|
|
367 |
|
|
368 |
version
|
261
|
369 |
^ '$Header: /cvs/stx/stx/libbasic3/ProfileTree.st,v 1.12 1996-05-18 17:05:49 cg Exp $'
|
98
|
370 |
! !
|