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 |
|
22
|
13 |
'From Smalltalk/X, Version:2.10.4 on 8-mar-1995 at 22:37:26'!
|
|
14 |
|
|
15 |
Object subclass:#ProfileTree
|
|
16 |
instanceVariableNames:'receiver selector class leafTally totalTally called isBlock'
|
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
24
|
19 |
category:'System-Debugging-Support'
|
22
|
20 |
!
|
|
21 |
|
23
|
22 |
!ProfileTree class methodsFor:'documentation'!
|
|
23 |
|
24
|
24 |
version
|
|
25 |
"
|
39
|
26 |
$Header: /cvs/stx/stx/libbasic3/ProfileTree.st,v 1.5 1995-08-11 16:01:31 claus Exp $
|
24
|
27 |
"
|
|
28 |
!
|
|
29 |
|
23
|
30 |
documentation
|
|
31 |
"
|
|
32 |
This is is used as a companion to MessageTally.
|
|
33 |
Instances of it are used to represent the calling tree.
|
|
34 |
"
|
24
|
35 |
!
|
|
36 |
|
|
37 |
copyright
|
|
38 |
"
|
|
39 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
40 |
All Rights Reserved
|
|
41 |
|
|
42 |
This software is furnished under a license and may be used
|
|
43 |
only in accordance with the terms of that license and with the
|
|
44 |
inclusion of the above copyright notice. This software may not
|
|
45 |
be provided or otherwise made available to, or used by, any
|
|
46 |
other person. No title to or ownership of the software is
|
|
47 |
hereby transferred.
|
|
48 |
"
|
23
|
49 |
! !
|
|
50 |
|
22
|
51 |
!ProfileTree methodsFor:'prettyPrinting'!
|
|
52 |
|
|
53 |
printOn:aStream indent:i
|
|
54 |
selector notNil ifTrue:[
|
23
|
55 |
aStream spaces:i.
|
|
56 |
self printSingleOn:aStream.
|
|
57 |
aStream cr.
|
22
|
58 |
].
|
|
59 |
|
|
60 |
called notNil ifTrue:[
|
23
|
61 |
called do:[:sub|
|
|
62 |
sub printOn:aStream indent:(i + 1)
|
|
63 |
].
|
22
|
64 |
].
|
|
65 |
!
|
|
66 |
|
|
67 |
printOn:aStream
|
|
68 |
|s|
|
|
69 |
|
|
70 |
"/ self printOn:aStream indent:0
|
|
71 |
s := WriteStream on:String new.
|
|
72 |
self printOn:s indent:0.
|
|
73 |
|
|
74 |
aStream nextPutAll:s contents
|
|
75 |
!
|
|
76 |
|
|
77 |
printSingleOn:aStream
|
|
78 |
selector notNil ifTrue:[
|
23
|
79 |
isBlock == true ifTrue:[
|
|
80 |
'[] in ' printOn:aStream
|
|
81 |
].
|
|
82 |
receiver name printOn:aStream.
|
|
83 |
(class notNil and:[class ~~ receiver class]) ifTrue:[
|
|
84 |
'>>' printOn:aStream.
|
|
85 |
class name printOn:aStream
|
|
86 |
].
|
|
87 |
aStream space.
|
|
88 |
selector printOn:aStream.
|
|
89 |
aStream space.
|
22
|
90 |
|
23
|
91 |
aStream nextPutAll:'(total '.
|
|
92 |
totalTally printOn:aStream.
|
|
93 |
aStream nextPutAll:'%)'.
|
22
|
94 |
|
23
|
95 |
leafTally notNil ifTrue:[
|
|
96 |
aStream nextPutAll:'(leaf '.
|
|
97 |
leafTally printOn:aStream.
|
|
98 |
aStream nextPutAll:'%)'.
|
|
99 |
].
|
22
|
100 |
].
|
|
101 |
!
|
|
102 |
|
|
103 |
printLeafsOn:aStream
|
|
104 |
|leafNodes|
|
|
105 |
|
|
106 |
leafNodes := OrderedCollection new.
|
|
107 |
self addLeafNodesTo:leafNodes.
|
|
108 |
leafNodes := leafNodes asSortedCollection:[:a :b |
|
23
|
109 |
a leafTally < b leafTally].
|
22
|
110 |
leafNodes do:[:aNode |
|
23
|
111 |
aNode printSingleOn:aStream.
|
|
112 |
aStream cr.
|
22
|
113 |
].
|
|
114 |
! !
|
|
115 |
|
|
116 |
!ProfileTree methodsFor:'accessing'!
|
|
117 |
|
|
118 |
selector
|
|
119 |
^ selector
|
|
120 |
!
|
|
121 |
|
|
122 |
called:aCollection
|
|
123 |
called := aCollection
|
|
124 |
!
|
|
125 |
|
|
126 |
methodClass
|
|
127 |
^ class
|
|
128 |
!
|
|
129 |
|
|
130 |
isBlock:aBoolean
|
|
131 |
isBlock := aBoolean
|
|
132 |
!
|
|
133 |
|
|
134 |
receiver
|
|
135 |
^ receiver
|
|
136 |
!
|
|
137 |
|
|
138 |
called
|
|
139 |
^ called
|
|
140 |
!
|
|
141 |
|
|
142 |
leafTally
|
|
143 |
^ leafTally
|
|
144 |
!
|
|
145 |
|
|
146 |
receiver:r selector:s class:cls
|
|
147 |
receiver := r.
|
|
148 |
selector := s.
|
|
149 |
class := cls
|
|
150 |
!
|
|
151 |
|
|
152 |
totalTally
|
|
153 |
^ totalTally
|
|
154 |
!
|
|
155 |
|
|
156 |
isBlock
|
|
157 |
^ isBlock
|
|
158 |
! !
|
|
159 |
|
|
160 |
!ProfileTree methodsFor:'adding info'!
|
|
161 |
|
|
162 |
computePercentage:total
|
|
163 |
totalTally := (totalTally / total * 1000) rounded / 10.0.
|
|
164 |
leafTally notNil ifTrue:[
|
23
|
165 |
leafTally := (leafTally / total * 1000) rounded / 10.0
|
22
|
166 |
].
|
|
167 |
|
|
168 |
called notNil ifTrue:[
|
23
|
169 |
called do:[:subTree |
|
|
170 |
subTree computePercentage:total
|
|
171 |
]
|
22
|
172 |
].
|
|
173 |
!
|
|
174 |
|
|
175 |
addChain:aCallChain
|
|
176 |
|node found subTree chain called|
|
|
177 |
|
|
178 |
node := self.
|
|
179 |
chain := aCallChain.
|
|
180 |
|
|
181 |
[chain notNil] whileTrue:[
|
|
182 |
node incrementTotalTally.
|
|
183 |
|
|
184 |
found := false.
|
|
185 |
(called := node called) notNil ifTrue:[
|
|
186 |
called do:[:subTree |
|
|
187 |
found ifFalse:[
|
|
188 |
(chain = subTree) ifTrue:[
|
|
189 |
node := subTree.
|
|
190 |
chain := chain rest.
|
|
191 |
found := true
|
|
192 |
].
|
|
193 |
].
|
|
194 |
].
|
|
195 |
] ifFalse:[
|
|
196 |
node called:(OrderedCollection new)
|
|
197 |
].
|
|
198 |
found ifFalse:[
|
|
199 |
subTree := ProfileTree new.
|
|
200 |
subTree receiver:chain receiver
|
|
201 |
selector:chain selector
|
|
202 |
class:chain methodClass.
|
|
203 |
subTree isBlock:(chain isBlock).
|
|
204 |
|
|
205 |
node called add:subTree.
|
|
206 |
node := subTree.
|
|
207 |
chain := chain rest
|
|
208 |
]
|
|
209 |
|
|
210 |
].
|
|
211 |
|
|
212 |
node incrementTotalTally.
|
|
213 |
node incrementLeafTally.
|
|
214 |
!
|
|
215 |
|
|
216 |
incrementTotalTally
|
|
217 |
totalTally isNil ifTrue:[
|
|
218 |
totalTally := 1
|
|
219 |
] ifFalse:[
|
|
220 |
totalTally := totalTally + 1.
|
|
221 |
].
|
|
222 |
!
|
|
223 |
|
|
224 |
leafTally:aCount
|
|
225 |
leafTally := aCount
|
|
226 |
!
|
|
227 |
|
|
228 |
incrementLeafTally
|
|
229 |
leafTally isNil ifTrue:[
|
|
230 |
leafTally := 1
|
|
231 |
] ifFalse:[
|
|
232 |
leafTally := leafTally + 1.
|
|
233 |
].
|
|
234 |
!
|
|
235 |
|
|
236 |
totalTally:aCount
|
|
237 |
totalTally := aCount
|
|
238 |
! !
|
|
239 |
|
|
240 |
!ProfileTree methodsFor:'private'!
|
|
241 |
|
|
242 |
addLeafNodesTo:aCollection
|
|
243 |
|idx|
|
|
244 |
|
|
245 |
leafTally notNil ifTrue:[
|
23
|
246 |
idx := aCollection indexOf:self.
|
|
247 |
idx == 0 ifTrue:[
|
|
248 |
aCollection add:self copy
|
|
249 |
] ifFalse:[
|
|
250 |
|nd|
|
22
|
251 |
|
23
|
252 |
nd := aCollection at:idx.
|
|
253 |
nd leafTally:(nd leafTally + leafTally).
|
|
254 |
nd totalTally:(nd totalTally max: totalTally)
|
|
255 |
]
|
22
|
256 |
].
|
|
257 |
called notNil ifTrue:[
|
23
|
258 |
called do:[:aNode |
|
|
259 |
aNode addLeafNodesTo:aCollection
|
|
260 |
]
|
22
|
261 |
]
|
|
262 |
!
|
|
263 |
|
|
264 |
= aProfileTreeNode
|
|
265 |
receiver ~= aProfileTreeNode receiver ifTrue:[^ false].
|
|
266 |
selector ~~ aProfileTreeNode selector ifTrue:[^ false].
|
|
267 |
class ~~ aProfileTreeNode methodClass ifTrue:[^ false].
|
|
268 |
^ true
|
|
269 |
! !
|