0
|
1 |
"
|
21
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
0
|
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:#MessageTally
|
236
|
14 |
instanceVariableNames:'process tree ntally theBlock spyInterval'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'System-Debugging-Support'
|
0
|
18 |
!
|
|
19 |
|
9
|
20 |
!MessageTally class methodsFor:'documentation'!
|
|
21 |
|
88
|
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 |
"
|
9
|
34 |
!
|
|
35 |
|
|
36 |
documentation
|
|
37 |
"
|
|
38 |
MessageTally allows profiling excution of a block;
|
|
39 |
statistic of method evaluation is output on Transcript.
|
|
40 |
To get statistic, use 'MessageTally spyOn:aBlock'.
|
|
41 |
|
|
42 |
example:
|
236
|
43 |
MessageTally spyOn:[
|
|
44 |
(ByteArray uninitalizedNew:1000) sort
|
|
45 |
]
|
21
|
46 |
|
|
47 |
By default, probing is done every 10ms (i.e. the execution of the block is
|
|
48 |
interrupted every 10ms, and the context chain analyzed).
|
|
49 |
For better resolution, use smaller clock ticks (if your OperatingSystem
|
|
50 |
supports it). Try spyDetailedOn:aBlock, which tries to measure things
|
|
51 |
every 1ms. (Notice, that some OS's only provide a resolution of less than
|
|
52 |
that time interval)
|
236
|
53 |
|
|
54 |
[author:]
|
|
55 |
Claus Gittinger
|
21
|
56 |
"
|
|
57 |
!
|
|
58 |
|
|
59 |
examples
|
9
|
60 |
"
|
21
|
61 |
MessageTally spyOn:[ #(6 5 4 3 2 1) sort ]
|
|
62 |
MessageTally spyOn:[100 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
63 |
MessageTally spyOn:[1000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
64 |
MessageTally spyOn:[10000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
65 |
MessageTally spyOn:[100000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
66 |
MessageTally spyOn:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
67 |
MessageTally spyDetailedOn:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
68 |
Time millisecondsToRun:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
69 |
|
|
70 |
MessageTally spyOn:[SystemBrowser open ]
|
|
71 |
MessageTally spyDetailedOn:[SystemBrowser open ]
|
|
72 |
"
|
9
|
73 |
! !
|
0
|
74 |
|
|
75 |
!MessageTally class methodsFor:'instance creation'!
|
|
76 |
|
88
|
77 |
spyDetailedOn:aBlock
|
|
78 |
"evaluate aBlock and output time statistic on the Transcript.
|
|
79 |
Tick is 1ms."
|
|
80 |
|
|
81 |
^ self spyOn:aBlock interval:1
|
|
82 |
!
|
|
83 |
|
|
84 |
spyOn:aBlock
|
|
85 |
"evaluate aBlock and output time statistic on the Transcript.
|
|
86 |
Tick is 10ms."
|
|
87 |
|
|
88 |
^ self spyOn:aBlock interval:10
|
|
89 |
!
|
|
90 |
|
21
|
91 |
spyOn:aBlock interval:ms
|
0
|
92 |
"evaluate aBlock and output time statistic on Transcript"
|
|
93 |
|
21
|
94 |
|runTime aTally nTally|
|
0
|
95 |
|
|
96 |
aTally := self new.
|
21
|
97 |
runTime := aTally spyOn:aBlock interval:ms.
|
|
98 |
|
|
99 |
aTally tree isNil ifTrue:[
|
24
|
100 |
Transcript cr.
|
|
101 |
Transcript showCr:'TALLY: No probes - execution time too short;'.
|
|
102 |
Transcript showCr:'TALLY: retry using: spyOn:[n timesRepeat:[...]]'.
|
21
|
103 |
] ifFalse:[
|
24
|
104 |
"/ aTally tree inspect.
|
|
105 |
nTally := aTally nTally.
|
|
106 |
Transcript cr.
|
|
107 |
Transcript showCr:('total execution time: '
|
|
108 |
, runTime printString , ' ms '
|
|
109 |
, '(' , nTally printString , ' probes ;'
|
|
110 |
, ' error >= '
|
|
111 |
, (1000 // nTally / 10.0) printString
|
|
112 |
, '%)').
|
|
113 |
Transcript cr.
|
|
114 |
aTally tree printOn:Transcript.
|
|
115 |
Transcript cr.
|
|
116 |
Transcript cr.
|
0
|
117 |
|
24
|
118 |
Transcript showCr:'leafs of calling tree:'.
|
|
119 |
Transcript cr.
|
|
120 |
aTally tree printLeafsOn:Transcript.
|
|
121 |
Transcript cr.
|
21
|
122 |
|
24
|
123 |
"
|
|
124 |
aTally statistics.
|
|
125 |
"
|
21
|
126 |
].
|
|
127 |
|
|
128 |
"
|
|
129 |
MessageTally spyOn:[ #(6 5 4 3 2 1) sort ]
|
|
130 |
MessageTally spyOn:[100 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
131 |
MessageTally spyOn:[1000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
132 |
MessageTally spyOn:[10000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
133 |
MessageTally spyOn:[100000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
134 |
MessageTally spyOn:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
135 |
MessageTally spyOn:[SystemBrowser open ]
|
|
136 |
MessageTally spyDetailedOn:[SystemBrowser open ]
|
|
137 |
Time millisecondsToRun:[500000 timesRepeat:[#(6 5 4 3 2 1) sort] ]
|
|
138 |
"
|
88
|
139 |
! !
|
|
140 |
|
|
141 |
!MessageTally methodsFor:'accessing'!
|
|
142 |
|
|
143 |
nTally
|
|
144 |
^ ntally
|
0
|
145 |
!
|
|
146 |
|
88
|
147 |
tree
|
|
148 |
^ tree
|
0
|
149 |
! !
|
|
150 |
|
|
151 |
!MessageTally methodsFor:'private'!
|
|
152 |
|
21
|
153 |
execute
|
|
154 |
theBlock value
|
|
155 |
! !
|
0
|
156 |
|
21
|
157 |
!MessageTally methodsFor:'probes'!
|
|
158 |
|
|
159 |
count:aContext
|
|
160 |
|con chain info atEnd sender home|
|
0
|
161 |
|
21
|
162 |
con := aContext.
|
|
163 |
con isNil ifTrue:[^ self].
|
0
|
164 |
|
21
|
165 |
ntally := ntally + 1.
|
|
166 |
"walk up above the interrupt context"
|
|
167 |
|
|
168 |
[con receiver == Processor] whileTrue:[
|
|
169 |
con := con sender
|
0
|
170 |
].
|
|
171 |
|
21
|
172 |
"got it - collect info from contexts"
|
|
173 |
|
|
174 |
"walk up"
|
|
175 |
|
|
176 |
con isNil ifTrue:[^ self].
|
|
177 |
|
|
178 |
atEnd := false.
|
0
|
179 |
|
21
|
180 |
[atEnd] whileFalse:[
|
|
181 |
con isNil ifTrue:[
|
|
182 |
atEnd := true
|
|
183 |
] ifFalse:[
|
|
184 |
sender := con sender.
|
|
185 |
sender isNil ifTrue:[
|
|
186 |
atEnd := true
|
|
187 |
] ifFalse:[
|
|
188 |
((sender receiver == self) and:[sender selector == #execute]) ifTrue:[
|
|
189 |
atEnd := true
|
36
|
190 |
"/ ] ifFalse:[
|
|
191 |
"/ (sender isMemberOf:BlockContext) ifTrue:[
|
|
192 |
"/ sender sender selector == #execute ifTrue:[
|
|
193 |
"/ atEnd := true
|
|
194 |
"/ ]
|
|
195 |
"/ ]
|
21
|
196 |
]
|
|
197 |
]
|
|
198 |
].
|
|
199 |
atEnd ifFalse:[
|
|
200 |
info := CallChain new.
|
|
201 |
(con isMemberOf:BlockContext) ifTrue:[
|
|
202 |
home := con methodHome.
|
|
203 |
home isNil ifTrue:[
|
|
204 |
info receiver:UndefinedObject
|
|
205 |
selector:'optimized'
|
|
206 |
class:UndefinedObject.
|
|
207 |
] ifFalse:[
|
|
208 |
info receiver:home receiver class
|
|
209 |
selector:home selector
|
|
210 |
class:con methodClass.
|
|
211 |
].
|
36
|
212 |
info isBlock:true.
|
21
|
213 |
] ifFalse:[
|
|
214 |
info receiver:con receiver class
|
|
215 |
selector:con selector
|
|
216 |
class:con methodClass.
|
|
217 |
].
|
|
218 |
info rest:chain.
|
|
219 |
chain := info.
|
|
220 |
con := sender
|
|
221 |
]
|
|
222 |
].
|
|
223 |
"add chain to the tree"
|
|
224 |
|
|
225 |
chain isNil ifTrue:[^ self].
|
|
226 |
|
|
227 |
tree isNil ifTrue:[
|
|
228 |
tree := ProfileTree new.
|
36
|
229 |
tree receiver:MessageTally
|
|
230 |
selector:#execute
|
|
231 |
class:MessageTally .
|
0
|
232 |
].
|
|
233 |
|
21
|
234 |
tree addChain:chain
|
|
235 |
! !
|
0
|
236 |
|
88
|
237 |
!MessageTally methodsFor:'setup'!
|
|
238 |
|
|
239 |
spyOn:aBlock interval:ms
|
|
240 |
"spy on execution time"
|
|
241 |
|
|
242 |
|startTime endTime running delay|
|
|
243 |
|
|
244 |
theBlock := aBlock.
|
|
245 |
|
|
246 |
Processor activeProcess withPriority:23 do:[
|
|
247 |
process := [
|
|
248 |
[
|
|
249 |
self execute
|
|
250 |
] valueNowOrOnUnwindDo:[
|
|
251 |
running := false.
|
|
252 |
theBlock := nil.
|
|
253 |
]
|
|
254 |
] newProcess.
|
|
255 |
|
|
256 |
Processor activeProcess withPriority:24 do:[
|
|
257 |
startTime := OperatingSystem getMillisecondTime.
|
|
258 |
delay := (Delay forMilliseconds:ms).
|
|
259 |
|
|
260 |
ntally := 0.
|
|
261 |
running := true.
|
|
262 |
process resume.
|
|
263 |
|
|
264 |
[running] whileTrue:[
|
|
265 |
delay wait.
|
|
266 |
self count:process suspendedContext
|
|
267 |
].
|
|
268 |
|
|
269 |
endTime := OperatingSystem getMillisecondTime.
|
|
270 |
].
|
|
271 |
].
|
|
272 |
|
|
273 |
tree notNil ifTrue:[tree computePercentage:ntally].
|
|
274 |
^ endTime - startTime
|
|
275 |
! !
|
|
276 |
|
98
|
277 |
!MessageTally class methodsFor:'documentation'!
|
|
278 |
|
|
279 |
version
|
236
|
280 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTally.st,v 1.18 1996-04-25 17:11:32 cg Exp $'
|
98
|
281 |
! !
|