author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Tue, 16 Jul 2013 14:00:01 +0100 | |
branch | jv |
changeset 3350 | 2331896e5005 |
parent 3329 | a4cbc797038b |
parent 3347 | 9cd0b535463b |
child 3397 | 2932425d1b5c |
permissions | -rw-r--r-- |
8 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 3 |
All Rights Reserved |
8 | 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 |
" |
|
950 | 12 |
"{ Package: 'stx:libbasic3' }" |
13 |
||
120 | 14 |
Object subclass:#MessageTracer |
735 | 15 |
instanceVariableNames:'traceDetail tracedBlock' |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
16 |
classVariableNames:'BreakpointSignal CallingLevel BreakBlock TraceSenderBlock |
664 | 17 |
TraceSenderBlock2 LeaveBreakBlock LeaveTraceBlock MethodCounts |
3308 | 18 |
MethodCountsPerReceiverClass MethodMemoryUsage MethodTiming |
19 |
TraceFullBlock TraceFullBlock2 ObjectWrittenBreakpointSignal |
|
20 |
ObjectCopyHolders TimeForWrappers' |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
21 |
poolDictionaries:'' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
22 |
category:'System-Debugging-Support' |
8 | 23 |
! |
24 |
||
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
25 |
MessageTracer subclass:#InteractionCollector |
735 | 26 |
instanceVariableNames:'' |
27 |
classVariableNames:'' |
|
28 |
poolDictionaries:'' |
|
29 |
privateIn:MessageTracer |
|
30 |
! |
|
31 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
32 |
Object subclass:#MethodTimingInfo |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
33 |
instanceVariableNames:'count minTime maxTime sumTimes avgTime' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
34 |
classVariableNames:'' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
35 |
poolDictionaries:'' |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
36 |
privateIn:MessageTracer |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
37 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
38 |
|
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
39 |
MessageTracer subclass:#PrintingMessageTracer |
2972 | 40 |
instanceVariableNames:'output' |
734 | 41 |
classVariableNames:'' |
42 |
poolDictionaries:'' |
|
43 |
privateIn:MessageTracer |
|
44 |
! |
|
45 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
46 |
!MessageTracer class methodsFor:'documentation'! |
8 | 47 |
|
9 | 48 |
copyright |
49 |
" |
|
50 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 51 |
All Rights Reserved |
9 | 52 |
|
53 |
This software is furnished under a license and may be used |
|
54 |
only in accordance with the terms of that license and with the |
|
55 |
inclusion of the above copyright notice. This software may not |
|
56 |
be provided or otherwise made available to, or used by, any |
|
57 |
other person. No title to or ownership of the software is |
|
58 |
hereby transferred. |
|
59 |
" |
|
60 |
! |
|
61 |
||
8 | 62 |
documentation |
63 |
" |
|
11 | 64 |
This class provides a common home for the tracing |
65 |
facilities (originally, they where in Object, but have been moved to |
|
2972 | 66 |
allow easier separation of development vs. runtime configurations). |
8 | 67 |
|
11 | 68 |
tracing execution of a block: |
69 |
||
236 | 70 |
MessageTracer trace:[ ... ] |
11 | 71 |
|
236 | 72 |
MessageTracer traceFull:[ ... ] |
11 | 73 |
|
825 | 74 |
(for system developer only:) |
11 | 75 |
|
236 | 76 |
MessageTracer debugTrace:[ ... ] |
11 | 77 |
|
78 |
||
8 | 79 |
trapping sends to a specific object: |
80 |
||
236 | 81 |
MessageTracer trap:anObject selector:aSelector |
82 |
... |
|
83 |
MessageTracer untrap:anObject selector:aSelector |
|
84 |
or: |
|
85 |
MessageTracer untrap:anObject |
|
11 | 86 |
|
8 | 87 |
|
88 |
||
27 | 89 |
trapping some messages sent to a specific object: |
90 |
||
236 | 91 |
MessageTracer trap:anObject selectors:aCollectionOfSelectors |
92 |
... |
|
93 |
MessageTracer untrap:anObject |
|
27 | 94 |
|
95 |
||
96 |
||
97 |
trapping any message sent to a specific object: |
|
98 |
||
236 | 99 |
MessageTracer trapAll:anObject |
100 |
... |
|
101 |
MessageTracer untrap:anObject |
|
27 | 102 |
|
103 |
||
104 |
||
8 | 105 |
trapping evaluation of a specific method: |
106 |
||
236 | 107 |
MessageTracer trapMethod:aMethod |
108 |
... |
|
109 |
MessageTracer unwrapMethod:aMethod |
|
8 | 110 |
|
111 |
||
112 |
||
12 | 113 |
trapping evaluation of a specific method with |
114 |
receiver being an instance of some class: |
|
115 |
||
236 | 116 |
MessageTracer trapMethod:aMethod forInstancesOf:aClass |
117 |
... |
|
118 |
MessageTracer unwrapMethod:aMethod |
|
12 | 119 |
|
120 |
||
121 |
||
8 | 122 |
tracing sends to a specific object: |
123 |
||
236 | 124 |
MessageTracer trace:anObject selector:aSelector |
125 |
... |
|
126 |
MessageTracer untrace:anObject selector:aSelector |
|
127 |
or: |
|
128 |
MessageTracer untrace:anObject |
|
11 | 129 |
|
8 | 130 |
|
131 |
||
132 |
tracing sender only: |
|
133 |
||
236 | 134 |
MessageTracer traceSender:anObject selector:aSelector |
135 |
... |
|
136 |
MessageTracer untrace:anObject selector:aSelector |
|
137 |
or: |
|
138 |
MessageTracer untrace:anObject |
|
11 | 139 |
|
8 | 140 |
|
141 |
||
142 |
tracing evaluation of a specific method: |
|
143 |
||
236 | 144 |
MessageTracer traceMethod:aMethod |
145 |
... |
|
146 |
MessageTracer unwrapmethod:aMethod |
|
18 | 147 |
|
148 |
see more in examples and in method comments. |
|
236 | 149 |
|
150 |
[author:] |
|
151 |
Claus Gittinger |
|
8 | 152 |
" |
12 | 153 |
! |
154 |
||
155 |
examples |
|
156 |
" |
|
157 |
For the common cases, you will find a menu entry in the SystemBrowser. |
|
158 |
Howeever, more special cases (especially with condition checks) can be |
|
159 |
set up by evaluating the lower level entries. |
|
160 |
||
161 |
||
162 |
trapping specific methods: |
|
163 |
(by class/selector): |
|
244 | 164 |
[exBegin] |
12 | 165 |
MessageTracer trapClass:Collection selector:#select:. |
591 | 166 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
167 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
168 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 169 |
MessageTracer untrapClass:Collection |
244 | 170 |
[exEnd] |
12 | 171 |
|
172 |
(by method): |
|
244 | 173 |
[exBegin] |
12 | 174 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
591 | 175 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
176 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
177 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 178 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
244 | 179 |
[exEnd] |
12 | 180 |
|
27 | 181 |
(by method & instance class): |
244 | 182 |
[exBegin] |
27 | 183 |
MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:) |
244 | 184 |
forInstancesOf:SortedCollection. |
591 | 185 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
186 |
(Array new:10) select:[:e | ]. 'not caught - not a SortedCollection'. |
|
187 |
OrderedCollection new select:[:e | ]. 'not caught - not a SortedCollection'. |
|
188 |
SortedCollection new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
27 | 189 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:). |
244 | 190 |
[exEnd] |
27 | 191 |
|
12 | 192 |
tracing specific methods: |
193 |
(by class/selector): |
|
244 | 194 |
[exBegin] |
12 | 195 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
196 |
#(6 1 9 66 2 17) copy sort. |
|
197 |
MessageTracer untraceClass:SequenceableCollection |
|
244 | 198 |
[exEnd] |
12 | 199 |
|
200 |
(by method): |
|
244 | 201 |
[exBegin] |
12 | 202 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
203 |
#(6 1 9 66 2 17) copy sort. |
|
204 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
244 | 205 |
[exEnd] |
27 | 206 |
|
207 |
object trapping: |
|
244 | 208 |
[exBegin] |
27 | 209 |
|o| |
210 |
||
211 |
o := OrderedCollection new. |
|
212 |
MessageTracer trapAll:o. |
|
213 |
o collect:[:el | el]. |
|
244 | 214 |
[exEnd] |
661 | 215 |
|
216 |
trapping modifications to an objects instVars: |
|
2972 | 217 |
[exBegin] |
661 | 218 |
|o| |
219 |
||
220 |
o := Point new. |
|
221 |
MessageTracer trapModificationsIn:o. |
|
222 |
o x:1. |
|
223 |
o y:2. |
|
224 |
o x:1. |
|
225 |
o y:2. |
|
226 |
MessageTracer untrap:o |
|
2972 | 227 |
[exEnd] |
661 | 228 |
|
229 |
trapping modifications of a particular instVar: |
|
230 |
[exBegin] |
|
231 |
|o| |
|
232 |
||
233 |
o := Point new. |
|
234 |
MessageTracer trapModificationsIn:o filter:[:old :new | old x ~~ new x]. |
|
235 |
o x:1. |
|
236 |
o y:2. |
|
237 |
o x:1. |
|
238 |
o y:2. |
|
239 |
MessageTracer untrap:o |
|
240 |
[exEnd] |
|
2972 | 241 |
tracing during block execution: |
242 |
[exBegin] |
|
243 |
MessageTracer trace:[ 10 factorialR ] |
|
244 |
[exEnd] |
|
245 |
||
12 | 246 |
" |
8 | 247 |
! ! |
248 |
||
664 | 249 |
!MessageTracer class methodsFor:'Signal constants'! |
250 |
||
251 |
breakpointSignal |
|
252 |
^ BreakpointSignal |
|
253 |
! |
|
254 |
||
255 |
objectWrittenBreakpointSignal |
|
256 |
^ ObjectWrittenBreakpointSignal |
|
257 |
||
258 |
"Created: / 21.4.1998 / 14:38:49 / cg" |
|
259 |
! ! |
|
260 |
||
261 |
!MessageTracer class methodsFor:'class initialization'! |
|
11 | 262 |
|
263 |
initialize |
|
264 |
BreakpointSignal isNil ifTrue:[ |
|
1072 | 265 |
"/ BreakpointSignal := HaltSignal newSignalMayProceed:true. |
266 |
"/ BreakpointSignal nameClass:self message:#breakpointSignal. |
|
267 |
BreakpointSignal := BreakPointInterrupt. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
268 |
BreakpointSignal notifierString:'breakpoint encountered'. |
1072 | 269 |
]. |
270 |
||
271 |
ObjectWrittenBreakpointSignal isNil ifTrue:[ |
|
660 | 272 |
ObjectWrittenBreakpointSignal := BreakpointSignal newSignalMayProceed:true. |
273 |
ObjectWrittenBreakpointSignal nameClass:self message:#objectWrittenBreakpointSignal. |
|
274 |
ObjectWrittenBreakpointSignal notifierString:'object modified'. |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
275 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
276 |
|
1072 | 277 |
"/ the following have been written as cheapBlocks (by purpose) |
278 |
BreakBlock := [:con | BreakpointSignal raiseRequestWith:nil errorString:nil in:con]. |
|
279 |
TraceSenderBlock := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Stderr) ]. |
|
280 |
TraceSenderBlock2 := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Transcript) ]. |
|
281 |
TraceFullBlock := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Stderr) ]. |
|
282 |
TraceFullBlock2 := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Transcript) ]. |
|
2523 | 283 |
LeaveBreakBlock := [:con :retVal | retVal ]. |
284 |
LeaveTraceBlock := [:con :retVal | retVal ]. |
|
1072 | 285 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
286 |
ObjectMemory addDependent:self. |
156 | 287 |
|
288 |
" |
|
289 |
BreakpointSignal := nil. |
|
290 |
MessageTracer initialize |
|
291 |
" |
|
292 |
||
2523 | 293 |
"Modified: / 15-09-2011 / 19:02:13 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
294 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
295 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
296 |
update:something with:parameter from:changedObject |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
297 |
"sent when restarted after a snapIn" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
298 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
299 |
(something == #restarted) ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
300 |
TimeForWrappers := nil |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
301 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
302 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
303 |
"Created: / 30.7.1998 / 17:00:09 / cg" |
11 | 304 |
! ! |
305 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
306 |
!MessageTracer class methodsFor:'class tracing'! |
88 | 307 |
|
308 |
untraceAllClasses |
|
309 |
"remove all traces of messages sent to any class" |
|
310 |
||
311 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
312 |
trace facilities ..." |
|
313 |
||
314 |
^ self untrapAllClasses |
|
315 |
! |
|
316 |
||
317 |
untraceClass:aClass |
|
318 |
"remove all traces of messages sent to instances of aClass" |
|
319 |
||
320 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
321 |
trace facilities ..." |
|
322 |
||
323 |
^ self untrapClass:aClass |
|
324 |
! ! |
|
325 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
326 |
!MessageTracer class methodsFor:'class wrapping'! |
88 | 327 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
328 |
wrapClass:orgClass selector:aSelector onEntry:entryBlock onExit:exitBlock |
88 | 329 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
330 |
aSelector is sent to instances of orgClass or subclasses. |
88 | 331 |
EntryBlock will be called on entry, and get the current context passed as argument. |
332 |
ExitBlock will be called, when the method is left, and get context and the methods return value as arguments. |
|
333 |
" |
|
334 |
||
1452 | 335 |
|myMetaclass trapMethod s spec implClass newClass dict| |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
336 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
337 |
WrappedMethod autoload. "/ just to make sure ... |
88 | 338 |
|
339 |
" |
|
340 |
create a new method, which calls the original one, |
|
341 |
but only if not already being trapped. |
|
342 |
" |
|
343 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
344 |
||
345 |
s := WriteStream on:String new. |
|
346 |
s nextPutAll:spec. |
|
347 |
s cr. |
|
3286 | 348 |
s nextPutAll:'<context: #return>'; cr. |
88 | 349 |
s nextPutAll:'|retVal stubClass|'; cr. |
350 |
entryBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
351 |
s nextPutAll:'#literal1 yourself value:thisContext.'; cr. |
88 | 352 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
353 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a literal to be replaced by theoriginal method |
88 | 354 |
s nextPutAll:('retVal := super ' , spec , '.'); cr. |
355 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
356 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal.'; cr. |
88 | 357 |
]. |
358 |
s nextPutAll:'^ retVal'; cr. |
|
359 |
||
1452 | 360 |
ParserFlags |
361 |
withSTCCompilation:#never |
|
362 |
do:[ |
|
363 |
Class withoutUpdatingChangesDo:[ |
|
3286 | 364 |
trapMethod := Compiler |
365 |
compile:s contents |
|
366 |
forClass:orgClass |
|
1452 | 367 |
inCategory:'trapping' |
3286 | 368 |
notifying:nil |
369 |
install:false |
|
1452 | 370 |
skipIfSame:false |
3286 | 371 |
silent:true. |
1452 | 372 |
] |
373 |
]. |
|
88 | 374 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
375 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
376 |
implClass isNil ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
377 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
378 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
379 |
trapMethod changeLiteral:#originalMethod to:(implClass compiledMethodAt:aSelector). |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
380 |
]. |
88 | 381 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
382 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
88 | 383 |
]. |
384 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
385 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
88 | 386 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
387 |
|
88 | 388 |
" |
389 |
change the source of this new method |
|
390 |
(to avoid confusion in the debugger ...) |
|
391 |
" |
|
392 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
393 |
trapMethod changeClassTo:WrappedMethod. |
2396 | 394 |
trapMethod register. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
395 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
396 |
dict := orgClass methodDictionary. |
88 | 397 |
|
398 |
" |
|
399 |
if not already trapping, create a new class |
|
400 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
401 |
orgClass category == #'* trapping *' ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
402 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
403 |
orgClass methodDictionary:dict. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
404 |
newClass := orgClass superclass. |
88 | 405 |
] ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
406 |
myMetaclass := orgClass class. |
88 | 407 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
408 |
newClass := myMetaclass copy new. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
409 |
newClass setSuperclass:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
410 |
newClass instSize:orgClass instSize. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
411 |
newClass flags:orgClass flags. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
412 |
newClass setClassVariableString:orgClass classVariableString. |
2310 | 413 |
newClass setSharedPoolNames:(orgClass sharedPoolNames). |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
414 |
newClass setInstanceVariableString:orgClass instanceVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
415 |
newClass setName:orgClass name. |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
416 |
newClass setCategory:orgClass category. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
417 |
newClass methodDictionary:dict. |
88 | 418 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
419 |
orgClass setSuperclass:newClass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
420 |
orgClass setClassVariableString:''. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
421 |
orgClass setInstanceVariableString:''. |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
422 |
orgClass setCategory:#'* trapping *'. |
88 | 423 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
424 |
dict := MethodDictionary new:1. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
425 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
426 |
orgClass methodDictionary:dict. |
88 | 427 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
428 |
trapMethod changeLiteral:(newClass superclass) to:newClass. |
88 | 429 |
|
430 |
ObjectMemory flushCaches. |
|
431 |
||
432 |
" |
|
433 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
434 |
wrapClass:Point |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
435 |
selector:#scaleBy: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
436 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
437 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
438 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
439 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
440 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
441 |
]. |
88 | 442 |
(1@2) scaleBy:5. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
443 |
MessageTracer untrapClass:Point selector:#scaleBy:. |
88 | 444 |
(1@2) scaleBy:5. |
445 |
" |
|
446 |
" |
|
447 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
448 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
449 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
450 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
451 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
452 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
453 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
454 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
455 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
456 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
457 |
]. |
258 | 458 |
Transcript showCR:'5 factorial traced'. |
88 | 459 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
460 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 461 |
Transcript showCR:'5 factorial normal'. |
88 | 462 |
5 factorial. |
463 |
" |
|
464 |
" |
|
465 |
|lvl| |
|
466 |
||
467 |
lvl := 0. |
|
468 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
469 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
470 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
471 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
472 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
473 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
474 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
475 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
476 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
477 |
Transcript show:('leave ' , con receiver printString , '>>factorial; returning:'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
478 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
479 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
480 |
]. |
258 | 481 |
Transcript showCR:'5 factorial traced'. |
88 | 482 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
483 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 484 |
Transcript showCR:'5 factorial normal'. |
88 | 485 |
5 factorial. |
486 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
487 |
|
2310 | 488 |
"Modified: / 25-06-1996 / 22:01:05 / stefan" |
2396 | 489 |
"Modified: / 01-07-2011 / 10:01:59 / cg" |
88 | 490 |
! ! |
491 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
492 |
!MessageTracer class methodsFor:'cleanup'! |
27 | 493 |
|
494 |
cleanup |
|
495 |
"if you forgot which classes/methods where wrapped and/or trapped, |
|
496 |
this cleans up everything ..." |
|
497 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
498 |
ObjectCopyHolders := nil. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
499 |
MethodCounts := MethodMemoryUsage := MethodTiming := TimeForWrappers := nil. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
500 |
|
27 | 501 |
self untrapAllClasses. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
502 |
self unwrapAllMethods. |
27 | 503 |
|
504 |
" |
|
505 |
MessageTracer cleanup |
|
506 |
" |
|
507 |
! ! |
|
508 |
||
1082 | 509 |
!MessageTracer class methodsFor:'execution trace'! |
88 | 510 |
|
511 |
debugTrace:aBlock |
|
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
512 |
"trace execution of aBlock. This is for system debugging only; |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
513 |
The trace output is a low level trace generated in the VM." |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
514 |
|
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
515 |
ObjectMemory sendTraceOn. |
1139
56861678ff27
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1082
diff
changeset
|
516 |
^ aBlock ensure:[ObjectMemory sendTraceOff] |
11 | 517 |
|
88 | 518 |
" |
519 |
MessageTracer debugTrace:[#(6 5 4 3 2 1) sort] |
|
520 |
" |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
521 |
|
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
522 |
"Modified: / 31.7.1998 / 16:39:43 / cg" |
88 | 523 |
! |
11 | 524 |
|
525 |
trace:aBlock |
|
526 |
"evaluate aBlock sending trace information to stdout. |
|
27 | 527 |
Return the value of the block." |
11 | 528 |
|
2972 | 529 |
^ self trace:aBlock on:Stderr |
11 | 530 |
|
531 |
" |
|
532 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] |
|
533 |
" |
|
534 |
! |
|
535 |
||
2972 | 536 |
trace:aBlock on:aStream |
537 |
"evaluate aBlock sending trace information to stdout. |
|
538 |
Return the value of the block." |
|
539 |
||
540 |
^ PrintingMessageTracer new |
|
541 |
output:aStream; |
|
542 |
trace:aBlock detail:false. |
|
543 |
||
544 |
" |
|
545 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] on:Transcript |
|
546 |
" |
|
547 |
! |
|
548 |
||
11 | 549 |
traceFull:aBlock |
550 |
"evaluate aBlock sending trace information to stdout. |
|
551 |
Return the value of the block. |
|
27 | 552 |
The trace information is more detailed." |
11 | 553 |
|
2972 | 554 |
^ self traceFull:aBlock on:Stderr |
555 |
||
556 |
" |
|
557 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
558 |
" |
|
559 |
! |
|
560 |
||
561 |
traceFull:aBlock on:aStream |
|
562 |
"evaluate aBlock sending trace information to stdout. |
|
563 |
Return the value of the block. |
|
564 |
The trace information is more detailed." |
|
565 |
||
566 |
^ PrintingMessageTracer new |
|
567 |
output:aStream; |
|
568 |
trace:aBlock detail:true. |
|
11 | 569 |
|
570 |
" |
|
571 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
572 |
" |
|
734 | 573 |
! |
574 |
||
575 |
traceFullIndented:aBlock |
|
576 |
"evaluate aBlock sending trace information to stdout. |
|
577 |
Return the value of the block. |
|
578 |
The trace information is more detailed." |
|
579 |
||
2972 | 580 |
^ self traceFullIndented:aBlock on:Stderr |
581 |
||
582 |
" |
|
583 |
MessageTracer traceFullIndented:[ #(6 5 4 3 2 1) sort ] |
|
584 |
" |
|
585 |
! |
|
586 |
||
587 |
traceFullIndented:aBlock on:aStream |
|
588 |
"evaluate aBlock sending trace information to stdout. |
|
589 |
Return the value of the block. |
|
590 |
The trace information is more detailed." |
|
591 |
||
592 |
^ PrintingMessageTracer new |
|
593 |
output:aStream; |
|
594 |
trace:aBlock detail:#fullIndent. |
|
734 | 595 |
|
596 |
" |
|
597 |
MessageTracer traceFullIndented:[ #(6 5 4 3 2 1) sort ] |
|
598 |
" |
|
599 |
! |
|
600 |
||
601 |
traceIndented:aBlock |
|
602 |
"evaluate aBlock sending trace information to stdout. |
|
603 |
Return the value of the block." |
|
604 |
||
2972 | 605 |
^ self traceIndented:aBlock on:Stderr |
734 | 606 |
|
607 |
" |
|
608 |
MessageTracer traceIndented:[ #(6 5 4 3 2 1) sort ] |
|
609 |
" |
|
2972 | 610 |
! |
611 |
||
612 |
traceIndented:aBlock on:aStream |
|
613 |
"evaluate aBlock sending trace information to stdout. |
|
614 |
Return the value of the block." |
|
615 |
||
616 |
^ PrintingMessageTracer new |
|
617 |
output:aStream; |
|
618 |
trace:aBlock detail:#indent. |
|
619 |
||
620 |
" |
|
621 |
MessageTracer traceIndented:[ #(6 5 4 3 2 1) sort ] on:Transcript |
|
622 |
" |
|
88 | 623 |
! ! |
624 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
625 |
!MessageTracer class methodsFor:'method breakpointing'! |
88 | 626 |
|
627 |
trapClass:aClass selector:aSelector |
|
628 |
"arrange for the debugger to be entered when a message with aSelector is |
|
629 |
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap. |
|
630 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
631 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
632 |
entry/leave blocks." |
|
633 |
||
634 |
self trapMethod:(aClass compiledMethodAt:aSelector) |
|
635 |
||
636 |
" |
|
637 |
MessageTracer trapClass:Collection selector:#select:. |
|
591 | 638 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
639 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
640 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 641 |
MessageTracer untrapClass:Collection |
642 |
" |
|
11 | 643 |
! |
644 |
||
88 | 645 |
trapMethod:aMethod |
646 |
"arrange for the debugger to be entered when aMethod is about to be executed. |
|
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
647 |
The trap is enabled for any process - see #trapMethod:inProcess: for a more |
495 | 648 |
selective breakPoint. |
88 | 649 |
Use unwrapMethod or untrapClass to remove this trap. |
650 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
651 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
652 |
entry/leave blocks." |
|
653 |
||
654 |
^ self wrapMethod:aMethod |
|
495 | 655 |
onEntry:BreakBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
656 |
onExit:LeaveBreakBlock. |
88 | 657 |
|
658 |
" |
|
659 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
|
591 | 660 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
661 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
662 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 663 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
664 |
" |
|
495 | 665 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
666 |
"Modified: 22.10.1996 / 17:39:58 / cg" |
88 | 667 |
! |
11 | 668 |
|
908 | 669 |
trapMethod:aMethod after:countInvocations |
670 |
"arrange for the debugger to be entered when aMethod has been invoked countInvocations times. |
|
671 |
The trap is enabled for any process. |
|
672 |
Use unwrapMethod or untrapClass to remove this trap. |
|
673 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
674 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
675 |
entry/leave blocks." |
|
676 |
||
677 |
|n| |
|
678 |
||
679 |
n := 0. |
|
680 |
^ self wrapMethod:aMethod |
|
681 |
onEntry:[:con | n := n + 1. |
|
682 |
n > countInvocations |
|
683 |
ifTrue:[ |
|
684 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
685 |
] |
|
686 |
] |
|
687 |
onExit:LeaveBreakBlock. |
|
688 |
||
689 |
! |
|
690 |
||
88 | 691 |
trapMethod:aMethod forInstancesOf:aClass |
692 |
"arrange for the debugger to be entered when aMethod is about to be executed |
|
693 |
for an instance of aClass. |
|
694 |
Use unwrapMethod or untrapClass to remove this trap. |
|
695 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
696 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
697 |
entry/leave blocks." |
|
698 |
||
699 |
^ self wrapMethod:aMethod |
|
809 | 700 |
onEntry:[:con | |
701 |
(con receiver isMemberOf:aClass) ifTrue:[ |
|
702 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
703 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
704 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
705 |
onExit:LeaveBreakBlock. |
88 | 706 |
|
707 |
" |
|
708 |
MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView. |
|
709 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
710 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
711 |
"Modified: 22.10.1996 / 17:40:03 / cg" |
88 | 712 |
! |
713 |
||
950 | 714 |
trapMethod:aMethod if:conditionBlock |
715 |
"arrange for the debugger to be entered when aMethod has been invoked and conditionBlock |
|
716 |
evaluates to true. |
|
717 |
The trap is enabled for any process. |
|
718 |
Use unwrapMethod or untrapClass to remove this trap. |
|
719 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
720 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
721 |
entry/leave blocks." |
|
722 |
||
2291 | 723 |
^ self |
724 |
wrapMethod:aMethod |
|
725 |
onEntry:[:con | |
|
726 |
|conditionFires| |
|
727 |
||
728 |
Error handle:[:ex | |
|
729 |
'MessageTrace: error in breakpoint condition cought: ' errorPrint. |
|
730 |
ex description errorPrintCR. |
|
731 |
] do:[ |
|
732 |
conditionBlock numArgs == 1 ifTrue:[ |
|
733 |
conditionFires := conditionBlock value:con |
|
734 |
] ifFalse:[ |
|
735 |
conditionFires := conditionBlock value:con value:aMethod |
|
736 |
]. |
|
737 |
]. |
|
738 |
conditionFires == true ifTrue:[ |
|
739 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
|
740 |
] |
|
741 |
] |
|
742 |
onExit:LeaveBreakBlock. |
|
743 |
||
744 |
"Created: / 18-08-2000 / 22:09:10 / cg" |
|
745 |
"Modified: / 20-10-2010 / 09:38:57 / cg" |
|
950 | 746 |
! |
747 |
||
496 | 748 |
trapMethod:aMethod inProcess:aProcess |
495 | 749 |
"arrange for the debugger to be entered when aMethod is about to be executed, |
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
750 |
but only, if executed aProcess or one of aProcess's offspring. |
495 | 751 |
This allows for breakpoints to be set on system-critical code. |
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
752 |
The trap will only fire for selected processes (making browsers etc. still usable). |
495 | 753 |
Use unwrapMethod or untrapClass to remove this trap. |
754 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
755 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
756 |
entry/leave blocks." |
|
757 |
||
758 |
^ self wrapMethod:aMethod |
|
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
759 |
onEntry:[:con | |
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
760 |
(Processor activeProcess processGroupId = aProcess id) ifTrue:[ |
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
761 |
BreakpointSignal raiseRequestWith:nil errorString:nil in:con |
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
762 |
] |
495 | 763 |
] |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
764 |
onExit:LeaveBreakBlock. |
495 | 765 |
|
496 | 766 |
"Created: 14.10.1996 / 15:38:46 / cg" |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
767 |
"Modified: 22.10.1996 / 17:40:06 / cg" |
495 | 768 |
! |
769 |
||
88 | 770 |
untrapAllClasses |
771 |
"remove any traps on any class" |
|
772 |
||
970 | 773 |
Smalltalk allClassesDo:[:aClass | |
774 |
self untrapClass:aClass |
|
11 | 775 |
] |
776 |
||
777 |
" |
|
88 | 778 |
MessageTracer untrapAllClasses |
779 |
" |
|
780 |
! |
|
781 |
||
782 |
untrapClass:aClass |
|
783 |
"remove any traps on aClass" |
|
784 |
||
785 |
"this is done by just patching the class back to the original" |
|
786 |
||
787 |
|orgClass| |
|
788 |
||
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
789 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
790 |
^ self |
88 | 791 |
]. |
792 |
orgClass := aClass superclass. |
|
793 |
||
794 |
aClass setSuperclass:orgClass superclass. |
|
795 |
aClass setClassVariableString:orgClass classVariableString. |
|
2310 | 796 |
aClass setSharedPoolNames:(orgClass sharedPoolNames). |
88 | 797 |
aClass setInstanceVariableString:orgClass instanceVariableString. |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
798 |
aClass setCategory:orgClass category. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
799 |
aClass methodDictionary:orgClass methodDictionary. |
88 | 800 |
|
801 |
ObjectMemory flushCaches. |
|
802 |
||
803 |
" |
|
804 |
MessageTracer untrapClass:Point |
|
11 | 805 |
" |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
806 |
|
2310 | 807 |
"Modified: / 05-06-1996 / 13:57:39 / stefan" |
808 |
"Modified: / 18-01-2011 / 20:43:50 / cg" |
|
88 | 809 |
! |
810 |
||
811 |
untrapClass:aClass selector:aSelector |
|
812 |
"remove trap of aSelector sent to aClass" |
|
813 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
814 |
|dict| |
88 | 815 |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
816 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
817 |
^ self |
88 | 818 |
]. |
819 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
820 |
dict := aClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
821 |
dict at:aSelector ifAbsent:[^ self]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
822 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
823 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
824 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
825 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
826 |
"the last trapped method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
827 |
^ self untrapClass:aClass |
88 | 828 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
829 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
830 |
aClass methodDictionary:dict. |
88 | 831 |
|
832 |
" |
|
833 |
MessageTracer trapClass:Point selector:#copy. |
|
834 |
(1@2) copy. |
|
835 |
(1@2) deepCopy. |
|
836 |
MessageTracer trapClass:Point selector:#deepCopy. |
|
837 |
(1@2) copy. |
|
838 |
(1@2) deepCopy. |
|
839 |
MessageTracer untrapClass:Point selector:#copy. |
|
840 |
(1@2) copy. |
|
841 |
(1@2) deepCopy. |
|
842 |
MessageTracer untrapClass:Point selector:#deepCopy. |
|
843 |
(1@2) copy. |
|
844 |
(1@2) deepCopy. |
|
845 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
846 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
847 |
"Modified: 5.6.1996 / 14:00:55 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
848 |
"Modified: 10.9.1996 / 20:06:29 / cg" |
88 | 849 |
! |
850 |
||
851 |
untrapMethod:aMethod |
|
852 |
"remove break on aMethod" |
|
853 |
||
854 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
855 |
trace facilities ..." |
|
856 |
||
857 |
^ self unwrapMethod:aMethod |
|
11 | 858 |
! ! |
859 |
||
3238
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
860 |
!MessageTracer class methodsFor:'method breakpointing - new'! |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
861 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
862 |
breakMethod: method atLine: line |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
863 |
"Installs new breakpoint in given method at given line. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
864 |
Returns the installed breakpoint or nil if none could be |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
865 |
installed" |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
866 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
867 |
| analyzer map lines i breakpoint table | |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
868 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
869 |
(ConfigurableFeatures includesFeature: #VMBreakpointSupport) ifFalse:[ |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
870 |
self error: 'Breakpoint support not present'. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
871 |
^nil. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
872 |
]. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
873 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
874 |
analyzer := BreakpointAnalyzer parseMethodSilent: method source in: method mclass. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
875 |
map := analyzer messageSendMap. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
876 |
lines := map keys asSortedCollection. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
877 |
i := lines indexForInserting: line. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
878 |
i > lines size ifTrue:[ |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
879 |
^nil |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
880 |
]. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
881 |
breakpoint := Breakpoint new line: (lines at: i). |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
882 |
breakpoint breaksToIgnore: (((map at: breakpoint line) size - 1) max: 0). |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
883 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
884 |
table := method breakpointTable. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
885 |
table isNil ifTrue:[ |
3240
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
886 |
"/old way: |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
887 |
"/table := Array with: (breakpoint line) with: breakpoint. |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
888 |
|
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
889 |
"/new way: |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
890 |
table := Array with: breakpoint. |
3238
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
891 |
] ifFalse:[ |
3240
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
892 |
"/old way: |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
893 |
"/table := table, (Array with: (breakpoint line) with: breakpoint). |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
894 |
|
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
895 |
"/new way: |
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
896 |
table := table copyWith: breakpoint |
3238
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
897 |
]. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
898 |
method breakpointTable: table. |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
899 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
900 |
^breakpoint |
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
901 |
|
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
902 |
"Created: / 16-04-2013 / 00:25:43 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3240
7d753640035b
Updated to single array (not alternating line/breakpoint)
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3239
diff
changeset
|
903 |
"Modified: / 24-04-2013 / 19:40:10 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
3238
ce14576bac56
Initial support for new breakpoint implementation.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3158
diff
changeset
|
904 |
! ! |
3158
f8c56a311307
Merged 87750af738dc and 72ca7e81fbbf (branch default - CVS HEAD)
Jan Vrany <jan.vrany@fit.cvut.cz>
diff
changeset
|
905 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
906 |
!MessageTracer class methodsFor:'method counting'! |
155 | 907 |
|
908 |
countMethod:aMethod |
|
2972 | 909 |
"arrange for a aMethod's execution to be counted. |
155 | 910 |
Use unwrapMethod to remove this." |
911 |
||
912 |
MethodCounts isNil ifTrue:[ |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
913 |
MethodCounts := IdentityDictionary new. |
155 | 914 |
]. |
915 |
MethodCounts at:aMethod put:0. |
|
916 |
||
917 |
^ self wrapMethod:aMethod |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
918 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
919 |
|cnt| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
920 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
921 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
922 |
MethodCounts at:aMethod put:(cnt + 1). |
2972 | 923 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
924 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
925 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
926 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
927 |
] |
155 | 928 |
|
929 |
" |
|
930 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
931 |
5 factorial. |
|
932 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
933 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
934 |
" |
|
935 |
||
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
936 |
"Created: / 15.12.1995 / 10:57:49 / cg" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
937 |
"Modified: / 27.7.1998 / 10:47:46 / cg" |
155 | 938 |
! |
939 |
||
3308 | 940 |
countMethodByReceiverClass:aMethod |
941 |
"arrange for a aMethod's execution to be counted and maintain |
|
942 |
a per-receiver class profile. |
|
943 |
Use unwrapMethod to remove this." |
|
944 |
||
945 |
MethodCountsPerReceiverClass isNil ifTrue:[ |
|
946 |
MethodCountsPerReceiverClass := IdentityDictionary new. |
|
947 |
]. |
|
948 |
MethodCountsPerReceiverClass at:aMethod put:(IdentityDictionary new). |
|
949 |
||
950 |
^ self wrapMethod:aMethod |
|
951 |
onEntry:[:con | |
|
952 |
|cls perMethodCounts cnt| |
|
953 |
||
954 |
cls := (con receiver class). |
|
955 |
perMethodCounts := MethodCountsPerReceiverClass at:aMethod. |
|
956 |
cnt := perMethodCounts at:cls ifAbsentPut:0. |
|
957 |
perMethodCounts at:cls put:(cnt + 1). |
|
958 |
MessageTracer changed:#statistics: with:aMethod. |
|
959 |
aMethod changed:#statistics |
|
960 |
] |
|
961 |
onExit:[:con :retVal | |
|
962 |
] |
|
963 |
||
964 |
" |
|
965 |
MessageTracer countMethodWithReceiverStatistic:(Collection compiledMethodAt:#detect:). |
|
966 |
NewSystemBrowser open. |
|
967 |
MessageTracer executionCountsOf:(Collection compiledMethodAt:#detect:) printNL. |
|
968 |
MessageTracer stopCountingMethod:(Collection compiledMethodAt:#detect:) |
|
969 |
" |
|
970 |
! |
|
971 |
||
155 | 972 |
executionCountOfMethod:aMethod |
973 |
"return the current count" |
|
974 |
||
3308 | 975 |
|count counts| |
976 |
||
977 |
MethodCounts notNil ifTrue:[ |
|
978 |
aMethod isWrapped ifTrue:[ |
|
979 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
|
980 |
count notNil ifTrue:[^ count]. |
|
981 |
]. |
|
982 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
983 |
]. |
|
984 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
985 |
aMethod isWrapped ifTrue:[ |
|
986 |
counts := MethodCountsPerReceiverClass at:aMethod originalMethod ifAbsent:nil. |
|
987 |
]. |
|
988 |
counts isNil ifTrue:[ |
|
989 |
counts := MethodCounts at:aMethod ifAbsent:#(). |
|
990 |
]. |
|
991 |
^ (counts collect:[:eachClassCountAssoc | eachClassCountAssoc value]) sum |
|
155 | 992 |
]. |
3308 | 993 |
^ 0 |
994 |
! |
|
995 |
||
996 |
executionCountsByReceiverClassOfMethod:aMethod |
|
997 |
"return a collection mapping receiver class to call counts" |
|
998 |
||
999 |
|counts| |
|
1000 |
||
1001 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
1002 |
aMethod isWrapped ifTrue:[ |
|
1003 |
counts := MethodCountsPerReceiverClass at:aMethod originalMethod ifAbsent:nil. |
|
1004 |
]. |
|
1005 |
counts isNil ifTrue:[ |
|
1006 |
counts := MethodCounts at:aMethod ifAbsent:#(). |
|
1007 |
]. |
|
1008 |
^ counts |
|
1009 |
]. |
|
1010 |
^ #() |
|
155 | 1011 |
! |
1012 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1013 |
resetCountOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1014 |
"return the current count" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1015 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1016 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1017 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1018 |
MethodCounts at:aMethod originalMethod put:0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1019 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1020 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1021 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1022 |
"Created: / 30.7.1998 / 17:42:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1023 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1024 |
|
155 | 1025 |
stopCountingMethod:aMethod |
1026 |
"remove counting of aMethod" |
|
1027 |
||
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1028 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1029 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1030 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1031 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1032 |
]. |
3308 | 1033 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
1034 |
aMethod isWrapped ifTrue:[ |
|
1035 |
MethodCountsPerReceiverClass removeKey:aMethod originalMethod ifAbsent:nil. |
|
1036 |
]. |
|
1037 |
]. |
|
155 | 1038 |
^ self unwrapMethod:aMethod |
1039 |
||
1040 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
1041 |
! ! |
|
1042 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1043 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1044 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1045 |
countMemoryUsageOfMethod:aMethod |
2972 | 1046 |
"arrange for aMethod's memory usage to be counted. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1047 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1048 |
|
501 | 1049 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1050 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1051 |
MethodCounts isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1052 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1053 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1054 |
MethodMemoryUsage isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1055 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1056 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1057 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1058 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1059 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1060 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1061 |
^ self wrapMethod:aMethod |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1062 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1063 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1064 |
oldNewUsed := ObjectMemory newSpaceUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1065 |
oldScavengeCount := ObjectMemory scavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1066 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1067 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1068 |
|cnt memUse scavenges| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1069 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1070 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1071 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1072 |
scavenges ~= 0 ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1073 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1074 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1075 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1076 |
MethodCounts notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1077 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1078 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1079 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1080 |
MethodMemoryUsage notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1081 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1082 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1083 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1084 |
Processor activeProcess priority:oldPriority. |
2972 | 1085 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1086 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1087 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1088 |
onUnwind:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1089 |
oldPriority notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1090 |
Processor activeProcess priority:oldPriority |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1091 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1092 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1093 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1094 |
" |
2825
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1095 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR). |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1096 |
3 factorialR. |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1097 |
Transcript showCR:(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorialR)). |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1098 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR) |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1099 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1100 |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1101 |
"Created: / 18.12.1995 / 15:41:27 / stefan" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1102 |
"Modified: / 18.12.1995 / 21:46:48 / stefan" |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1103 |
"Modified: / 27.7.1998 / 10:47:38 / cg" |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1104 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1105 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1106 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1107 |
"return true if aMethod is counting memoryUsage" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1108 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1109 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1110 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1111 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1112 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1113 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1114 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1115 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1116 |
"Created: 18.12.1995 / 15:51:49 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1117 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1118 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1119 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1120 |
"return the current count" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1121 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1122 |
|count memUse orgMethod| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1123 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1124 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1125 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1126 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1127 |
count := MethodCounts at:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1128 |
memUse := MethodMemoryUsage at:orgMethod ifAbsent:nil. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1129 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1130 |
memUse isNil ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1131 |
count := MethodCounts at:aMethod ifAbsent:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1132 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1133 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1134 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1135 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1136 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1137 |
"Modified: 18.12.1995 / 16:25:51 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1138 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1139 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1140 |
resetMemoryUsageOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1141 |
"reset the current usage" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1142 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1143 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1144 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1145 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1146 |
MethodMemoryUsage notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1147 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1148 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1149 |
MethodCounts at:orgMethod put:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1150 |
MethodMemoryUsage at:orgMethod put:nil. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1151 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1152 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1153 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1154 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1155 |
"Created: / 30.7.1998 / 17:43:07 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1156 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1157 |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1158 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1159 |
"remove counting memory of aMethod" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1160 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1161 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1162 |
|
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1163 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1164 |
MethodMemoryUsage notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1165 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1166 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1167 |
MethodCounts removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1168 |
MethodMemoryUsage removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1169 |
] |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1170 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1171 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1172 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1173 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1174 |
"Modified: 18.12.1995 / 21:54:36 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1175 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1176 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1177 |
!MessageTracer class methodsFor:'method timing'! |
327 | 1178 |
|
1179 |
executionTimesOfMethod:aMethod |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1180 |
"return the current gathered execution time statistics" |
327 | 1181 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1182 |
|info| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1183 |
|
327 | 1184 |
MethodTiming notNil ifTrue:[ |
1185 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1186 |
info := ( MethodTiming at:(aMethod originalMethod) ifAbsent:nil ) copy. |
327 | 1187 |
]. |
1188 |
]. |
|
1189 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1190 |
info isNil ifTrue:[ info := MethodTimingInfo new ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1191 |
^ info |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1192 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1193 |
"Created: / 17-06-1996 / 17:07:30 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1194 |
"Modified: / 05-03-2007 / 15:46:17 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1195 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1196 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1197 |
resetExecutionTimesOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1198 |
"reset the gathered execution times statistics for aMethod; |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1199 |
the method remains wrapped." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1200 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1201 |
MethodTiming notNil ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1202 |
MethodTiming removeKey:aMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1203 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1204 |
MethodTiming removeKey:aMethod originalMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1205 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1206 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1207 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1208 |
"Created: / 30-07-1998 / 17:12:35 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1209 |
"Modified: / 05-03-2007 / 15:36:59 / cg" |
327 | 1210 |
! |
1211 |
||
1212 |
stopTimingMethod:aMethod |
|
1213 |
"remove timing of aMethod" |
|
1214 |
||
1215 |
^ self unwrapMethod:aMethod |
|
1216 |
||
1217 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
1218 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
1219 |
! |
|
1220 |
||
1221 |
timeMethod:aMethod |
|
2972 | 1222 |
"arrange for a aMethod's execution time to be measured. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1223 |
Use unwrapMethod: or stopTimingMethod: to remove this." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1224 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1225 |
|t0| |
327 | 1226 |
|
1227 |
MethodTiming isNil ifTrue:[ |
|
1228 |
MethodTiming := IdentityDictionary new. |
|
1229 |
]. |
|
1230 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1231 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1232 |
TimeForWrappers isNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1233 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1234 |
]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1235 |
|
327 | 1236 |
^ self wrapMethod:aMethod |
1237 |
onEntry:[:con | |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1238 |
t0 := OperatingSystem getMicrosecondTime. |
327 | 1239 |
] |
1240 |
onExit:[:con :retVal | |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
1241 |
|info t cnt minT maxT sumTimes| |
327 | 1242 |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1243 |
t := OperatingSystem getMicrosecondTime - t0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1244 |
t := t - TimeForWrappers. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1245 |
t < 0 ifTrue:[t := 0]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1246 |
t := t / 1000.0. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1247 |
|
2004 | 1248 |
MethodTiming isNil ifTrue:[ |
1249 |
MethodTiming := IdentityDictionary new. |
|
1250 |
]. |
|
327 | 1251 |
info := MethodTiming at:aMethod ifAbsent:nil. |
1252 |
info isNil ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1253 |
MethodTiming at:aMethod put:(info := MethodTimingInfo new) |
327 | 1254 |
] ifFalse:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1255 |
info rememberExecutionTime:t. |
327 | 1256 |
]. |
2972 | 1257 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1258 |
aMethod changed:#statistics |
327 | 1259 |
] |
1260 |
||
1261 |
" |
|
1262 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
1263 |
5 factorial. |
|
1264 |
5 factorial. |
|
1265 |
5 factorial. |
|
1266 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
1267 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
1268 |
" |
|
1269 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1270 |
"Created: / 17-06-1996 / 17:03:50 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1271 |
"Modified: / 05-03-2007 / 15:34:01 / cg" |
327 | 1272 |
! ! |
1273 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1274 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 1275 |
|
664 | 1276 |
traceClass:aClass selector:aSelector |
1277 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
1278 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1279 |
||
1280 |
self traceClass:aClass selector:aSelector on:Stderr |
|
1281 |
||
1282 |
" |
|
1283 |
MessageTracer traceClass:Integer selector:#factorial. |
|
1284 |
5 factorial. |
|
1285 |
MessageTracer untraceClass:Integer |
|
1286 |
" |
|
1287 |
" |
|
1288 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
1289 |
#(6 1 9 66 2 17) copy sort. |
|
1290 |
MessageTracer untraceClass:SequenceableCollection |
|
1291 |
" |
|
1292 |
" |
|
1293 |
MessageTracer traceClass:Array selector:#at:. |
|
1294 |
MessageTracer traceClass:Array selector:#at:put:. |
|
1295 |
#(6 1 9 66 2 17) copy sort. |
|
1296 |
MessageTracer untraceClass:Array |
|
1297 |
" |
|
1298 |
! |
|
1299 |
||
1300 |
traceClass:aClass selector:aSelector on:aStream |
|
1301 |
"arrange for a trace message to be output on aStream, when a message with aSelector is |
|
1302 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1303 |
||
1304 |
self traceMethod:(aClass compiledMethodAt:aSelector) on:aStream |
|
1305 |
||
1306 |
" |
|
1307 |
MessageTracer traceClass:Integer selector:#factorial on:Transcript. |
|
1308 |
5 factorial. |
|
1309 |
MessageTracer untraceClass:Integer |
|
1310 |
" |
|
1311 |
" |
|
1312 |
MessageTracer traceClass:Integer selector:#factorialR on:Transcript. |
|
1313 |
5 factorialR. |
|
1314 |
MessageTracer untraceClass:Integer |
|
1315 |
" |
|
1316 |
||
1317 |
! |
|
1318 |
||
88 | 1319 |
traceMethod:aMethod |
664 | 1320 |
"arrange for a trace message to be output on Stderr, |
1321 |
when aMethod is executed. Traces both entry and exit. |
|
88 | 1322 |
Use unwrapMethod to remove this." |
1323 |
||
664 | 1324 |
^ self traceMethod:aMethod on:Stderr |
11 | 1325 |
|
1326 |
" |
|
88 | 1327 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
1328 |
5 factorial. |
|
1329 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1330 |
" |
|
1331 |
" |
|
664 | 1332 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR). |
1333 |
5 factorialR. |
|
1334 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1335 |
" |
|
1336 |
" |
|
88 | 1337 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
1338 |
#(6 1 9 66 2 17) copy sort. |
|
1339 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1340 |
" |
|
1341 |
" |
|
1342 |
dont do this: |
|
1343 |
" |
|
1344 |
" |
|
1345 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
1346 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
1347 |
#(6 1 9 66 2 17) copy sort. |
|
1348 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
1349 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 1350 |
" |
1351 |
! |
|
1352 |
||
664 | 1353 |
traceMethod:aMethod on:aStream |
1354 |
"arrange for a trace message to be output on aStream, |
|
1355 |
when aMethod is executed. Traces both entry and exit. |
|
1356 |
Use unwrapMethod to remove this." |
|
1357 |
||
1358 |
|lvl inside| |
|
1359 |
||
1360 |
^ self wrapMethod:aMethod |
|
1361 |
onEntry:[:con | |
|
1362 |
inside isNil ifTrue:[ |
|
1363 |
inside := true. |
|
1364 |
CallingLevel isNil ifTrue:[ |
|
1365 |
CallingLevel := 0. |
|
1366 |
]. |
|
1367 |
lvl notNil ifTrue:[ |
|
1368 |
lvl := lvl + 1 |
|
1369 |
] ifFalse:[ |
|
1370 |
CallingLevel := lvl := CallingLevel + 1. |
|
1371 |
]. |
|
1372 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1373 |
inside := nil |
|
1374 |
] |
|
1375 |
] |
|
1376 |
onExit:[:con :retVal | |
|
1377 |
inside isNil ifTrue:[ |
|
1378 |
inside := true. |
|
1379 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1380 |
CallingLevel := lvl := lvl - 1. |
|
1381 |
inside := nil |
|
1382 |
] |
|
1383 |
] |
|
1384 |
||
1385 |
" |
|
1386 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1387 |
5 factorial. |
|
1388 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1389 |
" |
|
1390 |
" |
|
1391 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1392 |
5 factorialR. |
|
1393 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1394 |
" |
|
1395 |
" |
|
1396 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1397 |
#(6 1 9 66 2 17) copy sort. |
|
1398 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1399 |
" |
|
1400 |
! |
|
1401 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1402 |
traceMethodAll:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1403 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1404 |
Only the sender is traced on entry. |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1405 |
Use untraceMethod to remove this trace. |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1406 |
This is for system debugging only; |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1407 |
The trace output is a low level trace generated in the VM." |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1408 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1409 |
^ self wrapMethod:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1410 |
onEntry:[:con | ObjectMemory flushCaches. ObjectMemory sendTraceOn.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1411 |
onExit:[:con :val | ObjectMemory sendTraceOff.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1412 |
|
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1413 |
"Modified: / 31.7.1998 / 16:40:07 / cg" |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1414 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1415 |
|
664 | 1416 |
traceMethodEntry:aMethod |
1417 |
"arrange for a trace message to be output on stdErr, |
|
1418 |
when aMethod is executed. Only entry is traced. |
|
1419 |
Use unwrapMethod to remove this." |
|
1420 |
||
1421 |
^ self traceMethodEntry:aMethod on:Stderr |
|
1422 |
||
1423 |
" |
|
1424 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial). |
|
1425 |
5 factorial. |
|
1426 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1427 |
" |
|
1428 |
" |
|
1429 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR). |
|
1430 |
5 factorialR. |
|
1431 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1432 |
" |
|
1433 |
" |
|
1434 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1435 |
#(6 1 9 66 2 17) copy sort. |
|
1436 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1437 |
" |
|
1438 |
! |
|
1439 |
||
1440 |
traceMethodEntry:aMethod on:aStream |
|
1441 |
"arrange for a trace message to be output on aStream, |
|
1442 |
when aMethod is executed. Only entry is traced. |
|
1443 |
Use unwrapMethod to remove this." |
|
1444 |
||
1445 |
|lvl inside| |
|
1446 |
||
1447 |
^ self wrapMethod:aMethod |
|
1448 |
onEntry:[:con | |
|
1449 |
inside isNil ifTrue:[ |
|
1450 |
inside := true. |
|
1451 |
CallingLevel isNil ifTrue:[ |
|
1452 |
CallingLevel := 0. |
|
1453 |
]. |
|
1454 |
lvl notNil ifTrue:[ |
|
1455 |
lvl := lvl + 1 |
|
1456 |
] ifFalse:[ |
|
1457 |
CallingLevel := lvl := CallingLevel + 1. |
|
1458 |
]. |
|
1459 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1460 |
inside := nil |
|
1461 |
] |
|
1462 |
] |
|
1463 |
onExit:[:con :retVal |] |
|
1464 |
||
1465 |
" |
|
1466 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1467 |
5 factorial. |
|
1468 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1469 |
" |
|
1470 |
" |
|
1471 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1472 |
5 factorialR. |
|
1473 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1474 |
" |
|
1475 |
" |
|
1476 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1477 |
#(6 1 9 66 2 17) copy sort. |
|
1478 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1479 |
" |
|
1480 |
! |
|
1481 |
||
156 | 1482 |
traceMethodFull:aMethod |
1483 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
1484 |
Only the sender is traced on entry. |
|
1485 |
Use untraceMethod to remove this trace." |
|
1486 |
||
664 | 1487 |
^ self traceMethodFull:aMethod on:Stderr |
1488 |
||
1489 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
1490 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
|
1491 |
! |
|
1492 |
||
1493 |
traceMethodFull:aMethod on:aStream |
|
1494 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
|
1495 |
Only the sender is traced on entry. |
|
1496 |
Use untraceMethod to remove this trace." |
|
1497 |
||
1498 |
^ self |
|
1499 |
wrapMethod:aMethod |
|
1500 |
onEntry:(self traceFullBlockFor:aStream) |
|
1501 |
onExit:LeaveTraceBlock. |
|
156 | 1502 |
|
1503 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1504 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 1505 |
! |
1506 |
||
88 | 1507 |
traceMethodSender:aMethod |
664 | 1508 |
"arrange for a trace message to be output on Stderr, |
1509 |
when amethod is executed. |
|
1510 |
Only the sender is traced on entry. |
|
1511 |
Use untraceMethod to remove this trace." |
|
1512 |
||
1513 |
^ self traceMethodSender:aMethod on:Stderr |
|
1514 |
! |
|
1515 |
||
1516 |
traceMethodSender:aMethod on:aStream |
|
88 | 1517 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
1518 |
Only the sender is traced on entry. |
|
1519 |
Use untraceMethod to remove this trace." |
|
35 | 1520 |
|
664 | 1521 |
^ self |
1522 |
wrapMethod:aMethod |
|
1523 |
onEntry:(self traceSenderBlockFor:aStream) |
|
1524 |
onExit:LeaveTraceBlock. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1525 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1526 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1527 |
! |
1528 |
||
1071 | 1529 |
traceUpdateMethod:aMethod on:aStream |
1530 |
"arrange for a trace message to be output on aStream, |
|
1531 |
when aMethod is executed. |
|
1532 |
Traces both entry and exit. |
|
1533 |
Use unwrapMethod to remove this. |
|
1534 |
This one is specialized for change-update calling i.e. it traces from the update |
|
1535 |
back to the origial change message." |
|
1536 |
||
1537 |
|lvl inside| |
|
1538 |
||
1539 |
^ self |
|
1540 |
wrapMethod:aMethod |
|
1541 |
onEntry:[:con | |
|
1542 |
inside isNil ifTrue:[ |
|
1543 |
inside := true. |
|
1544 |
CallingLevel isNil ifTrue:[ |
|
1545 |
CallingLevel := 0. |
|
1546 |
]. |
|
1547 |
lvl notNil ifTrue:[ |
|
1548 |
lvl := lvl + 1 |
|
1549 |
] ifFalse:[ |
|
1550 |
CallingLevel := lvl := CallingLevel + 1. |
|
1551 |
]. |
|
1552 |
MessageTracer printUpdateEntryFull:con level:lvl on:aStream. |
|
1553 |
inside := nil |
|
1554 |
] |
|
1555 |
] |
|
1556 |
onExit:[:con :retVal | |
|
1557 |
inside isNil ifTrue:[ |
|
1558 |
inside := true. |
|
1559 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1560 |
CallingLevel := lvl := lvl - 1. |
|
1561 |
inside := nil |
|
1562 |
] |
|
1563 |
] |
|
1564 |
! |
|
1565 |
||
3126
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1566 |
tracelogMethod:aMethod |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1567 |
"arrange for a trace log entry to be appended to a standard log using |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1568 |
Logger, when aMethod is executed. Traces both entry and exit. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1569 |
Use unwrapMethod to remove this." |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1570 |
|
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1571 |
|lvl inside| |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1572 |
|
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1573 |
^ self wrapMethod:aMethod |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1574 |
onEntry:[:con | |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1575 |
| msg | |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1576 |
inside isNil ifTrue:[ |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1577 |
inside := true. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1578 |
CallingLevel isNil ifTrue:[ |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1579 |
CallingLevel := 0. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1580 |
]. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1581 |
lvl notNil ifTrue:[ |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1582 |
lvl := lvl + 1 |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1583 |
] ifFalse:[ |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1584 |
CallingLevel := lvl := CallingLevel + 1. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1585 |
]. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1586 |
msg := String streamContents:[:s|MessageTracer printEntryFull:con level:lvl on:s]. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1587 |
Logger log: msg severity: #trace attachment: con args. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1588 |
inside := nil |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1589 |
] |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1590 |
] |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1591 |
onExit:[:con :retVal | |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1592 |
| msg | |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1593 |
inside isNil ifTrue:[ |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1594 |
inside := true. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1595 |
msg := String streamContents:[:s|MessageTracer printExit:con with:retVal level:lvl on:s]. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1596 |
Logger log: msg severity: #trace attachment: retVal. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1597 |
CallingLevel := lvl := lvl - 1. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1598 |
inside := nil |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1599 |
] |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1600 |
] |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1601 |
|
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1602 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1603 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1604 |
5 factorial. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1605 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1606 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1607 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1608 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1609 |
5 factorialR. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1610 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1611 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1612 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1613 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1614 |
#(6 1 9 66 2 17) copy sort. |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1615 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1616 |
" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1617 |
|
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1618 |
"Created: / 15-03-2013 / 11:04:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1619 |
! |
d6be49d743b4
Added CompiledCode>>setTracelog to trace method's execution using system logger.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3125
diff
changeset
|
1620 |
|
88 | 1621 |
untraceMethod:aMethod |
1622 |
"remove tracing of aMethod" |
|
1623 |
||
1624 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1625 |
trace facilities ..." |
|
1626 |
||
1627 |
^ self unwrapMethod:aMethod |
|
11 | 1628 |
! ! |
1629 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1630 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1631 |
|
88 | 1632 |
unwrapAllMethods |
1633 |
"just in case you dont know what methods have break/trace-points |
|
1634 |
on them; this removes them all" |
|
1635 |
||
2396 | 1636 |
WrappedMethod allInstancesDo:[:aWrapperMethod | |
1637 |
aWrapperMethod unregister. |
|
1638 |
self unwrapMethod:aWrapperMethod. |
|
88 | 1639 |
] |
1145 | 1640 |
|
1641 |
" |
|
1642 |
MessageTracer unwrapAllMethods |
|
1643 |
" |
|
2396 | 1644 |
|
1645 |
"Modified: / 01-07-2011 / 10:02:47 / cg" |
|
11 | 1646 |
! |
1647 |
||
88 | 1648 |
unwrapMethod:aMethod |
1649 |
"remove any wrapper on aMethod" |
|
1650 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1651 |
|selector class originalMethod dict mthd| |
88 | 1652 |
|
1970 | 1653 |
aMethod isWrapped ifTrue:[ |
1654 |
originalMethod := aMethod originalMethod. |
|
1655 |
]. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1656 |
|
155 | 1657 |
MethodCounts notNil ifTrue:[ |
265 | 1658 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1659 |
MethodCounts removeKey:originalMethod ifAbsent:nil. |
265 | 1660 |
]. |
1661 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
3347 | 1662 |
MethodCounts := MethodCounts asNilIfEmpty. |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1663 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1664 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1665 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1666 |
MethodMemoryUsage removeKey:originalMethod ifAbsent:nil. |
265 | 1667 |
]. |
1668 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
3347 | 1669 |
MethodMemoryUsage := MethodMemoryUsage asNilIfEmpty. |
155 | 1670 |
]. |
327 | 1671 |
MethodTiming notNil ifTrue:[ |
1672 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1673 |
MethodTiming removeKey:originalMethod ifAbsent:nil. |
327 | 1674 |
]. |
1675 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
3347 | 1676 |
MethodTiming := MethodTiming asNilIfEmpty. |
327 | 1677 |
]. |
155 | 1678 |
|
88 | 1679 |
CallingLevel := 0. |
1680 |
||
1681 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1682 |
^ aMethod |
88 | 1683 |
]. |
1684 |
||
1685 |
" |
|
1686 |
get class/selector |
|
1687 |
" |
|
1688 |
class := aMethod containingClass. |
|
1689 |
class isNil ifTrue:[ |
|
536 | 1690 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
265 | 1691 |
^ aMethod |
88 | 1692 |
]. |
1693 |
selector := class selectorAtMethod:aMethod. |
|
1694 |
||
1695 |
originalMethod isNil ifTrue:[ |
|
808 | 1696 |
self error:'oops, could not find original method' mayProceed:true. |
265 | 1697 |
^ aMethod |
88 | 1698 |
]. |
1699 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1700 |
dict := class methodDictionary. |
506 | 1701 |
mthd := dict at:selector ifAbsent:nil. |
1702 |
mthd notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1703 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1704 |
class methodDictionary:dict. |
88 | 1705 |
] ifFalse:[ |
667 | 1706 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
1707 |
"/ self halt:'oops, unexpected error - cannot remove wrap'. |
|
1708 |
aMethod becomeSameAs:originalMethod. |
|
265 | 1709 |
^ aMethod |
88 | 1710 |
]. |
1711 |
||
1712 |
ObjectMemory flushCaches. |
|
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1713 |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1714 |
class changed:#methodTrap with:selector. "/ tell browsers |
2278 | 1715 |
MethodTrapChangeNotificationParameter notNil ifTrue:[ |
1716 |
Smalltalk changed:#methodTrap with:(MethodTrapChangeNotificationParameter changeClass:class changeSelector:selector). |
|
1717 |
]. |
|
88 | 1718 |
^ originalMethod |
265 | 1719 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1720 |
"Modified: / 05-06-1996 / 14:08:08 / stefan" |
1970 | 1721 |
"Modified: / 04-10-2007 / 16:41:01 / cg" |
13 | 1722 |
! |
1723 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1724 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1725 |
^ self wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:nil |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1726 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1727 |
"Modified: 18.12.1995 / 15:58:12 / stefan" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1728 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1729 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1730 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1731 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1732 |
aMethod is evaluated. |
|
1733 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1734 |
ExitBlock will be called, when the method is left, and gets the context and |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1735 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1736 |
UnwindBlock will be called when the contxt of aMethod is unwound. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1737 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
572 | 1738 |
because allocating the unwindBlock uses memory and some users want to count allocated memory. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1739 |
" |
88 | 1740 |
|
1452 | 1741 |
|selector class trapMethod s spec src dict sel saveUS xselector| |
88 | 1742 |
|
1743 |
CallingLevel := 0. |
|
1744 |
||
1745 |
" |
|
1746 |
create a new method, which calls the original one, |
|
1747 |
but only if not already being trapped. |
|
1748 |
" |
|
1749 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1750 |
^ aMethod |
88 | 1751 |
]. |
1752 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1753 |
aMethod makeRealMethod |
88 | 1754 |
]. |
1755 |
||
1756 |
" |
|
1757 |
get class/selector |
|
1758 |
" |
|
1759 |
class := aMethod containingClass. |
|
1760 |
class isNil ifTrue:[ |
|
808 | 1761 |
self error:'cannot place trap (no containing class found)' mayProceed:true. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1762 |
^ aMethod |
88 | 1763 |
]. |
1764 |
selector := class selectorAtMethod:aMethod. |
|
1765 |
||
1766 |
WrappedMethod autoload. "/ for small systems |
|
1767 |
||
1768 |
" |
|
1769 |
get a new method-spec |
|
1770 |
" |
|
730 | 1771 |
xselector := '_x'. |
729 | 1772 |
aMethod numArgs timesRepeat:[ |
1773 |
xselector := xselector , '_:' |
|
1774 |
]. |
|
1775 |
spec := Parser methodSpecificationForSelector:xselector. |
|
88 | 1776 |
|
1777 |
" |
|
1778 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1779 |
" |
|
1780 |
s := WriteStream on:String new. |
|
1781 |
s nextPutAll:spec. |
|
3286 | 1782 |
s nextPutAll:' <context: #return>'. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1783 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1784 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1785 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1786 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1787 |
]. |
88 | 1788 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1789 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1790 |
]. |
1791 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1792 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1793 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1794 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1795 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1796 |
nextPutAll: ' sender:nil. '. |
1797 |
||
1798 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1799 |
s nextPutAll:'#exitBlock yourself value:context value:retVal.'. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1800 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1801 |
unwindBlock notNil ifTrue:[ |
2825
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1802 |
s nextPutAll:'] ifCurtailed:#unwindBlock yourself.'. |
88 | 1803 |
]. |
1804 |
s nextPutAll:'^ retVal'; cr. |
|
1805 |
||
1806 |
src := s contents. |
|
1452 | 1807 |
saveUS := Compiler allowUnderscoreInIdentifier. |
1808 |
ParserFlags |
|
1809 |
withSTCCompilation:#never |
|
1810 |
do:[ |
|
1811 |
[ |
|
1812 |
Compiler allowUnderscoreInIdentifier:true. |
|
1813 |
Class withoutUpdatingChangesDo:[ |
|
3286 | 1814 |
trapMethod := Compiler |
1815 |
compile:src |
|
1816 |
forClass:UndefinedObject |
|
1452 | 1817 |
inCategory:aMethod category |
3286 | 1818 |
notifying:nil |
1819 |
install:false |
|
1452 | 1820 |
skipIfSame:false |
3286 | 1821 |
silent:false. "/ true. |
1452 | 1822 |
] |
1823 |
] ensure:[ |
|
1824 |
Compiler allowUnderscoreInIdentifier:saveUS. |
|
1825 |
]. |
|
1826 |
]. |
|
88 | 1827 |
|
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1828 |
trapMethod setPackage:aMethod package. |
88 | 1829 |
trapMethod changeClassTo:WrappedMethod. |
2396 | 1830 |
trapMethod register. |
1831 |
||
88 | 1832 |
" |
1833 |
raising our eyebrows here ... |
|
1834 |
" |
|
1835 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1836 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1837 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1838 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1839 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1840 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1841 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1842 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1843 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1844 |
]. |
88 | 1845 |
" |
1846 |
change the source of this new method |
|
1847 |
(to avoid confusion in the debugger ...) |
|
1848 |
" |
|
840
5ec82d6c2e55
care for the wrappers source info (to allow source access in browser)
Claus Gittinger <cg@exept.de>
parents:
825
diff
changeset
|
1849 |
"/ trapMethod source:'this is a wrapper method - not the real one'. |
5ec82d6c2e55
care for the wrappers source info (to allow source access in browser)
Claus Gittinger <cg@exept.de>
parents:
825
diff
changeset
|
1850 |
trapMethod sourceFilename:(aMethod getSource) position:(aMethod getSourcePosition). |
88 | 1851 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1852 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1853 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1854 |
sel == 0 ifTrue:[ |
808 | 1855 |
self error:'oops, unexpected error' mayProceed:true. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1856 |
^ aMethod |
88 | 1857 |
]. |
1858 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1859 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1860 |
class methodDictionary:dict. |
88 | 1861 |
ObjectMemory flushCaches. |
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1862 |
|
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1863 |
class changed:#methodTrap with:selector. "/ tell browsers |
2278 | 1864 |
MethodTrapChangeNotificationParameter notNil ifTrue:[ |
1865 |
Smalltalk changed:#methodTrap with:(MethodTrapChangeNotificationParameter changeClass:class changeSelector:selector). |
|
1866 |
]. |
|
88 | 1867 |
^ trapMethod |
1868 |
||
1869 |
" |
|
1870 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1871 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1872 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1873 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1874 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1875 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1876 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1877 |
]. |
88 | 1878 |
(1@2) scaleBy:5. |
1879 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1880 |
(1@2) scaleBy:5. |
|
1881 |
" |
|
1882 |
" |
|
1883 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1884 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1885 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1886 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1887 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1888 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1889 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1890 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1891 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1892 |
]. |
258 | 1893 |
Transcript showCR:'5 factorial traced'. |
88 | 1894 |
5 factorial. |
1895 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1896 |
Transcript showCR:'5 factorial normal'. |
88 | 1897 |
5 factorial. |
1898 |
" |
|
1899 |
" |
|
1900 |
|lvl| |
|
1901 |
||
1902 |
lvl := 0. |
|
1903 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1904 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1905 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1906 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1907 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1908 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1909 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1910 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1911 |
Transcript show:('leave ' , con receiver printString , '>>factorial; returning:'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1912 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1913 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1914 |
]. |
258 | 1915 |
Transcript showCR:'5 factorial traced'. |
88 | 1916 |
5 factorial. |
1917 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1918 |
Transcript showCR:'5 factorial normal'. |
88 | 1919 |
5 factorial. |
1920 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1921 |
|
2396 | 1922 |
"Modified: / 25-06-1996 / 22:04:51 / stefan" |
1923 |
"Modified: / 01-07-2011 / 10:01:48 / cg" |
|
88 | 1924 |
! ! |
1925 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1926 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1927 |
|
525 | 1928 |
objectHasWraps:anObject |
1929 |
"return true, if anObject has any wraps" |
|
1930 |
||
1931 |
^ anObject class category == #'* trapping *' |
|
1932 |
! |
|
1933 |
||
1934 |
realClassOf:anObject |
|
1935 |
"return anObjects real class" |
|
1936 |
||
1937 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1938 |
^ anObject class |
|
1939 |
]. |
|
1940 |
^ anObject class superclass |
|
1941 |
! |
|
1942 |
||
88 | 1943 |
trap:anObject selector:aSelector |
1944 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1945 |
sent to anObject. Use untrap to remove this trap. |
|
1946 |
The current implementation does not allow integers or nil to be trapped." |
|
1947 |
||
1948 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1949 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1950 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1951 |
onExit:LeaveBreakBlock. |
88 | 1952 |
|
1953 |
" |
|
1954 |
|p| |
|
1955 |
||
1956 |
p := Point new. |
|
1957 |
MessageTracer trap:p selector:#x:. |
|
1958 |
p x:5 |
|
1959 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1960 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1961 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1962 |
! |
1963 |
||
88 | 1964 |
trap:anObject selectors:aCollection |
1965 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1966 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1967 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1968 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1969 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1970 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1971 |
! |
1972 |
||
1973 |
trapAll:anObject |
|
1974 |
"trap on all messages which are understood by anObject" |
|
1975 |
||
1976 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1977 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1978 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1979 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1980 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1981 |
! |
1982 |
||
1983 |
trapAll:anObject from:aClass |
|
1984 |
"trap on all messages defined in aClass sent to anObject" |
|
1985 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1986 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1987 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1988 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1989 |
! |
1990 |
||
1991 |
untrap:anObject |
|
1992 |
"remove any traps on anObject" |
|
1993 |
||
1994 |
"this is done by just patching the objects class back to the original" |
|
1995 |
||
1996 |
|orgClass| |
|
1997 |
||
1998 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1999 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2000 |
^ self |
88 | 2001 |
]. |
2002 |
||
660 | 2003 |
anObject changeClassTo:orgClass superclass. |
662 | 2004 |
ObjectCopyHolders notNil ifTrue:[ |
2005 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
2006 |
]. |
|
88 | 2007 |
|
2008 |
" |
|
2009 |
|p| |
|
2010 |
||
2011 |
p := Point new copy. |
|
2012 |
MessageTracer trace:p selector:#x:. |
|
2013 |
MessageTracer trace:p selector:#y:. |
|
2014 |
p y:1. |
|
2015 |
p x:2. |
|
2016 |
MessageTracer untrap:p |
|
2017 |
p y:2. |
|
2018 |
p x:1. |
|
2019 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2020 |
|
660 | 2021 |
"Modified: / 21.4.1998 / 15:43:33 / cg" |
13 | 2022 |
! |
2023 |
||
88 | 2024 |
untrap:anObject selector:aSelector |
2025 |
"remove trap on aSelector from anObject" |
|
2026 |
||
501 | 2027 |
|orgClass dict| |
88 | 2028 |
|
2029 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2030 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 2031 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2032 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2033 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 2034 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2035 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2036 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2037 |
anObject changeClassTo:orgClass superclass. |
662 | 2038 |
ObjectCopyHolders notNil ifTrue:[ |
2039 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
2040 |
]. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2041 |
^ self |
88 | 2042 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2043 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2044 |
orgClass methodDictionary:dict. |
88 | 2045 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
2046 |
||
2047 |
" |
|
2048 |
|p| |
|
2049 |
||
2050 |
p := Point new copy. |
|
2051 |
MessageTracer trace:p selector:#x:. |
|
2052 |
MessageTracer trace:p selector:#y:. |
|
2053 |
'trace both ...' errorPrintNL. |
|
2054 |
p x:2. |
|
2055 |
p y:1. |
|
2056 |
'trace only y ...' errorPrintNL. |
|
2057 |
MessageTracer untrap:p selector:#x:. |
|
2058 |
p x:2. |
|
2059 |
p y:1. |
|
2060 |
'trace none ...' errorPrintNL. |
|
2061 |
MessageTracer untrap:p selector:#y:. |
|
2062 |
p x:2. |
|
2063 |
p y:1. |
|
2064 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2065 |
|
660 | 2066 |
"Modified: / 5.6.1996 / 13:56:08 / stefan" |
2067 |
"Modified: / 21.4.1998 / 15:43:55 / cg" |
|
525 | 2068 |
! |
2069 |
||
2070 |
wrappedSelectorsOf:anObject |
|
2071 |
"return the set of wrapped selectors (if any)" |
|
2072 |
||
2073 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
2074 |
^ #() |
|
2075 |
]. |
|
2076 |
^ anObject class selectors |
|
11 | 2077 |
! ! |
2078 |
||
660 | 2079 |
!MessageTracer class methodsFor:'object modification traps'! |
2080 |
||
2081 |
trapModificationsIn:anObject |
|
2082 |
"trap modifications in anObject" |
|
2083 |
||
2084 |
self |
|
663 | 2085 |
trapModificationsIn:anObject filter:[:old :new | true] |
660 | 2086 |
|
2087 |
" |
|
2088 |
|a| |
|
2089 |
||
2090 |
a := Array new:10. |
|
2091 |
MessageTracer trapModificationsIn:a. |
|
2092 |
||
2093 |
a size. |
|
2094 |
a at:1. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2095 |
a at:2 put:nil. ' no trap here (nil already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2096 |
a at:2 put:2. ' expect trap here (changing nil to 2) '. |
660 | 2097 |
a at:2. |
2098 |
a at:3. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2099 |
a at:2 put:2. ' no trap here (2 already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2100 |
a at:2 put:3. ' expect trap here (changing 2 to 3) '. |
660 | 2101 |
MessageTracer untrace:a. |
2102 |
a at:3 put:5. |
|
2103 |
" |
|
2104 |
||
2105 |
"Created: / 21.4.1998 / 14:32:34 / cg" |
|
2106 |
"Modified: / 21.4.1998 / 14:58:24 / cg" |
|
2107 |
! |
|
2108 |
||
2109 |
trapModificationsIn:anObject filter:aFilterBlock |
|
2110 |
"trap modifications in anObject" |
|
2111 |
||
2112 |
|allSelectors| |
|
2113 |
||
2114 |
allSelectors := IdentitySet new. |
|
972 | 2115 |
anObject class withAllSuperclassesDo:[:aClass | |
660 | 2116 |
aClass methodDictionary keys addAllTo:allSelectors |
2117 |
]. |
|
2118 |
||
2119 |
self trapModificationsIn:anObject selectors:allSelectors filter:aFilterBlock |
|
2120 |
||
2121 |
"trap if arrays 5th slot is modified: |
|
2122 |
||
2123 |
|a| |
|
2124 |
||
2125 |
a := Array new:10. |
|
2126 |
MessageTracer trapModificationsIn:a filter:[:old :new | (old at:5) ~~ (new at:5)]. |
|
2127 |
||
2128 |
a size. |
|
2129 |
a at:1. |
|
2130 |
a at:2 put:nil. |
|
2131 |
a at:2 put:2. |
|
2132 |
a at:2. |
|
2133 |
a at:3. |
|
2134 |
a at:2 put:2. |
|
2135 |
a at:2 put:3. |
|
2136 |
a at:5 put:3. |
|
2137 |
a at:5 put:3. |
|
2138 |
MessageTracer untrace:a. |
|
2139 |
a at:3 put:5. |
|
2140 |
" |
|
2141 |
||
2142 |
"Modified: / 21.4.1998 / 15:53:38 / cg" |
|
2143 |
! |
|
2144 |
||
2145 |
trapModificationsIn:anObject selector:aSelector filter:aFilterBlock |
|
2146 |
"install a trap for modifications in anObject by aSelector-messages. |
|
2147 |
the filterBlock will be invoked (after a modification) with the old and |
|
2148 |
new values as arguments and should return true, |
|
2149 |
if the debugger is really wanted." |
|
2150 |
||
2151 |
self |
|
2152 |
trapModificationsIn:anObject |
|
2153 |
selectors:(Array with:aSelector) |
|
2154 |
filter:aFilterBlock |
|
2155 |
||
2156 |
"Modified: / 21.4.1998 / 15:34:44 / cg" |
|
2157 |
! |
|
2158 |
||
2159 |
trapModificationsIn:anObject selectors:aCollectionOfSelectors filter:aFilterBlock |
|
2160 |
"install a trap for modifications in anObject by aSelector-messages. |
|
2161 |
the filterBlock will be invoked (after a modification) with the old and |
|
2162 |
new values as arguments and should return true, |
|
2163 |
if the debugger is really wanted." |
|
2164 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2165 |
|copyHolder sels checkBlock| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2166 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2167 |
(anObject isNil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2168 |
or:[anObject isSymbol |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2169 |
or:[anObject class == SmallInteger |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2170 |
or:[anObject == true |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2171 |
or:[anObject == false]]]]) |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2172 |
ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2173 |
self error:'cannot place trap on this object' mayProceed:true. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2174 |
^ self. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2175 |
]. |
660 | 2176 |
|
2177 |
ObjectCopyHolders isNil ifTrue:[ |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2178 |
ObjectCopyHolders := WeakIdentityDictionary new. |
660 | 2179 |
]. |
2180 |
copyHolder := ObjectCopyHolders at:anObject ifAbsent:nil. |
|
2181 |
copyHolder isNil ifTrue:[ |
|
2182 |
ObjectCopyHolders at:anObject put:(copyHolder := ValueHolder new). |
|
2183 |
]. |
|
2184 |
||
2185 |
copyHolder value:(anObject shallowCopy). |
|
2186 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2187 |
"/ some required ones, which are used in the wrapped code and are known to |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2188 |
"/ do no harm to the object ... consider this a kludge |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2189 |
sels := aCollectionOfSelectors copy. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2190 |
sels removeAll:#(#class #species #yourself #'sameContentsAs:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2191 |
#'instVarAt:' #'at:' #'basicAt:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2192 |
#'shallowCopy' #'copy' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2193 |
#'=' #'==' #'~=' #'~~' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2194 |
#'size' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2195 |
). |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2196 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2197 |
checkBlock := |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2198 |
[:con :retVal | |
660 | 2199 |
|oldValue| |
2200 |
||
2201 |
oldValue := copyHolder value. |
|
2202 |
||
2203 |
"/ compare with copy ... |
|
2204 |
(anObject sameContentsAs:oldValue) ifFalse:[ |
|
2205 |
"/ see oldValue vs. anObject |
|
2206 |
(aFilterBlock value:oldValue value:anObject) ifTrue:[ |
|
2207 |
copyHolder value:(anObject shallowCopy). |
|
2208 |
ObjectWrittenBreakpointSignal |
|
2209 |
raiseRequestWith:(oldValue -> anObject) |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2210 |
errorString:('object was modififed in: ' , con sender selector) |
660 | 2211 |
in:con sender |
2212 |
] |
|
2213 |
] |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2214 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2215 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2216 |
sels do:[:aSelector | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2217 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2218 |
wrap:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2219 |
selector:aSelector |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2220 |
onEntry:[:con | ] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2221 |
onExit:checkBlock |
660 | 2222 |
withOriginalClass:true |
2223 |
flushCaches:false. |
|
2224 |
]. |
|
2225 |
ObjectMemory flushCaches |
|
2226 |
||
2227 |
"Created: / 21.4.1998 / 15:34:05 / cg" |
|
2228 |
"Modified: / 21.4.1998 / 16:00:39 / cg" |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2229 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2230 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2231 |
trapModificationsOf:anInstVarOrOffset in:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2232 |
"trap modifications in anObject" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2233 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2234 |
|idx selectors definingClass| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2235 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2236 |
anInstVarOrOffset isInteger ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2237 |
"/ indexed slot |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2238 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2239 |
trapModificationsIn:anObject filter:[:old :new | (old at:anInstVarOrOffset) ~~ (new at:anInstVarOrOffset)] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2240 |
] ifFalse:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2241 |
"/ instVar by name |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2242 |
selectors := IdentitySet new. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2243 |
definingClass := anObject class whichClassDefinesInstVar:anInstVarOrOffset. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2244 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2245 |
definingClass withAllSuperclassesDo:[:aClass | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2246 |
aClass methodDictionary keys addAllTo:selectors |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2247 |
]. |
3326 | 2248 |
idx := anObject class instVarIndexFor:anInstVarOrOffset. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2249 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2250 |
trapModificationsIn:anObject selectors:selectors filter:[:old :new | (old instVarAt:idx) ~~ (new instVarAt:idx)] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2251 |
] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2252 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2253 |
" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2254 |
|a| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2255 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2256 |
a := Array new:10. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2257 |
MessageTracer trapModificationsOf:2 in:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2258 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2259 |
a size. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2260 |
a at:1. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2261 |
a at:2 put:nil. ' no trap here (nil already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2262 |
a at:2 put:2. ' expect trap here (changing nil to 2) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2263 |
a at:2. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2264 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2265 |
a at:2 put:2. ' no trap here (2 already there) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2266 |
a at:2 put:3. ' expect trap here (changing nil to 2) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2267 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2268 |
a at:3 put:3. ' no trap here (index is different) '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2269 |
MessageTracer untrace:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2270 |
a at:3 put:5. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2271 |
" |
660 | 2272 |
! ! |
2273 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2274 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 2275 |
|
2276 |
trace:anObject selector:aSelector |
|
2277 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2278 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2279 |
Use untrap to remove this trace. |
|
2280 |
The current implementation does not allow integers or nil to be traced." |
|
2281 |
||
664 | 2282 |
self trace:anObject selector:aSelector on:Stderr |
88 | 2283 |
|
2284 |
" |
|
2285 |
|p| |
|
8 | 2286 |
|
88 | 2287 |
p := Point new. |
2288 |
MessageTracer trace:p selector:#x:. |
|
2289 |
p x:5. |
|
2290 |
p y:1. |
|
2291 |
p x:10. |
|
2292 |
MessageTracer untrap:p. |
|
2293 |
p x:7 |
|
2294 |
" |
|
2295 |
" |
|
2296 |
|a| |
|
2297 |
||
2298 |
a := #(6 1 9 66 2 17) copy. |
|
2299 |
MessageTracer trace:a selector:#at:put:. |
|
2300 |
MessageTracer trace:a selector:#at:. |
|
2301 |
a sort. |
|
2302 |
" |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2303 |
|
660 | 2304 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
88 | 2305 |
! |
2306 |
||
664 | 2307 |
trace:anObject selector:aSelector on:aStream |
2308 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2309 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2310 |
Use untrap to remove this trace. |
|
2311 |
The current implementation does not allow integers or nil to be traced." |
|
2312 |
||
2313 |
self |
|
2314 |
trace:anObject |
|
2315 |
selectors:(Array with:aSelector) |
|
2316 |
on:aStream |
|
2317 |
||
2318 |
" |
|
2319 |
|p| |
|
2320 |
||
2321 |
p := Point new. |
|
2322 |
MessageTracer trace:p selector:#x: on:Stderr. |
|
2323 |
p x:5. |
|
2324 |
p y:1. |
|
2325 |
p x:10. |
|
2326 |
MessageTracer untrap:p. |
|
2327 |
p x:7 |
|
2328 |
" |
|
2329 |
" |
|
2330 |
|a| |
|
2331 |
||
2332 |
a := #(6 1 9 66 2 17) copy. |
|
2333 |
MessageTracer trace:a selector:#at:put: on:Stderr. |
|
2334 |
MessageTracer trace:a selector:#at:. on:Stderr |
|
2335 |
a sort. |
|
2336 |
" |
|
2337 |
||
2338 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
|
2339 |
! |
|
2340 |
||
660 | 2341 |
trace:anObject selectors:aCollectionOfSelectors |
2342 |
"arrange for a trace message to be output on Stderr, when any message |
|
2343 |
from aCollectionOfSelectors is sent to anObject. |
|
2344 |
Both entry and exit are traced. |
|
2345 |
Use untrap:/untrace: to remove this trace. |
|
2346 |
The current implementation does not allow integers or nil to be traced." |
|
2347 |
||
664 | 2348 |
self trace:anObject selectors:aCollectionOfSelectors on:Stderr |
88 | 2349 |
|
2350 |
" |
|
660 | 2351 |
|p| |
2352 |
||
2353 |
p := Point new. |
|
2354 |
MessageTracer trace:p selector:#x:. |
|
2355 |
p x:5. |
|
2356 |
p y:1. |
|
2357 |
p x:10. |
|
2358 |
MessageTracer untrap:p. |
|
2359 |
p x:7 |
|
2360 |
" |
|
2361 |
" |
|
2362 |
|a| |
|
2363 |
||
2364 |
a := #(6 1 9 66 2 17) copy. |
|
2365 |
MessageTracer trace:a selector:#at:put:. |
|
2366 |
MessageTracer trace:a selector:#at:. |
|
2367 |
a sort. |
|
88 | 2368 |
" |
2369 |
||
660 | 2370 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
88 | 2371 |
! |
2372 |
||
664 | 2373 |
trace:anObject selectors:aCollectionOfSelectors on:aStream |
2374 |
"arrange for a trace message to be output on Stderr, when any message |
|
2375 |
from aCollectionOfSelectors is sent to anObject. |
|
2376 |
Both entry and exit are traced. |
|
2377 |
Use untrap:/untrace: to remove this trace. |
|
2378 |
The current implementation does not allow integers or nil to be traced." |
|
2379 |
||
2380 |
aCollectionOfSelectors do:[:aSelector | |
|
3290 | 2381 |
|methodName| |
2382 |
||
664 | 2383 |
methodName := anObject class name , '>>' , aSelector. |
2384 |
self |
|
2385 |
wrap:anObject |
|
2386 |
selector:aSelector |
|
2387 |
onEntry:[:con | |
|
2388 |
aStream nextPutAll:'enter '; nextPutAll:methodName. |
|
2389 |
aStream nextPutAll:' receiver='. |
|
2390 |
con receiver printOn:aStream. |
|
2391 |
aStream nextPutAll:' args='. (con args) printOn:aStream. |
|
2392 |
aStream nextPutAll:' from:'. con sender printOn:aStream. |
|
2393 |
aStream cr; flush |
|
2394 |
] |
|
2395 |
onExit:[:con :retVal | |
|
2396 |
aStream nextPutAll:'leave '; nextPutAll:methodName. |
|
2397 |
aStream nextPutAll:' receiver='. con receiver printOn:aStream. |
|
2398 |
aStream nextPutAll:' returning:'. retVal printOn:aStream. |
|
2399 |
aStream cr; flush |
|
2400 |
] |
|
2401 |
withOriginalClass:true |
|
2402 |
flushCaches:false |
|
2403 |
]. |
|
2404 |
ObjectMemory flushCaches |
|
2405 |
||
2406 |
" |
|
2407 |
|p| |
|
2408 |
||
2409 |
p := Point new. |
|
2410 |
MessageTracer trace:p selectors:#(x:) on:Transcript. |
|
2411 |
p x:5. |
|
2412 |
p y:1. |
|
2413 |
p x:10. |
|
2414 |
MessageTracer untrap:p. |
|
2415 |
p x:7 |
|
2416 |
" |
|
2417 |
" |
|
2418 |
|a| |
|
2419 |
||
2420 |
a := #(6 1 9 66 2 17) copy. |
|
2421 |
MessageTracer trace:a selectors:#( at:put: at:) on:Transcript. |
|
2422 |
a sort. |
|
2423 |
" |
|
2424 |
||
2425 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2426 |
! |
|
2427 |
||
88 | 2428 |
traceAll:anObject |
2429 |
"trace all messages which are understood by anObject" |
|
27 | 2430 |
|
664 | 2431 |
self traceAll:anObject on:Stderr |
88 | 2432 |
|
2433 |
" |
|
2434 |
trace all (implemented) messages sent to Display |
|
2435 |
(other messages lead to an error, anyway) |
|
2436 |
" |
|
2437 |
||
2438 |
" |
|
2439 |
MessageTracer traceAll:Display |
|
2440 |
MessageTracer untrace:Display |
|
2441 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2442 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2443 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 2444 |
! |
2445 |
||
2446 |
traceAll:anObject from:aClass |
|
2447 |
"trace all messages defined in aClass sent to anObject" |
|
2448 |
||
664 | 2449 |
self traceAll:anObject from:aClass on:Stderr |
88 | 2450 |
|
2451 |
" |
|
2452 |
trace all methods in Display, which are implemented |
|
2453 |
in the DisplayWorkstation class. |
|
2454 |
" |
|
2455 |
||
2456 |
" |
|
2457 |
MessageTracer traceAll:Display from:XWorkstation |
|
2458 |
MessageTracer untrace:Display |
|
2459 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2460 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2461 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 2462 |
! |
2463 |
||
664 | 2464 |
traceAll:anObject from:aClass on:aStream |
2465 |
"trace all messages defined in aClass sent to anObject" |
|
2466 |
||
2467 |
self trace:anObject selectors:aClass selectors on:aStream |
|
2468 |
||
2469 |
" |
|
2470 |
trace all methods in Display, which are implemented |
|
2471 |
in the DisplayWorkstation class. |
|
2472 |
" |
|
2473 |
||
2474 |
" |
|
2475 |
MessageTracer traceAll:Display from:XWorkstation on:Transcript |
|
2476 |
MessageTracer untrace:Display |
|
2477 |
" |
|
2478 |
||
2479 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
|
2480 |
! |
|
2481 |
||
2482 |
traceAll:anObject on:aStream |
|
2483 |
"trace all messages which are understood by anObject" |
|
2484 |
||
2485 |
|allSelectors| |
|
2486 |
||
2487 |
allSelectors := IdentitySet new. |
|
972 | 2488 |
anObject class withAllSuperclassesDo:[:aClass | |
664 | 2489 |
aClass methodDictionary keys addAllTo:allSelectors |
2490 |
]. |
|
2491 |
self trace:anObject selectors:allSelectors on:aStream |
|
2492 |
||
2493 |
" |
|
2494 |
trace all (implemented) messages sent to Display |
|
2495 |
(other messages lead to an error, anyway) |
|
2496 |
" |
|
2497 |
||
2498 |
" |
|
2499 |
MessageTracer traceAll:Display on:Transcript |
|
2500 |
MessageTracer untrace:Display |
|
2501 |
" |
|
2502 |
||
2503 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
|
2504 |
! |
|
2505 |
||
2506 |
traceEntry:anObject selectors:aCollectionOfSelectors on:aStream |
|
2507 |
"arrange for a trace message to be output on Stderr, when any message |
|
2508 |
from aCollectionOfSelectors is sent to anObject. |
|
2509 |
Only entry is traced. |
|
2510 |
Use untrap:/untrace: to remove this trace. |
|
2511 |
The current implementation does not allow integers or nil to be traced." |
|
2512 |
||
2513 |
self |
|
2514 |
traceEntry:anObject selectors:aCollectionOfSelectors on:Stderr |
|
2515 |
||
2516 |
" |
|
2517 |
|p| |
|
2518 |
||
2519 |
p := Point new. |
|
2520 |
MessageTracer traceEntry:p selectors:#(x:). |
|
2521 |
p x:5. |
|
2522 |
p y:1. |
|
2523 |
p x:10. |
|
2524 |
MessageTracer untrap:p. |
|
2525 |
p x:7 |
|
2526 |
" |
|
2527 |
" |
|
2528 |
|a| |
|
2529 |
||
2530 |
a := #(6 1 9 66 2 17) copy. |
|
2531 |
MessageTracer traceEntry:a selectors:#( at:put: at:). |
|
2532 |
a sort. |
|
2533 |
" |
|
2534 |
||
2535 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2536 |
! |
|
2537 |
||
88 | 2538 |
traceSender:anObject selector:aSelector |
2539 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2540 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2541 |
Use untrap to remove this trace. |
|
2542 |
The current implementation does not allow integers or nil to be traced." |
|
2543 |
||
664 | 2544 |
^ self traceSender:anObject selector:aSelector on:Stderr |
88 | 2545 |
|
2546 |
" |
|
2547 |
|p| |
|
27 | 2548 |
|
88 | 2549 |
p := Point new. |
2550 |
MessageTracer traceSender:p selector:#x:. |
|
2551 |
p x:5. |
|
2552 |
p y:1. |
|
2553 |
p x:10. |
|
2554 |
MessageTracer untrap:p. |
|
2555 |
p x:7 |
|
2556 |
" |
|
2557 |
" |
|
2558 |
|a| |
|
2559 |
||
2560 |
a := #(6 1 9 66 2 17) copy. |
|
2561 |
MessageTracer traceSender:a selector:#at:put:. |
|
2562 |
MessageTracer traceSender:a selector:#at:. |
|
2563 |
a sort. |
|
2564 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2565 |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2566 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
11 | 2567 |
! |
2568 |
||
664 | 2569 |
traceSender:anObject selector:aSelector on:aStream |
2570 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2571 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2572 |
Use untrap to remove this trace. |
|
2573 |
The current implementation does not allow integers or nil to be traced." |
|
2574 |
||
2575 |
|methodName| |
|
2576 |
||
2577 |
methodName := anObject class name , '>>' , aSelector. |
|
2578 |
self wrap:anObject |
|
2579 |
selector:aSelector |
|
2580 |
onEntry:[:con | |
|
2581 |
aStream nextPutAll:methodName. |
|
2582 |
aStream nextPutAll:' from '. |
|
2583 |
con sender printOn:aStream. |
|
2584 |
aStream cr; flush. |
|
2585 |
] |
|
2586 |
onExit:LeaveTraceBlock. |
|
2587 |
||
2588 |
" |
|
2589 |
|p| |
|
2590 |
||
2591 |
p := Point new. |
|
2592 |
MessageTracer traceSender:p selector:#x: on:Transcript. |
|
2593 |
p x:5. |
|
2594 |
p y:1. |
|
2595 |
p x:10. |
|
2596 |
MessageTracer untrap:p. |
|
2597 |
p x:7 |
|
2598 |
" |
|
2599 |
" |
|
2600 |
|a| |
|
2601 |
||
2602 |
a := #(6 1 9 66 2 17) copy. |
|
2603 |
MessageTracer traceSender:a selector:#at:put: on:Transcript. |
|
2604 |
MessageTracer traceSender:a selector:#at:. on:Transcript |
|
2605 |
a sort. |
|
2606 |
" |
|
2607 |
||
2608 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
|
2609 |
! |
|
2610 |
||
88 | 2611 |
untrace:anObject |
2612 |
"remove any traces on anObject" |
|
2613 |
||
2614 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2615 |
trace facilities ..." |
|
2616 |
||
2617 |
^ self untrap:anObject |
|
2618 |
! |
|
2619 |
||
2620 |
untrace:anObject selector:aSelector |
|
2621 |
"remove traces of aSelector sent to anObject" |
|
2622 |
||
2623 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2624 |
trace facilities ..." |
|
2625 |
||
2626 |
^ self untrap:anObject selector:aSelector |
|
2627 |
! ! |
|
2628 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2629 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 2630 |
|
8 | 2631 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
2632 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
2633 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2634 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
2635 |
when the method is left, and get the context and the methods return value as arguments. |
|
2636 |
The current implementation does not allow integers or nil to be wrapped." |
|
2637 |
||
2638 |
"I have not yet enough experience, if the wrapped original method should |
|
2639 |
run as an instance of the original, or of the catching class; |
|
2640 |
The latter has the advantage of catching recursive and other sends, while |
|
2641 |
it might lead into trouble when the message is sent from a debugger or a long |
|
2642 |
return is done out of the original method ... |
|
2643 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
2644 |
" |
|
660 | 2645 |
^ self |
2646 |
wrap:anObject |
|
2647 |
selector:aSelector |
|
2648 |
onEntry:entryBlock |
|
2649 |
onExit:exitBlock |
|
2650 |
withOriginalClass:true |
|
2651 |
flushCaches:true |
|
2652 |
||
2653 |
"Modified: / 21.4.1998 / 15:29:50 / cg" |
|
8 | 2654 |
! |
2655 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2656 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock additionalEntryCode:additionalEntryCode additionalExitCode:additionalExitCode additionalVariables:additionalVariables withOriginalClass:withOriginalClass flushCaches:flushCaches |
8 | 2657 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
2658 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2659 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2660 |
when the method is left, and get the current context and the methods return value as argument. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2661 |
If withOriginalClass is true, the class of anObject will be set to its original class |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2662 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2663 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 2664 |
|
1452 | 2665 |
|newClass orgClass myMetaclass trapMethod s spec implClass dict |
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2666 |
originalMethod| |
8 | 2667 |
|
2668 |
" |
|
27 | 2669 |
some are not allowed (otherwise we get into trouble ...) |
2670 |
" |
|
660 | 2671 |
(aSelector == #class |
2672 |
or:[aSelector == #changeClassTo:]) ifTrue:[ |
|
256 | 2673 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
2674 |
^ self |
|
27 | 2675 |
]. |
2676 |
||
2677 |
WrappedMethod autoload. "/ just to make sure ... |
|
2678 |
||
2679 |
" |
|
8 | 2680 |
create a new (anonymous) subclass of the receivers class |
2681 |
but only if not already being trapped. |
|
2682 |
" |
|
2683 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2684 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 2685 |
newClass := orgClass |
8 | 2686 |
] ifFalse:[ |
256 | 2687 |
myMetaclass := orgClass class. |
8 | 2688 |
|
256 | 2689 |
newClass := myMetaclass copy new. |
2690 |
newClass setSuperclass:orgClass. |
|
2691 |
newClass instSize:orgClass instSize. |
|
2692 |
newClass flags:orgClass flags. |
|
667 | 2693 |
newClass isMeta ifFalse:[newClass setClassVariableString:'']. |
256 | 2694 |
newClass setInstanceVariableString:''. |
2695 |
newClass setName:orgClass name. |
|
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2696 |
newClass setCategory:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2697 |
newClass methodDictionary:MethodDictionary new. |
8 | 2698 |
]. |
2699 |
||
2700 |
" |
|
2701 |
create a method, executing the trap-blocks and the original method via a super-send |
|
2702 |
" |
|
2703 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
2704 |
s := WriteStream on:String new. |
|
2705 |
s nextPutAll:spec. |
|
3286 | 2706 |
s nextPutAll:' <context: #return>'. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2707 |
s nextPutAll:' |retVal stubClass '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2708 |
additionalVariables notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2709 |
s nextPutAll:additionalVariables. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2710 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2711 |
s nextPutAll:'| '. |
8 | 2712 |
withOriginalClass ifTrue:[ |
256 | 2713 |
s nextPutAll:'stubClass := self class. '. |
2714 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 2715 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2716 |
additionalEntryCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2717 |
s nextPutAll:additionalEntryCode. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2718 |
]. |
8 | 2719 |
entryBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2720 |
s nextPutAll:'#literal1 yourself value:thisContext. '. "/ #literal1 will be replaced by the entryBlock |
8 | 2721 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2722 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 2723 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 2724 |
exitBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2725 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal. '. "/ #literal2 will be replaced by the exitBlock |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2726 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2727 |
additionalExitCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2728 |
s nextPutAll:additionalExitCode. |
8 | 2729 |
]. |
2730 |
withOriginalClass ifTrue:[ |
|
256 | 2731 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 2732 |
]. |
2733 |
s nextPutAll:'^ retVal'; cr. |
|
2734 |
||
1452 | 2735 |
ParserFlags |
2736 |
withSTCCompilation:#never |
|
2737 |
do:[ |
|
2738 |
Class withoutUpdatingChangesDo:[ |
|
3286 | 2739 |
trapMethod := Compiler |
2740 |
compile:s contents |
|
2741 |
forClass:newClass |
|
1452 | 2742 |
inCategory:'breakpointed' |
3286 | 2743 |
notifying:nil |
2744 |
install:false |
|
1452 | 2745 |
skipIfSame:false |
3286 | 2746 |
silent:true. |
1452 | 2747 |
] |
2748 |
]. |
|
8 | 2749 |
|
646 | 2750 |
trapMethod == #Error ifTrue:[ |
2751 |
Transcript showCR:('cannot place trap on method: ' , aSelector). |
|
2752 |
^ self |
|
2753 |
]. |
|
2754 |
||
29 | 2755 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
2756 |
implClass isNil ifTrue:[ |
|
256 | 2757 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 2758 |
] ifFalse:[ |
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2759 |
originalMethod := (implClass compiledMethodAt:aSelector). |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2760 |
originalMethod notNil ifTrue:[ |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2761 |
trapMethod setPackage:originalMethod package. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2762 |
]. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2763 |
|
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2764 |
trapMethod changeLiteral:#originalMethod to:originalMethod. |
29 | 2765 |
]. |
8 | 2766 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2767 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 2768 |
]. |
2769 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2770 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 2771 |
]. |
2772 |
" |
|
2773 |
change the source of this new method |
|
2774 |
(to avoid confusion in the debugger ...) |
|
2775 |
" |
|
2776 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 2777 |
trapMethod changeClassTo:WrappedMethod. |
2396 | 2778 |
trapMethod register. |
8 | 2779 |
|
2780 |
" |
|
2781 |
install this new method |
|
2782 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2783 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2784 |
dict := dict at:aSelector putOrAppend:trapMethod. |
660 | 2785 |
flushCaches ifTrue:[ |
2786 |
newClass methodDictionary:dict. |
|
2787 |
] ifFalse:[ |
|
2788 |
newClass setMethodDictionary:dict. |
|
2789 |
]. |
|
8 | 2790 |
|
2791 |
" |
|
2792 |
and finally, the big trick: |
|
2793 |
" |
|
660 | 2794 |
newClass ~~ orgClass ifTrue:[ |
2795 |
anObject changeClassTo:newClass |
|
2796 |
]. |
|
8 | 2797 |
|
2798 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2799 |
[exBegin] |
8 | 2800 |
|p| |
2801 |
||
2802 |
p := Point new copy. |
|
2803 |
MessageTracer |
|
256 | 2804 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2805 |
selector:#y: |
256 | 2806 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2807 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2808 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 2809 |
Transcript showCR:retVal printString. |
2810 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2811 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2812 |
withOriginalClass:true. |
256 | 2813 |
Transcript showCR:'sending x: ...'. |
8 | 2814 |
p x:1. |
256 | 2815 |
Transcript showCR:'sending y: ...'. |
8 | 2816 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2817 |
MessageTracer untrap:p. |
256 | 2818 |
Transcript showCR:'sending x: ...'. |
8 | 2819 |
p x:2. |
256 | 2820 |
Transcript showCR:'sending y: ...'. |
8 | 2821 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2822 |
[exEnd] |
8 | 2823 |
" |
2824 |
||
2825 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2826 |
[exBegin] |
8 | 2827 |
|p| |
2828 |
||
2829 |
p := Point new copy. |
|
2830 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2831 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2832 |
onEntry:[:context | self halt:'y: you are trapped'] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2833 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2834 |
withOriginalClass:false. |
256 | 2835 |
Transcript showCR:'sending x: ...'. |
8 | 2836 |
p x:1. |
256 | 2837 |
Transcript showCR:'sending y: ...'. |
8 | 2838 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2839 |
MessageTracer untrap:p. |
256 | 2840 |
Transcript showCR:'sending x: ...'. |
8 | 2841 |
p x:2. |
256 | 2842 |
Transcript showCR:'sending y: ...'. |
8 | 2843 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2844 |
[exEnd] |
8 | 2845 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
2846 |
|
2396 | 2847 |
"Modified: / 25-06-1996 / 22:11:21 / stefan" |
2848 |
"Created: / 21-04-1998 / 15:30:27 / cg" |
|
8 | 2849 |
! |
2850 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2851 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:withOriginalClass flushCaches:flushCaches |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2852 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2853 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2854 |
entry, and get the current context passed as argument. ExitBlock will be called, |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2855 |
when the method is left, and get the current context and the methods return value as argument. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2856 |
If withOriginalClass is true, the class of anObject will be set to its original class |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2857 |
before the wrapped method will be called. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2858 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2859 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2860 |
^ self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2861 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2862 |
additionalEntryCode:nil additionalExitCode:nil additionalVariables:nil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2863 |
withOriginalClass:withOriginalClass flushCaches:flushCaches |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2864 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2865 |
|
88 | 2866 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
2867 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 2868 |
|
88 | 2869 |
aCollection do:[:aSelector | |
660 | 2870 |
self |
2871 |
wrap:anObject selector:aSelector |
|
2872 |
onEntry:entryBlock onExit:exitBlock |
|
2873 |
withOriginalClass:true |
|
2874 |
flushCaches:false |
|
2875 |
]. |
|
2876 |
ObjectMemory flushCaches |
|
2877 |
||
2878 |
"Modified: / 21.4.1998 / 15:40:28 / cg" |
|
8 | 2879 |
! |
2880 |
||
88 | 2881 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
2882 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 2883 |
|
2884 |
|allSelectors| |
|
2885 |
||
2886 |
allSelectors := IdentitySet new. |
|
972 | 2887 |
anObject class withAllSuperclassesDo:[:aClass | |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2888 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 2889 |
]. |
88 | 2890 |
self wrap:anObject selectors:allSelectors onEntry:entryBlock onExit:exitBlock |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2891 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2892 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 2893 |
! ! |
2894 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2895 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2896 |
|
1369 | 2897 |
allWrappedMethods |
3130 | 2898 |
^ Smalltalk allMethodsForWhich:[:mthd | mthd isWrapped] |
1369 | 2899 |
! |
2900 |
||
2901 |
areAnyMethodsWrapped |
|
1472
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2902 |
Smalltalk allMethodsDo:[:mthd | |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2903 |
mthd isWrapped ifTrue:[ ^ true ] |
1369 | 2904 |
]. |
2905 |
^ false |
|
2906 |
! |
|
2907 |
||
579 | 2908 |
isCounting:aMethod |
2909 |
"return true if aMethod is counted" |
|
2910 |
||
3308 | 2911 |
MethodCounts notNil ifTrue:[ |
2912 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
2913 |
aMethod isWrapped ifTrue:[ |
|
2914 |
(MethodCounts includesKey:aMethod originalMethod)ifTrue:[^ true]. |
|
2915 |
]. |
|
2916 |
]. |
|
2917 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
2918 |
(MethodCountsPerReceiverClass includesKey:aMethod) ifTrue:[^ true]. |
|
2919 |
aMethod isWrapped ifTrue:[ |
|
2920 |
(MethodCountsPerReceiverClass includesKey:aMethod originalMethod)ifTrue:[^ true]. |
|
2921 |
]. |
|
579 | 2922 |
]. |
2923 |
^ false |
|
2924 |
||
2925 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
2926 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2927 |
! |
|
2928 |
||
3308 | 2929 |
isCountingByReceiverClass:aMethod |
2930 |
"return true if aMethod is counted with per receiver class statistics" |
|
2931 |
||
2932 |
MethodCountsPerReceiverClass isNil ifTrue:[^ false]. |
|
2933 |
(MethodCountsPerReceiverClass includesKey:aMethod) ifTrue:[^ true]. |
|
2934 |
aMethod isWrapped ifTrue:[ |
|
2935 |
^ MethodCountsPerReceiverClass includesKey:aMethod originalMethod |
|
2936 |
]. |
|
2937 |
^ false |
|
2938 |
! |
|
2939 |
||
579 | 2940 |
isTiming:aMethod |
2941 |
"return true if aMethod is timed" |
|
2942 |
||
2943 |
MethodTiming isNil ifTrue:[^ false]. |
|
2944 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
2945 |
aMethod isWrapped ifTrue:[ |
|
2946 |
^ MethodTiming includesKey:aMethod originalMethod |
|
2947 |
]. |
|
2948 |
^ false |
|
2949 |
||
2950 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2951 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
2952 |
! |
|
2953 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2954 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2955 |
"return true, if a breakpoint is set on aMethod. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2956 |
This only returns true for standard breakpoints (i.e. for user-wraps, |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2957 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2958 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2959 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2960 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2961 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2962 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2963 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2964 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2965 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2966 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2967 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2968 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2969 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2970 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2971 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2972 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 2973 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2974 |
dummyEmptyMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2975 |
"helper - to get the time it takes to evaluate the wrappers for |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2976 |
a dummy method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2977 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2978 |
"Created: / 30.7.1998 / 16:58:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2979 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2980 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2981 |
getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2982 |
"helper - get the overhead (in ms) spent in the wrapper code of |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2983 |
a timed method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2984 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2985 |
|m times| |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2986 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2987 |
TimeForWrappers := 0. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2988 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2989 |
"/ wrap the dummy method ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2990 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2991 |
m := self class compiledMethodAt:#dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2992 |
m := self timeMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2993 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2994 |
"/ invoke it a few times ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2995 |
"/ (cannot take the smallest, since the work done in the wrapper |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2996 |
"/ depends on whether there is already some statistic data) |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2997 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2998 |
10 timesRepeat:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2999 |
self dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3000 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3001 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3002 |
"/ fetch min time & unwrap |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3003 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3004 |
times := self executionTimesOfMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3005 |
self stopTimingMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3006 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3007 |
^ (TimeForWrappers := times avgTime) |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3008 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3009 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3010 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3011 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3012 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3013 |
"Modified: / 05-03-2007 / 15:44:24 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3014 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
3015 |
|
88 | 3016 |
printEntryFull:aContext |
664 | 3017 |
self printEntryFull:aContext level:0 on:Stderr |
88 | 3018 |
! |
27 | 3019 |
|
88 | 3020 |
printEntryFull:aContext level:lvl |
664 | 3021 |
self printEntryFull:aContext level:lvl on:Stderr |
3022 |
! |
|
3023 |
||
3024 |
printEntryFull:aContext level:lvl on:aStream |
|
3025 |
aStream |
|
3026 |
spaces:lvl; |
|
734 | 3027 |
nextPutAll:'enter '. |
3028 |
self printFull:aContext on:aStream withSender:true. |
|
88 | 3029 |
! |
27 | 3030 |
|
664 | 3031 |
printEntryFull:aContext on:aStream |
3032 |
self printEntryFull:aContext level:0 on:aStream |
|
3033 |
! |
|
3034 |
||
3035 |
printEntrySender:aContext on:aStream |
|
3036 |
|sender mClass mClassName| |
|
3037 |
||
3038 |
mClass := aContext methodClass. |
|
3039 |
mClass isNil ifTrue:[ |
|
3040 |
mClassName := '???' |
|
3041 |
] ifFalse:[ |
|
3042 |
mClassName := mClass name |
|
3043 |
]. |
|
734 | 3044 |
|
664 | 3045 |
aStream |
3046 |
nextPutAll:mClassName; |
|
3047 |
space; |
|
665 | 3048 |
bold; |
664 | 3049 |
nextPutAll:aContext selector; |
665 | 3050 |
normal; |
664 | 3051 |
nextPutAll:' from '. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
3052 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3053 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3054 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3055 |
(sender selector startsWith:'perform:') ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3056 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3057 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3058 |
]. |
664 | 3059 |
sender printOn:aStream. |
666 | 3060 |
aStream cr; flush. |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
3061 |
|
695 | 3062 |
"Modified: / 30.7.1998 / 20:40:14 / cg" |
88 | 3063 |
! |
3064 |
||
3065 |
printExit:aContext with:retVal |
|
664 | 3066 |
self printExit:aContext with:retVal level:0 on:Stderr |
27 | 3067 |
! |
3068 |
||
88 | 3069 |
printExit:aContext with:retVal level:lvl |
664 | 3070 |
self printExit:aContext with:retVal level:lvl on:Stderr |
3071 |
! |
|
3072 |
||
3073 |
printExit:aContext with:retVal level:lvl on:aStream |
|
3074 |
|mClass mClassName| |
|
3075 |
||
3076 |
mClass := aContext methodClass. |
|
3077 |
mClass isNil ifTrue:[ |
|
3078 |
mClassName := '???' |
|
3079 |
] ifFalse:[ |
|
3080 |
mClassName := mClass name |
|
3081 |
]. |
|
3082 |
aStream |
|
3083 |
spaces:lvl; |
|
3084 |
nextPutAll:'leave '; |
|
3085 |
nextPutAll:mClassName; |
|
3086 |
space; |
|
665 | 3087 |
bold; |
664 | 3088 |
nextPutAll:aContext selector; |
665 | 3089 |
normal; |
666 | 3090 |
nextPutAll:' rec=['. |
664 | 3091 |
|
1486
d7ae9a86ea38
print same receiver on entry and exit
Stefan Vogel <sv@exept.de>
parents:
1472
diff
changeset
|
3092 |
self printObject:aContext receiver on:aStream. |
666 | 3093 |
aStream nextPutAll:'] return: ['. |
664 | 3094 |
retVal printOn:aStream. |
666 | 3095 |
aStream nextPutAll:']'; cr; flush. |
664 | 3096 |
! |
3097 |
||
3098 |
printExit:aContext with:retVal on:aStream |
|
3099 |
self printExit:aContext with:retVal level:0 on:aStream |
|
3100 |
! |
|
3101 |
||
734 | 3102 |
printFull:aContext on:aStream withSender:withSender |
1071 | 3103 |
self |
3104 |
printFull:aContext on:aStream |
|
3105 |
withSenderContext:(withSender ifTrue:[aContext sender] |
|
3106 |
ifFalse:[nil]) |
|
3107 |
! |
|
3108 |
||
3109 |
printFull:aContext on:aStream withSenderContext:aSenderContextOrNil |
|
3110 |
|mClass mClassName| |
|
734 | 3111 |
|
3112 |
mClass := aContext methodClass. |
|
3113 |
mClass isNil ifTrue:[ |
|
3114 |
mClassName := '???' |
|
3115 |
] ifFalse:[ |
|
3116 |
mClassName := mClass name |
|
3117 |
]. |
|
3118 |
||
3119 |
aStream |
|
3120 |
nextPutAll:mClassName; |
|
3121 |
space; |
|
3122 |
bold; |
|
3123 |
nextPutAll:aContext selector; |
|
3124 |
normal; |
|
3125 |
nextPutAll:' rec=['. |
|
3126 |
||
735 | 3127 |
self printObject:aContext receiver on:aStream. |
3128 |
||
734 | 3129 |
aStream nextPutAll:'] '. |
3130 |
(aContext args) keysAndValuesDo:[:idx :arg | |
|
3131 |
aStream nextPutAll:'arg'. idx printOn:aStream. aStream nextPutAll:'=['. |
|
735 | 3132 |
self printObject:arg on:aStream. |
734 | 3133 |
aStream nextPutAll:'] '. |
3134 |
]. |
|
3135 |
||
1071 | 3136 |
aSenderContextOrNil notNil ifTrue:[ |
3137 |
self printSender:aSenderContextOrNil on:aStream. |
|
734 | 3138 |
]. |
3139 |
aStream cr; flush. |
|
3140 |
! |
|
3141 |
||
735 | 3142 |
printObject:anObject on:aStream |
3143 |
|s| |
|
3144 |
||
3145 |
s := anObject printString. |
|
2085
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
3146 |
s size > 40 ifTrue:[ |
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
3147 |
s := s chopTo:40. |
735 | 3148 |
]. |
3149 |
aStream nextPutAll:s |
|
3150 |
! |
|
3151 |
||
1071 | 3152 |
printSender:aSenderContext on:aStream |
3153 |
|sender| |
|
3154 |
||
3155 |
sender := aSenderContext. |
|
3156 |
sender notNil ifTrue:[ |
|
3157 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3158 |
sender := sender sender. |
|
3159 |
]. |
|
3160 |
]. |
|
3161 |
aStream nextPutAll:'from:'. |
|
3162 |
aStream bold. |
|
3163 |
sender printOn:aStream. |
|
3164 |
aStream normal. |
|
3165 |
! |
|
3166 |
||
3167 |
printUpdateEntryFull:aContext level:lvl on:aStream |
|
3168 |
|con| |
|
3169 |
||
3170 |
con := aContext. |
|
3171 |
||
3172 |
[con notNil |
|
3173 |
and:[con selector ~~ #'changed:with:'] |
|
3174 |
] whileTrue:[ |
|
3175 |
con := con sender. |
|
3176 |
]. |
|
3177 |
"/ con is #'changed:with:' |
|
3178 |
con isNil ifTrue:[ |
|
3179 |
^ self printEntryFull:aContext level:lvl on:aStream. |
|
3180 |
]. |
|
3181 |
||
3182 |
(con sender notNil |
|
3183 |
and:[ con sender selector == #'changed:']) ifTrue:[ |
|
3184 |
con := con sender. |
|
3185 |
]. |
|
3186 |
(con sender notNil |
|
3187 |
and:[ con sender selector == #'changed']) ifTrue:[ |
|
3188 |
con := con sender. |
|
3189 |
]. |
|
3190 |
(con sender notNil) ifTrue:[ |
|
3191 |
con := con sender. |
|
3192 |
]. |
|
3193 |
||
3194 |
aStream spaces:lvl; nextPutAll:'enter '. |
|
3195 |
self |
|
3196 |
printFull:aContext |
|
3197 |
on:aStream |
|
3198 |
withSenderContext:con |
|
3199 |
! |
|
3200 |
||
697 | 3201 |
traceEntryFull:aContext on:aStream |
3202 |
aStream nextPutLine:'-----------------------------------------'. |
|
3203 |
aContext fullPrintAllOn:aStream |
|
3204 |
||
3205 |
"Created: / 30.7.1998 / 20:39:57 / cg" |
|
3206 |
"Modified: / 30.7.1998 / 20:42:23 / cg" |
|
3207 |
! |
|
3208 |
||
664 | 3209 |
traceFullBlockFor:aStream |
3210 |
"avoid generation of fullBlocks" |
|
3211 |
||
3212 |
aStream == Transcript ifTrue:[ |
|
3213 |
^ TraceFullBlock2 |
|
3214 |
]. |
|
3215 |
aStream == Stderr ifTrue:[ |
|
3216 |
^ TraceFullBlock |
|
3217 |
]. |
|
3218 |
^ [:con | con fullPrintAllOn:aStream] |
|
3219 |
||
3220 |
||
3221 |
||
3222 |
! |
|
3223 |
||
3224 |
traceSenderBlockFor:aStream |
|
3225 |
"avoid generation of fullBlocks" |
|
3226 |
||
3227 |
aStream == Transcript ifTrue:[ |
|
3228 |
^ TraceSenderBlock2 |
|
3229 |
]. |
|
3230 |
aStream == Stderr ifTrue:[ |
|
3231 |
^ TraceSenderBlock |
|
3232 |
]. |
|
3233 |
^ [:con | MessageTracer printEntrySender:con on:aStream] |
|
3234 |
||
3235 |
||
3236 |
||
88 | 3237 |
! ! |
13 | 3238 |
|
1082 | 3239 |
!MessageTracer methodsFor:'trace helpers'! |
88 | 3240 |
|
3241 |
trace:aBlock detail:fullDetail |
|
3242 |
"trace execution of aBlock." |
|
3243 |
||
3244 |
traceDetail := fullDetail. |
|
735 | 3245 |
tracedBlock := aBlock. |
3246 |
||
88 | 3247 |
ObjectMemory stepInterruptHandler:self. |
3248 |
^ [ |
|
735 | 3249 |
ObjectMemory flushInlineCaches. |
3250 |
StepInterruptPending := 1. |
|
3251 |
InterruptPending := 1. |
|
3252 |
aBlock value |
|
1139
56861678ff27
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1082
diff
changeset
|
3253 |
] ensure:[ |
735 | 3254 |
tracedBlock := nil. |
3255 |
StepInterruptPending := nil. |
|
3256 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 3257 |
] |
3258 |
||
3259 |
" |
|
735 | 3260 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:false |
3261 |
||
3262 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3263 |
||
3264 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3265 |
||
3266 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
8 | 3267 |
" |
3268 |
! ! |
|
27 | 3269 |
|
1082 | 3270 |
!MessageTracer::InteractionCollector methodsFor:'trace helpers'! |
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3271 |
|
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3272 |
stepInterrupt |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3273 |
StepInterruptPending := nil. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3274 |
ObjectMemory flushInlineCaches. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3275 |
StepInterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3276 |
InterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3277 |
! ! |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3278 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3279 |
!MessageTracer::MethodTimingInfo methodsFor:'accessing'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3280 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3281 |
avgTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3282 |
sumTimes notNil ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3283 |
^ sumTimes / count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3284 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3285 |
^ nil |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3286 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3287 |
"Created: / 05-03-2007 / 15:38:43 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3288 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3289 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3290 |
avgTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3291 |
|avg| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3292 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3293 |
avg := self avgTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3294 |
avg > 100 ifTrue:[ ^ avg roundTo:1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3295 |
avg > 10 ifTrue:[ ^ avg roundTo:0.1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3296 |
avg > 1 ifTrue:[ ^ avg roundTo:0.01 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3297 |
^ avg roundTo:0.001 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3298 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3299 |
"Created: / 05-03-2007 / 15:47:02 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3300 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3301 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3302 |
count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3303 |
^ count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3304 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3305 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3306 |
count:countArg minTime:minTimeArg maxTime:maxTimeArg sumTimes:sumTimesArg |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3307 |
count := countArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3308 |
minTime := minTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3309 |
maxTime := maxTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3310 |
sumTimes := sumTimesArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3311 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3312 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3313 |
maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3314 |
^ maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3315 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3316 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3317 |
maxTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3318 |
|max| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3319 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3320 |
max := self maxTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3321 |
^ max roundTo:(max > 10 ifTrue:0.1 ifFalse:0.01) |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3322 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3323 |
"Created: / 05-03-2007 / 15:47:22 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3324 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3325 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3326 |
minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3327 |
^ minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3328 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3329 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3330 |
minTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3331 |
|min| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3332 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3333 |
min := self minTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3334 |
^ min roundTo:(min > 10 ifTrue:0.1 ifFalse:0.01) |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3335 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3336 |
"Created: / 05-03-2007 / 15:47:16 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3337 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3338 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3339 |
sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3340 |
^ sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3341 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3342 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3343 |
!MessageTracer::MethodTimingInfo methodsFor:'initialization'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3344 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3345 |
rememberExecutionTime:t |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3346 |
(count isNil or:[count == 0]) ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3347 |
minTime := maxTime := sumTimes := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3348 |
count := 1. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3349 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3350 |
t < minTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3351 |
minTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3352 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3353 |
t > maxTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3354 |
maxTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3355 |
] |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3356 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3357 |
sumTimes := (sumTimes + t). |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3358 |
count := count + 1 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3359 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3360 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3361 |
"Created: / 05-03-2007 / 15:32:43 / cg" |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3362 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3363 |
|
2972 | 3364 |
!MessageTracer::PrintingMessageTracer methodsFor:'accessing'! |
3365 |
||
3366 |
output:something |
|
3367 |
output := something. |
|
3368 |
! ! |
|
3369 |
||
1082 | 3370 |
!MessageTracer::PrintingMessageTracer methodsFor:'trace helpers'! |
734 | 3371 |
|
3372 |
stepInterrupt |
|
3373 |
"called for every send while tracing" |
|
3374 |
||
3258 | 3375 |
|ignore sel con r outStream senderContext| |
734 | 3376 |
|
3377 |
StepInterruptPending := nil. |
|
3258 | 3378 |
con := senderContext := thisContext sender. |
734 | 3379 |
ignore := false. |
2972 | 3380 |
outStream := output ? Stderr. |
734 | 3381 |
|
3382 |
con receiver == Processor ifTrue:[ |
|
3383 |
(sel := con selector) == #threadSwitch: ifTrue:[ |
|
3384 |
ignore := true. |
|
3385 |
]. |
|
3386 |
sel == #timerInterrupt ifTrue:[ |
|
3387 |
ignore := true. |
|
3388 |
] |
|
3389 |
]. |
|
3390 |
||
3391 |
con lineNumber == 1 ifFalse:[ |
|
3392 |
ignore := true |
|
3393 |
]. |
|
3394 |
||
3395 |
ignore ifFalse:[ |
|
3396 |
con markForInterruptOnUnwind. |
|
3397 |
||
3398 |
((r := con receiver) ~~ self |
|
3399 |
and:[r ~~ tracedBlock]) ifTrue:[ |
|
3400 |
traceDetail == #fullIndent ifTrue:[ |
|
3401 |
[con notNil |
|
3402 |
and:[(r := con receiver) ~~ self |
|
3403 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
2972 | 3404 |
' ' printOn:outStream. |
734 | 3405 |
con := con sender. |
3406 |
]. |
|
3258 | 3407 |
con := senderContext. |
2972 | 3408 |
self class printFull:con on:outStream withSender:false. |
734 | 3409 |
] ifFalse:[ |
3410 |
traceDetail == #indent ifTrue:[ |
|
3411 |
[con notNil |
|
3412 |
and:[(r := con receiver) ~~ self |
|
3413 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
2972 | 3414 |
' ' printOn:outStream. |
734 | 3415 |
con := con sender. |
3416 |
]. |
|
3258 | 3417 |
con := senderContext. |
2972 | 3418 |
con printOn:outStream. |
3419 |
outStream cr. |
|
734 | 3420 |
] ifFalse:[ |
3421 |
traceDetail == true ifTrue:[ |
|
2972 | 3422 |
self class printFull:con on:outStream withSender:true. |
734 | 3423 |
] ifFalse:[ |
2972 | 3424 |
con printOn:outStream. |
3425 |
outStream cr. |
|
734 | 3426 |
] |
3427 |
] |
|
3428 |
]. |
|
3429 |
]. |
|
3430 |
]. |
|
3431 |
||
3432 |
ObjectMemory flushInlineCaches. |
|
3433 |
StepInterruptPending := 1. |
|
3434 |
InterruptPending := 1. |
|
3435 |
||
3436 |
" |
|
3437 |
self new trace:[#(6 5 4 3 2 1) sort] detail:false |
|
3438 |
||
3439 |
self new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3440 |
||
3441 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3442 |
||
3443 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
3444 |
self new trace:[ View new ] detail:#fullIndent |
|
3445 |
" |
|
3446 |
! ! |
|
3447 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
3448 |
!MessageTracer class methodsFor:'documentation'! |
98 | 3449 |
|
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
3450 |
version_CVS |
3347 | 3451 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.126 2013-07-13 20:36:18 cg Exp $' |
3012 | 3452 |
! |
3453 |
||
3121
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3095
diff
changeset
|
3454 |
version_HG |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3095
diff
changeset
|
3455 |
|
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3095
diff
changeset
|
3456 |
^ '$Changeset: <not expanded> $' |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3095
diff
changeset
|
3457 |
! |
19723298dd2c
Bugfix: reading of Java class extensions methods.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3095
diff
changeset
|
3458 |
|
3012 | 3459 |
version_SVN |
3241 | 3460 |
^ 'Id: MessageTracer.st 1981 2012-11-30 17:20:01Z vranyj1 ' |
98 | 3461 |
! ! |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3462 |
|
3130 | 3463 |
|
27 | 3464 |
MessageTracer initialize! |