author | Claus Gittinger <cg@exept.de> |
Sun, 30 Jun 2013 10:11:02 +0200 | |
changeset 3326 | eaabf640cda5 |
parent 3308 | 25b846cf6917 |
child 3329 | a4cbc797038b |
child 3347 | 9cd0b535463b |
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 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
860 |
!MessageTracer class methodsFor:'method counting'! |
155 | 861 |
|
862 |
countMethod:aMethod |
|
2972 | 863 |
"arrange for a aMethod's execution to be counted. |
155 | 864 |
Use unwrapMethod to remove this." |
865 |
||
866 |
MethodCounts isNil ifTrue:[ |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
867 |
MethodCounts := IdentityDictionary new. |
155 | 868 |
]. |
869 |
MethodCounts at:aMethod put:0. |
|
870 |
||
871 |
^ self wrapMethod:aMethod |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
872 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
873 |
|cnt| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
874 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
875 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
876 |
MethodCounts at:aMethod put:(cnt + 1). |
2972 | 877 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
878 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
879 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
880 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
881 |
] |
155 | 882 |
|
883 |
" |
|
884 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
885 |
5 factorial. |
|
886 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
887 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
888 |
" |
|
889 |
||
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
890 |
"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
|
891 |
"Modified: / 27.7.1998 / 10:47:46 / cg" |
155 | 892 |
! |
893 |
||
3308 | 894 |
countMethodByReceiverClass:aMethod |
895 |
"arrange for a aMethod's execution to be counted and maintain |
|
896 |
a per-receiver class profile. |
|
897 |
Use unwrapMethod to remove this." |
|
898 |
||
899 |
MethodCountsPerReceiverClass isNil ifTrue:[ |
|
900 |
MethodCountsPerReceiverClass := IdentityDictionary new. |
|
901 |
]. |
|
902 |
MethodCountsPerReceiverClass at:aMethod put:(IdentityDictionary new). |
|
903 |
||
904 |
^ self wrapMethod:aMethod |
|
905 |
onEntry:[:con | |
|
906 |
|cls perMethodCounts cnt| |
|
907 |
||
908 |
cls := (con receiver class). |
|
909 |
perMethodCounts := MethodCountsPerReceiverClass at:aMethod. |
|
910 |
cnt := perMethodCounts at:cls ifAbsentPut:0. |
|
911 |
perMethodCounts at:cls put:(cnt + 1). |
|
912 |
MessageTracer changed:#statistics: with:aMethod. |
|
913 |
aMethod changed:#statistics |
|
914 |
] |
|
915 |
onExit:[:con :retVal | |
|
916 |
] |
|
917 |
||
918 |
" |
|
919 |
MessageTracer countMethodWithReceiverStatistic:(Collection compiledMethodAt:#detect:). |
|
920 |
NewSystemBrowser open. |
|
921 |
MessageTracer executionCountsOf:(Collection compiledMethodAt:#detect:) printNL. |
|
922 |
MessageTracer stopCountingMethod:(Collection compiledMethodAt:#detect:) |
|
923 |
" |
|
924 |
! |
|
925 |
||
155 | 926 |
executionCountOfMethod:aMethod |
927 |
"return the current count" |
|
928 |
||
3308 | 929 |
|count counts| |
930 |
||
931 |
MethodCounts notNil ifTrue:[ |
|
932 |
aMethod isWrapped ifTrue:[ |
|
933 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
|
934 |
count notNil ifTrue:[^ count]. |
|
935 |
]. |
|
936 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
937 |
]. |
|
938 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
939 |
aMethod isWrapped ifTrue:[ |
|
940 |
counts := MethodCountsPerReceiverClass at:aMethod originalMethod ifAbsent:nil. |
|
941 |
]. |
|
942 |
counts isNil ifTrue:[ |
|
943 |
counts := MethodCounts at:aMethod ifAbsent:#(). |
|
944 |
]. |
|
945 |
^ (counts collect:[:eachClassCountAssoc | eachClassCountAssoc value]) sum |
|
155 | 946 |
]. |
3308 | 947 |
^ 0 |
948 |
! |
|
949 |
||
950 |
executionCountsByReceiverClassOfMethod:aMethod |
|
951 |
"return a collection mapping receiver class to call counts" |
|
952 |
||
953 |
|counts| |
|
954 |
||
955 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
956 |
aMethod isWrapped ifTrue:[ |
|
957 |
counts := MethodCountsPerReceiverClass at:aMethod originalMethod ifAbsent:nil. |
|
958 |
]. |
|
959 |
counts isNil ifTrue:[ |
|
960 |
counts := MethodCounts at:aMethod ifAbsent:#(). |
|
961 |
]. |
|
962 |
^ counts |
|
963 |
]. |
|
964 |
^ #() |
|
155 | 965 |
! |
966 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
967 |
resetCountOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
968 |
"return the current count" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
969 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
970 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
971 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
972 |
MethodCounts at:aMethod originalMethod put:0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
973 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
974 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
975 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
976 |
"Created: / 30.7.1998 / 17:42:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
977 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
978 |
|
155 | 979 |
stopCountingMethod:aMethod |
980 |
"remove counting of aMethod" |
|
981 |
||
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
982 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
983 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
984 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
985 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
986 |
]. |
3308 | 987 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
988 |
aMethod isWrapped ifTrue:[ |
|
989 |
MethodCountsPerReceiverClass removeKey:aMethod originalMethod ifAbsent:nil. |
|
990 |
]. |
|
991 |
]. |
|
155 | 992 |
^ self unwrapMethod:aMethod |
993 |
||
994 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
995 |
! ! |
|
996 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
997 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
998 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
999 |
countMemoryUsageOfMethod:aMethod |
2972 | 1000 |
"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
|
1001 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1002 |
|
501 | 1003 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1004 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1005 |
MethodCounts isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1006 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1007 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1008 |
MethodMemoryUsage isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1009 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1010 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1011 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1012 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1013 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1014 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1015 |
^ self wrapMethod:aMethod |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1016 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1017 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1018 |
oldNewUsed := ObjectMemory newSpaceUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1019 |
oldScavengeCount := ObjectMemory scavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1020 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1021 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1022 |
|cnt memUse scavenges| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1023 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1024 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1025 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1026 |
scavenges ~= 0 ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1027 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1028 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1029 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1030 |
MethodCounts notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1031 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1032 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1033 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1034 |
MethodMemoryUsage notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1035 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1036 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1037 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1038 |
Processor activeProcess priority:oldPriority. |
2972 | 1039 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1040 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1041 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1042 |
onUnwind:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1043 |
oldPriority notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1044 |
Processor activeProcess priority:oldPriority |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1045 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1046 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1047 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1048 |
" |
2825
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1049 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR). |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1050 |
3 factorialR. |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1051 |
Transcript showCR:(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorialR)). |
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1052 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorialR) |
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 |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1055 |
"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
|
1056 |
"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
|
1057 |
"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
|
1058 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1059 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1060 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1061 |
"return true if aMethod is counting memoryUsage" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1062 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1063 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1064 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1065 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1066 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1067 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1068 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1069 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1070 |
"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
|
1071 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1072 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1073 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1074 |
"return the current count" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1075 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1076 |
|count memUse orgMethod| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1077 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1078 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1079 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1080 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1081 |
count := MethodCounts at:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1082 |
memUse := MethodMemoryUsage at:orgMethod ifAbsent:nil. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1083 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1084 |
memUse isNil ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1085 |
count := MethodCounts at:aMethod ifAbsent:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1086 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1087 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1088 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1089 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1090 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1091 |
"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
|
1092 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1093 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1094 |
resetMemoryUsageOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1095 |
"reset the current usage" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1096 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1097 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1098 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1099 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1100 |
MethodMemoryUsage notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1101 |
aMethod isWrapped ifTrue:[ |
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1102 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1103 |
MethodCounts at:orgMethod put:0. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1104 |
MethodMemoryUsage at:orgMethod put:nil. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1105 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1106 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1107 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1108 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1109 |
"Created: / 30.7.1998 / 17:43:07 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1110 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1111 |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1112 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1113 |
"remove counting memory of aMethod" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1114 |
|
764
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1115 |
|orgMethod| |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1116 |
|
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1117 |
MethodCounts notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1118 |
MethodMemoryUsage notNil ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1119 |
aMethod isWrapped ifTrue:[ |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1120 |
orgMethod := aMethod originalMethod. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1121 |
MethodCounts removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1122 |
MethodMemoryUsage removeKey:orgMethod ifAbsent:nil. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1123 |
] |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1124 |
]. |
883a5f35113c
fixed reset count & reset memCount
Claus Gittinger <cg@exept.de>
parents:
736
diff
changeset
|
1125 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1126 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1127 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1128 |
"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
|
1129 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1130 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1131 |
!MessageTracer class methodsFor:'method timing'! |
327 | 1132 |
|
1133 |
executionTimesOfMethod:aMethod |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1134 |
"return the current gathered execution time statistics" |
327 | 1135 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1136 |
|info| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1137 |
|
327 | 1138 |
MethodTiming notNil ifTrue:[ |
1139 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1140 |
info := ( MethodTiming at:(aMethod originalMethod) ifAbsent:nil ) copy. |
327 | 1141 |
]. |
1142 |
]. |
|
1143 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1144 |
info isNil ifTrue:[ info := MethodTimingInfo new ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1145 |
^ info |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1146 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1147 |
"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
|
1148 |
"Modified: / 05-03-2007 / 15:46:17 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1149 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1150 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1151 |
resetExecutionTimesOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1152 |
"reset the gathered execution times statistics for aMethod; |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1153 |
the method remains wrapped." |
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 |
MethodTiming notNil ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1156 |
MethodTiming removeKey:aMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1157 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1158 |
MethodTiming removeKey:aMethod originalMethod. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1159 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1160 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1161 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1162 |
"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
|
1163 |
"Modified: / 05-03-2007 / 15:36:59 / cg" |
327 | 1164 |
! |
1165 |
||
1166 |
stopTimingMethod:aMethod |
|
1167 |
"remove timing of aMethod" |
|
1168 |
||
1169 |
^ self unwrapMethod:aMethod |
|
1170 |
||
1171 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
1172 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
1173 |
! |
|
1174 |
||
1175 |
timeMethod:aMethod |
|
2972 | 1176 |
"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
|
1177 |
Use unwrapMethod: or stopTimingMethod: to remove this." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1178 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1179 |
|t0| |
327 | 1180 |
|
1181 |
MethodTiming isNil ifTrue:[ |
|
1182 |
MethodTiming := IdentityDictionary new. |
|
1183 |
]. |
|
1184 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1185 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1186 |
TimeForWrappers isNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1187 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1188 |
]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1189 |
|
327 | 1190 |
^ self wrapMethod:aMethod |
1191 |
onEntry:[:con | |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1192 |
t0 := OperatingSystem getMicrosecondTime. |
327 | 1193 |
] |
1194 |
onExit:[:con :retVal | |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
1195 |
|info t cnt minT maxT sumTimes| |
327 | 1196 |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1197 |
t := OperatingSystem getMicrosecondTime - t0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1198 |
t := t - TimeForWrappers. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1199 |
t < 0 ifTrue:[t := 0]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1200 |
t := t / 1000.0. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1201 |
|
2004 | 1202 |
MethodTiming isNil ifTrue:[ |
1203 |
MethodTiming := IdentityDictionary new. |
|
1204 |
]. |
|
327 | 1205 |
info := MethodTiming at:aMethod ifAbsent:nil. |
1206 |
info isNil ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1207 |
MethodTiming at:aMethod put:(info := MethodTimingInfo new) |
327 | 1208 |
] ifFalse:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1209 |
info rememberExecutionTime:t. |
327 | 1210 |
]. |
2972 | 1211 |
MessageTracer changed:#statistics: with:aMethod. |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1212 |
aMethod changed:#statistics |
327 | 1213 |
] |
1214 |
||
1215 |
" |
|
1216 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
1217 |
5 factorial. |
|
1218 |
5 factorial. |
|
1219 |
5 factorial. |
|
1220 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
1221 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
1222 |
" |
|
1223 |
||
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1224 |
"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
|
1225 |
"Modified: / 05-03-2007 / 15:34:01 / cg" |
327 | 1226 |
! ! |
1227 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1228 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 1229 |
|
664 | 1230 |
traceClass:aClass selector:aSelector |
1231 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
1232 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1233 |
||
1234 |
self traceClass:aClass selector:aSelector on:Stderr |
|
1235 |
||
1236 |
" |
|
1237 |
MessageTracer traceClass:Integer selector:#factorial. |
|
1238 |
5 factorial. |
|
1239 |
MessageTracer untraceClass:Integer |
|
1240 |
" |
|
1241 |
" |
|
1242 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
1243 |
#(6 1 9 66 2 17) copy sort. |
|
1244 |
MessageTracer untraceClass:SequenceableCollection |
|
1245 |
" |
|
1246 |
" |
|
1247 |
MessageTracer traceClass:Array selector:#at:. |
|
1248 |
MessageTracer traceClass:Array selector:#at:put:. |
|
1249 |
#(6 1 9 66 2 17) copy sort. |
|
1250 |
MessageTracer untraceClass:Array |
|
1251 |
" |
|
1252 |
! |
|
1253 |
||
1254 |
traceClass:aClass selector:aSelector on:aStream |
|
1255 |
"arrange for a trace message to be output on aStream, when a message with aSelector is |
|
1256 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1257 |
||
1258 |
self traceMethod:(aClass compiledMethodAt:aSelector) on:aStream |
|
1259 |
||
1260 |
" |
|
1261 |
MessageTracer traceClass:Integer selector:#factorial on:Transcript. |
|
1262 |
5 factorial. |
|
1263 |
MessageTracer untraceClass:Integer |
|
1264 |
" |
|
1265 |
" |
|
1266 |
MessageTracer traceClass:Integer selector:#factorialR on:Transcript. |
|
1267 |
5 factorialR. |
|
1268 |
MessageTracer untraceClass:Integer |
|
1269 |
" |
|
1270 |
||
1271 |
! |
|
1272 |
||
88 | 1273 |
traceMethod:aMethod |
664 | 1274 |
"arrange for a trace message to be output on Stderr, |
1275 |
when aMethod is executed. Traces both entry and exit. |
|
88 | 1276 |
Use unwrapMethod to remove this." |
1277 |
||
664 | 1278 |
^ self traceMethod:aMethod on:Stderr |
11 | 1279 |
|
1280 |
" |
|
88 | 1281 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
1282 |
5 factorial. |
|
1283 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1284 |
" |
|
1285 |
" |
|
664 | 1286 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR). |
1287 |
5 factorialR. |
|
1288 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1289 |
" |
|
1290 |
" |
|
88 | 1291 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
1292 |
#(6 1 9 66 2 17) copy sort. |
|
1293 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1294 |
" |
|
1295 |
" |
|
1296 |
dont do this: |
|
1297 |
" |
|
1298 |
" |
|
1299 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
1300 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
1301 |
#(6 1 9 66 2 17) copy sort. |
|
1302 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
1303 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 1304 |
" |
1305 |
! |
|
1306 |
||
664 | 1307 |
traceMethod:aMethod on:aStream |
1308 |
"arrange for a trace message to be output on aStream, |
|
1309 |
when aMethod is executed. Traces both entry and exit. |
|
1310 |
Use unwrapMethod to remove this." |
|
1311 |
||
1312 |
|lvl inside| |
|
1313 |
||
1314 |
^ self wrapMethod:aMethod |
|
1315 |
onEntry:[:con | |
|
1316 |
inside isNil ifTrue:[ |
|
1317 |
inside := true. |
|
1318 |
CallingLevel isNil ifTrue:[ |
|
1319 |
CallingLevel := 0. |
|
1320 |
]. |
|
1321 |
lvl notNil ifTrue:[ |
|
1322 |
lvl := lvl + 1 |
|
1323 |
] ifFalse:[ |
|
1324 |
CallingLevel := lvl := CallingLevel + 1. |
|
1325 |
]. |
|
1326 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1327 |
inside := nil |
|
1328 |
] |
|
1329 |
] |
|
1330 |
onExit:[:con :retVal | |
|
1331 |
inside isNil ifTrue:[ |
|
1332 |
inside := true. |
|
1333 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1334 |
CallingLevel := lvl := lvl - 1. |
|
1335 |
inside := nil |
|
1336 |
] |
|
1337 |
] |
|
1338 |
||
1339 |
" |
|
1340 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1341 |
5 factorial. |
|
1342 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1343 |
" |
|
1344 |
" |
|
1345 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1346 |
5 factorialR. |
|
1347 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1348 |
" |
|
1349 |
" |
|
1350 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1351 |
#(6 1 9 66 2 17) copy sort. |
|
1352 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1353 |
" |
|
1354 |
! |
|
1355 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1356 |
traceMethodAll:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1357 |
"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
|
1358 |
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
|
1359 |
Use untraceMethod to remove this trace. |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1360 |
This is for system debugging only; |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1361 |
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
|
1362 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1363 |
^ self wrapMethod:aMethod |
699
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1364 |
onEntry:[:con | ObjectMemory flushCaches. ObjectMemory sendTraceOn.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1365 |
onExit:[:con :val | ObjectMemory sendTraceOff.] |
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1366 |
|
52a632386cef
some debugging methods moved from Smalltalk to ObjectMemory
Claus Gittinger <cg@exept.de>
parents:
698
diff
changeset
|
1367 |
"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
|
1368 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1369 |
|
664 | 1370 |
traceMethodEntry:aMethod |
1371 |
"arrange for a trace message to be output on stdErr, |
|
1372 |
when aMethod is executed. Only entry is traced. |
|
1373 |
Use unwrapMethod to remove this." |
|
1374 |
||
1375 |
^ self traceMethodEntry:aMethod on:Stderr |
|
1376 |
||
1377 |
" |
|
1378 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial). |
|
1379 |
5 factorial. |
|
1380 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1381 |
" |
|
1382 |
" |
|
1383 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR). |
|
1384 |
5 factorialR. |
|
1385 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1386 |
" |
|
1387 |
" |
|
1388 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1389 |
#(6 1 9 66 2 17) copy sort. |
|
1390 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1391 |
" |
|
1392 |
! |
|
1393 |
||
1394 |
traceMethodEntry:aMethod on:aStream |
|
1395 |
"arrange for a trace message to be output on aStream, |
|
1396 |
when aMethod is executed. Only entry is traced. |
|
1397 |
Use unwrapMethod to remove this." |
|
1398 |
||
1399 |
|lvl inside| |
|
1400 |
||
1401 |
^ self wrapMethod:aMethod |
|
1402 |
onEntry:[:con | |
|
1403 |
inside isNil ifTrue:[ |
|
1404 |
inside := true. |
|
1405 |
CallingLevel isNil ifTrue:[ |
|
1406 |
CallingLevel := 0. |
|
1407 |
]. |
|
1408 |
lvl notNil ifTrue:[ |
|
1409 |
lvl := lvl + 1 |
|
1410 |
] ifFalse:[ |
|
1411 |
CallingLevel := lvl := CallingLevel + 1. |
|
1412 |
]. |
|
1413 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1414 |
inside := nil |
|
1415 |
] |
|
1416 |
] |
|
1417 |
onExit:[:con :retVal |] |
|
1418 |
||
1419 |
" |
|
1420 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1421 |
5 factorial. |
|
1422 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1423 |
" |
|
1424 |
" |
|
1425 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1426 |
5 factorialR. |
|
1427 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1428 |
" |
|
1429 |
" |
|
1430 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1431 |
#(6 1 9 66 2 17) copy sort. |
|
1432 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1433 |
" |
|
1434 |
! |
|
1435 |
||
156 | 1436 |
traceMethodFull:aMethod |
1437 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
1438 |
Only the sender is traced on entry. |
|
1439 |
Use untraceMethod to remove this trace." |
|
1440 |
||
664 | 1441 |
^ self traceMethodFull:aMethod on:Stderr |
1442 |
||
1443 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
1444 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
|
1445 |
! |
|
1446 |
||
1447 |
traceMethodFull:aMethod on:aStream |
|
1448 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
|
1449 |
Only the sender is traced on entry. |
|
1450 |
Use untraceMethod to remove this trace." |
|
1451 |
||
1452 |
^ self |
|
1453 |
wrapMethod:aMethod |
|
1454 |
onEntry:(self traceFullBlockFor:aStream) |
|
1455 |
onExit:LeaveTraceBlock. |
|
156 | 1456 |
|
1457 |
"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
|
1458 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 1459 |
! |
1460 |
||
88 | 1461 |
traceMethodSender:aMethod |
664 | 1462 |
"arrange for a trace message to be output on Stderr, |
1463 |
when amethod is executed. |
|
1464 |
Only the sender is traced on entry. |
|
1465 |
Use untraceMethod to remove this trace." |
|
1466 |
||
1467 |
^ self traceMethodSender:aMethod on:Stderr |
|
1468 |
! |
|
1469 |
||
1470 |
traceMethodSender:aMethod on:aStream |
|
88 | 1471 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
1472 |
Only the sender is traced on entry. |
|
1473 |
Use untraceMethod to remove this trace." |
|
35 | 1474 |
|
664 | 1475 |
^ self |
1476 |
wrapMethod:aMethod |
|
1477 |
onEntry:(self traceSenderBlockFor:aStream) |
|
1478 |
onExit:LeaveTraceBlock. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1479 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1480 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1481 |
! |
1482 |
||
1071 | 1483 |
traceUpdateMethod:aMethod on:aStream |
1484 |
"arrange for a trace message to be output on aStream, |
|
1485 |
when aMethod is executed. |
|
1486 |
Traces both entry and exit. |
|
1487 |
Use unwrapMethod to remove this. |
|
1488 |
This one is specialized for change-update calling i.e. it traces from the update |
|
1489 |
back to the origial change message." |
|
1490 |
||
1491 |
|lvl inside| |
|
1492 |
||
1493 |
^ self |
|
1494 |
wrapMethod:aMethod |
|
1495 |
onEntry:[:con | |
|
1496 |
inside isNil ifTrue:[ |
|
1497 |
inside := true. |
|
1498 |
CallingLevel isNil ifTrue:[ |
|
1499 |
CallingLevel := 0. |
|
1500 |
]. |
|
1501 |
lvl notNil ifTrue:[ |
|
1502 |
lvl := lvl + 1 |
|
1503 |
] ifFalse:[ |
|
1504 |
CallingLevel := lvl := CallingLevel + 1. |
|
1505 |
]. |
|
1506 |
MessageTracer printUpdateEntryFull:con level:lvl on:aStream. |
|
1507 |
inside := nil |
|
1508 |
] |
|
1509 |
] |
|
1510 |
onExit:[:con :retVal | |
|
1511 |
inside isNil ifTrue:[ |
|
1512 |
inside := true. |
|
1513 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1514 |
CallingLevel := lvl := lvl - 1. |
|
1515 |
inside := nil |
|
1516 |
] |
|
1517 |
] |
|
1518 |
! |
|
1519 |
||
88 | 1520 |
untraceMethod:aMethod |
1521 |
"remove tracing of aMethod" |
|
1522 |
||
1523 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1524 |
trace facilities ..." |
|
1525 |
||
1526 |
^ self unwrapMethod:aMethod |
|
11 | 1527 |
! ! |
1528 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1529 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1530 |
|
88 | 1531 |
unwrapAllMethods |
1532 |
"just in case you dont know what methods have break/trace-points |
|
1533 |
on them; this removes them all" |
|
1534 |
||
2396 | 1535 |
WrappedMethod allInstancesDo:[:aWrapperMethod | |
1536 |
aWrapperMethod unregister. |
|
1537 |
self unwrapMethod:aWrapperMethod. |
|
88 | 1538 |
] |
1145 | 1539 |
|
1540 |
" |
|
1541 |
MessageTracer unwrapAllMethods |
|
1542 |
" |
|
2396 | 1543 |
|
1544 |
"Modified: / 01-07-2011 / 10:02:47 / cg" |
|
11 | 1545 |
! |
1546 |
||
88 | 1547 |
unwrapMethod:aMethod |
1548 |
"remove any wrapper on aMethod" |
|
1549 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1550 |
|selector class originalMethod dict mthd| |
88 | 1551 |
|
1970 | 1552 |
aMethod isWrapped ifTrue:[ |
1553 |
originalMethod := aMethod originalMethod. |
|
1554 |
]. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1555 |
|
155 | 1556 |
MethodCounts notNil ifTrue:[ |
265 | 1557 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1558 |
MethodCounts removeKey:originalMethod ifAbsent:nil. |
265 | 1559 |
]. |
1560 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
1561 |
MethodCounts isEmpty ifTrue:[MethodCounts := nil]. |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1562 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1563 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1564 |
aMethod isWrapped ifTrue:[ |
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1565 |
MethodMemoryUsage removeKey:originalMethod ifAbsent:nil. |
265 | 1566 |
]. |
1567 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
1568 |
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil]. |
|
155 | 1569 |
]. |
327 | 1570 |
MethodTiming notNil ifTrue:[ |
1571 |
aMethod isWrapped ifTrue:[ |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1572 |
MethodTiming removeKey:originalMethod ifAbsent:nil. |
327 | 1573 |
]. |
1574 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1575 |
MethodTiming isEmpty ifTrue:[MethodTiming := nil]. |
|
1576 |
]. |
|
155 | 1577 |
|
88 | 1578 |
CallingLevel := 0. |
1579 |
||
1580 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1581 |
^ aMethod |
88 | 1582 |
]. |
1583 |
||
1584 |
" |
|
1585 |
get class/selector |
|
1586 |
" |
|
1587 |
class := aMethod containingClass. |
|
1588 |
class isNil ifTrue:[ |
|
536 | 1589 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
265 | 1590 |
^ aMethod |
88 | 1591 |
]. |
1592 |
selector := class selectorAtMethod:aMethod. |
|
1593 |
||
1594 |
originalMethod isNil ifTrue:[ |
|
808 | 1595 |
self error:'oops, could not find original method' mayProceed:true. |
265 | 1596 |
^ aMethod |
88 | 1597 |
]. |
1598 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1599 |
dict := class methodDictionary. |
506 | 1600 |
mthd := dict at:selector ifAbsent:nil. |
1601 |
mthd notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1602 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1603 |
class methodDictionary:dict. |
88 | 1604 |
] ifFalse:[ |
667 | 1605 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
1606 |
"/ self halt:'oops, unexpected error - cannot remove wrap'. |
|
1607 |
aMethod becomeSameAs:originalMethod. |
|
265 | 1608 |
^ aMethod |
88 | 1609 |
]. |
1610 |
||
1611 |
ObjectMemory flushCaches. |
|
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1612 |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1613 |
class changed:#methodTrap with:selector. "/ tell browsers |
2278 | 1614 |
MethodTrapChangeNotificationParameter notNil ifTrue:[ |
1615 |
Smalltalk changed:#methodTrap with:(MethodTrapChangeNotificationParameter changeClass:class changeSelector:selector). |
|
1616 |
]. |
|
88 | 1617 |
^ originalMethod |
265 | 1618 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
1619 |
"Modified: / 05-06-1996 / 14:08:08 / stefan" |
1970 | 1620 |
"Modified: / 04-10-2007 / 16:41:01 / cg" |
13 | 1621 |
! |
1622 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1623 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1624 |
^ 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
|
1625 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1626 |
"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
|
1627 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1628 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1629 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1630 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1631 |
aMethod is evaluated. |
|
1632 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1633 |
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
|
1634 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1635 |
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
|
1636 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
572 | 1637 |
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
|
1638 |
" |
88 | 1639 |
|
1452 | 1640 |
|selector class trapMethod s spec src dict sel saveUS xselector| |
88 | 1641 |
|
1642 |
CallingLevel := 0. |
|
1643 |
||
1644 |
" |
|
1645 |
create a new method, which calls the original one, |
|
1646 |
but only if not already being trapped. |
|
1647 |
" |
|
1648 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1649 |
^ aMethod |
88 | 1650 |
]. |
1651 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1652 |
aMethod makeRealMethod |
88 | 1653 |
]. |
1654 |
||
1655 |
" |
|
1656 |
get class/selector |
|
1657 |
" |
|
1658 |
class := aMethod containingClass. |
|
1659 |
class isNil ifTrue:[ |
|
808 | 1660 |
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
|
1661 |
^ aMethod |
88 | 1662 |
]. |
1663 |
selector := class selectorAtMethod:aMethod. |
|
1664 |
||
1665 |
WrappedMethod autoload. "/ for small systems |
|
1666 |
||
1667 |
" |
|
1668 |
get a new method-spec |
|
1669 |
" |
|
730 | 1670 |
xselector := '_x'. |
729 | 1671 |
aMethod numArgs timesRepeat:[ |
1672 |
xselector := xselector , '_:' |
|
1673 |
]. |
|
1674 |
spec := Parser methodSpecificationForSelector:xselector. |
|
88 | 1675 |
|
1676 |
" |
|
1677 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1678 |
" |
|
1679 |
s := WriteStream on:String new. |
|
1680 |
s nextPutAll:spec. |
|
3286 | 1681 |
s nextPutAll:' <context: #return>'. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1682 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1683 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1684 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1685 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1686 |
]. |
88 | 1687 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1688 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1689 |
]. |
1690 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1691 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1692 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1693 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1694 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1695 |
nextPutAll: ' sender:nil. '. |
1696 |
||
1697 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1698 |
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
|
1699 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1700 |
unwindBlock notNil ifTrue:[ |
2825
e8266b38d38c
comment/format in: #countMemoryUsageOfMethod:
Stefan Vogel <sv@exept.de>
parents:
2523
diff
changeset
|
1701 |
s nextPutAll:'] ifCurtailed:#unwindBlock yourself.'. |
88 | 1702 |
]. |
1703 |
s nextPutAll:'^ retVal'; cr. |
|
1704 |
||
1705 |
src := s contents. |
|
1452 | 1706 |
saveUS := Compiler allowUnderscoreInIdentifier. |
1707 |
ParserFlags |
|
1708 |
withSTCCompilation:#never |
|
1709 |
do:[ |
|
1710 |
[ |
|
1711 |
Compiler allowUnderscoreInIdentifier:true. |
|
1712 |
Class withoutUpdatingChangesDo:[ |
|
3286 | 1713 |
trapMethod := Compiler |
1714 |
compile:src |
|
1715 |
forClass:UndefinedObject |
|
1452 | 1716 |
inCategory:aMethod category |
3286 | 1717 |
notifying:nil |
1718 |
install:false |
|
1452 | 1719 |
skipIfSame:false |
3286 | 1720 |
silent:false. "/ true. |
1452 | 1721 |
] |
1722 |
] ensure:[ |
|
1723 |
Compiler allowUnderscoreInIdentifier:saveUS. |
|
1724 |
]. |
|
1725 |
]. |
|
88 | 1726 |
|
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
1727 |
trapMethod setPackage:aMethod package. |
88 | 1728 |
trapMethod changeClassTo:WrappedMethod. |
2396 | 1729 |
trapMethod register. |
1730 |
||
88 | 1731 |
" |
1732 |
raising our eyebrows here ... |
|
1733 |
" |
|
1734 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1735 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1736 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1737 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1738 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1739 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1740 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1741 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1742 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1743 |
]. |
88 | 1744 |
" |
1745 |
change the source of this new method |
|
1746 |
(to avoid confusion in the debugger ...) |
|
1747 |
" |
|
840
5ec82d6c2e55
care for the wrappers source info (to allow source access in browser)
Claus Gittinger <cg@exept.de>
parents:
825
diff
changeset
|
1748 |
"/ 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
|
1749 |
trapMethod sourceFilename:(aMethod getSource) position:(aMethod getSourcePosition). |
88 | 1750 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1751 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1752 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1753 |
sel == 0 ifTrue:[ |
808 | 1754 |
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
|
1755 |
^ aMethod |
88 | 1756 |
]. |
1757 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1758 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1759 |
class methodDictionary:dict. |
88 | 1760 |
ObjectMemory flushCaches. |
1144
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1761 |
|
001b374a2431
change notification when traps are added/removed
Claus Gittinger <cg@exept.de>
parents:
1139
diff
changeset
|
1762 |
class changed:#methodTrap with:selector. "/ tell browsers |
2278 | 1763 |
MethodTrapChangeNotificationParameter notNil ifTrue:[ |
1764 |
Smalltalk changed:#methodTrap with:(MethodTrapChangeNotificationParameter changeClass:class changeSelector:selector). |
|
1765 |
]. |
|
88 | 1766 |
^ trapMethod |
1767 |
||
1768 |
" |
|
1769 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1770 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1771 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1772 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1773 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1774 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1775 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1776 |
]. |
88 | 1777 |
(1@2) scaleBy:5. |
1778 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1779 |
(1@2) scaleBy:5. |
|
1780 |
" |
|
1781 |
" |
|
1782 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1783 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1784 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1785 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1786 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1787 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1788 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1789 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1790 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1791 |
]. |
258 | 1792 |
Transcript showCR:'5 factorial traced'. |
88 | 1793 |
5 factorial. |
1794 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1795 |
Transcript showCR:'5 factorial normal'. |
88 | 1796 |
5 factorial. |
1797 |
" |
|
1798 |
" |
|
1799 |
|lvl| |
|
1800 |
||
1801 |
lvl := 0. |
|
1802 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1803 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1804 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1805 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1806 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1807 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1808 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1809 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1810 |
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
|
1811 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1812 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1813 |
]. |
258 | 1814 |
Transcript showCR:'5 factorial traced'. |
88 | 1815 |
5 factorial. |
1816 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1817 |
Transcript showCR:'5 factorial normal'. |
88 | 1818 |
5 factorial. |
1819 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1820 |
|
2396 | 1821 |
"Modified: / 25-06-1996 / 22:04:51 / stefan" |
1822 |
"Modified: / 01-07-2011 / 10:01:48 / cg" |
|
88 | 1823 |
! ! |
1824 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1825 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1826 |
|
525 | 1827 |
objectHasWraps:anObject |
1828 |
"return true, if anObject has any wraps" |
|
1829 |
||
1830 |
^ anObject class category == #'* trapping *' |
|
1831 |
! |
|
1832 |
||
1833 |
realClassOf:anObject |
|
1834 |
"return anObjects real class" |
|
1835 |
||
1836 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1837 |
^ anObject class |
|
1838 |
]. |
|
1839 |
^ anObject class superclass |
|
1840 |
! |
|
1841 |
||
88 | 1842 |
trap:anObject selector:aSelector |
1843 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1844 |
sent to anObject. Use untrap to remove this trap. |
|
1845 |
The current implementation does not allow integers or nil to be trapped." |
|
1846 |
||
1847 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1848 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1849 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1850 |
onExit:LeaveBreakBlock. |
88 | 1851 |
|
1852 |
" |
|
1853 |
|p| |
|
1854 |
||
1855 |
p := Point new. |
|
1856 |
MessageTracer trap:p selector:#x:. |
|
1857 |
p x:5 |
|
1858 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1859 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1860 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1861 |
! |
1862 |
||
88 | 1863 |
trap:anObject selectors:aCollection |
1864 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1865 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1866 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1867 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1868 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1869 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1870 |
! |
1871 |
||
1872 |
trapAll:anObject |
|
1873 |
"trap on all messages which are understood by anObject" |
|
1874 |
||
1875 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1876 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1877 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1878 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1879 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1880 |
! |
1881 |
||
1882 |
trapAll:anObject from:aClass |
|
1883 |
"trap on all messages defined in aClass sent to anObject" |
|
1884 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1885 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1886 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1887 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1888 |
! |
1889 |
||
1890 |
untrap:anObject |
|
1891 |
"remove any traps on anObject" |
|
1892 |
||
1893 |
"this is done by just patching the objects class back to the original" |
|
1894 |
||
1895 |
|orgClass| |
|
1896 |
||
1897 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1898 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1899 |
^ self |
88 | 1900 |
]. |
1901 |
||
660 | 1902 |
anObject changeClassTo:orgClass superclass. |
662 | 1903 |
ObjectCopyHolders notNil ifTrue:[ |
1904 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1905 |
]. |
|
88 | 1906 |
|
1907 |
" |
|
1908 |
|p| |
|
1909 |
||
1910 |
p := Point new copy. |
|
1911 |
MessageTracer trace:p selector:#x:. |
|
1912 |
MessageTracer trace:p selector:#y:. |
|
1913 |
p y:1. |
|
1914 |
p x:2. |
|
1915 |
MessageTracer untrap:p |
|
1916 |
p y:2. |
|
1917 |
p x:1. |
|
1918 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1919 |
|
660 | 1920 |
"Modified: / 21.4.1998 / 15:43:33 / cg" |
13 | 1921 |
! |
1922 |
||
88 | 1923 |
untrap:anObject selector:aSelector |
1924 |
"remove trap on aSelector from anObject" |
|
1925 |
||
501 | 1926 |
|orgClass dict| |
88 | 1927 |
|
1928 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1929 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 1930 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1931 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1932 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 1933 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1934 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1935 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1936 |
anObject changeClassTo:orgClass superclass. |
662 | 1937 |
ObjectCopyHolders notNil ifTrue:[ |
1938 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1939 |
]. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1940 |
^ self |
88 | 1941 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1942 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1943 |
orgClass methodDictionary:dict. |
88 | 1944 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
1945 |
||
1946 |
" |
|
1947 |
|p| |
|
1948 |
||
1949 |
p := Point new copy. |
|
1950 |
MessageTracer trace:p selector:#x:. |
|
1951 |
MessageTracer trace:p selector:#y:. |
|
1952 |
'trace both ...' errorPrintNL. |
|
1953 |
p x:2. |
|
1954 |
p y:1. |
|
1955 |
'trace only y ...' errorPrintNL. |
|
1956 |
MessageTracer untrap:p selector:#x:. |
|
1957 |
p x:2. |
|
1958 |
p y:1. |
|
1959 |
'trace none ...' errorPrintNL. |
|
1960 |
MessageTracer untrap:p selector:#y:. |
|
1961 |
p x:2. |
|
1962 |
p y:1. |
|
1963 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1964 |
|
660 | 1965 |
"Modified: / 5.6.1996 / 13:56:08 / stefan" |
1966 |
"Modified: / 21.4.1998 / 15:43:55 / cg" |
|
525 | 1967 |
! |
1968 |
||
1969 |
wrappedSelectorsOf:anObject |
|
1970 |
"return the set of wrapped selectors (if any)" |
|
1971 |
||
1972 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1973 |
^ #() |
|
1974 |
]. |
|
1975 |
^ anObject class selectors |
|
11 | 1976 |
! ! |
1977 |
||
660 | 1978 |
!MessageTracer class methodsFor:'object modification traps'! |
1979 |
||
1980 |
trapModificationsIn:anObject |
|
1981 |
"trap modifications in anObject" |
|
1982 |
||
1983 |
self |
|
663 | 1984 |
trapModificationsIn:anObject filter:[:old :new | true] |
660 | 1985 |
|
1986 |
" |
|
1987 |
|a| |
|
1988 |
||
1989 |
a := Array new:10. |
|
1990 |
MessageTracer trapModificationsIn:a. |
|
1991 |
||
1992 |
a size. |
|
1993 |
a at:1. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1994 |
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
|
1995 |
a at:2 put:2. ' expect trap here (changing nil to 2) '. |
660 | 1996 |
a at:2. |
1997 |
a at:3. |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
1998 |
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
|
1999 |
a at:2 put:3. ' expect trap here (changing 2 to 3) '. |
660 | 2000 |
MessageTracer untrace:a. |
2001 |
a at:3 put:5. |
|
2002 |
" |
|
2003 |
||
2004 |
"Created: / 21.4.1998 / 14:32:34 / cg" |
|
2005 |
"Modified: / 21.4.1998 / 14:58:24 / cg" |
|
2006 |
! |
|
2007 |
||
2008 |
trapModificationsIn:anObject filter:aFilterBlock |
|
2009 |
"trap modifications in anObject" |
|
2010 |
||
2011 |
|allSelectors| |
|
2012 |
||
2013 |
allSelectors := IdentitySet new. |
|
972 | 2014 |
anObject class withAllSuperclassesDo:[:aClass | |
660 | 2015 |
aClass methodDictionary keys addAllTo:allSelectors |
2016 |
]. |
|
2017 |
||
2018 |
self trapModificationsIn:anObject selectors:allSelectors filter:aFilterBlock |
|
2019 |
||
2020 |
"trap if arrays 5th slot is modified: |
|
2021 |
||
2022 |
|a| |
|
2023 |
||
2024 |
a := Array new:10. |
|
2025 |
MessageTracer trapModificationsIn:a filter:[:old :new | (old at:5) ~~ (new at:5)]. |
|
2026 |
||
2027 |
a size. |
|
2028 |
a at:1. |
|
2029 |
a at:2 put:nil. |
|
2030 |
a at:2 put:2. |
|
2031 |
a at:2. |
|
2032 |
a at:3. |
|
2033 |
a at:2 put:2. |
|
2034 |
a at:2 put:3. |
|
2035 |
a at:5 put:3. |
|
2036 |
a at:5 put:3. |
|
2037 |
MessageTracer untrace:a. |
|
2038 |
a at:3 put:5. |
|
2039 |
" |
|
2040 |
||
2041 |
"Modified: / 21.4.1998 / 15:53:38 / cg" |
|
2042 |
! |
|
2043 |
||
2044 |
trapModificationsIn:anObject selector:aSelector filter:aFilterBlock |
|
2045 |
"install a trap for modifications in anObject by aSelector-messages. |
|
2046 |
the filterBlock will be invoked (after a modification) with the old and |
|
2047 |
new values as arguments and should return true, |
|
2048 |
if the debugger is really wanted." |
|
2049 |
||
2050 |
self |
|
2051 |
trapModificationsIn:anObject |
|
2052 |
selectors:(Array with:aSelector) |
|
2053 |
filter:aFilterBlock |
|
2054 |
||
2055 |
"Modified: / 21.4.1998 / 15:34:44 / cg" |
|
2056 |
! |
|
2057 |
||
2058 |
trapModificationsIn:anObject selectors:aCollectionOfSelectors filter:aFilterBlock |
|
2059 |
"install a trap for modifications in anObject by aSelector-messages. |
|
2060 |
the filterBlock will be invoked (after a modification) with the old and |
|
2061 |
new values as arguments and should return true, |
|
2062 |
if the debugger is really wanted." |
|
2063 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2064 |
|copyHolder sels checkBlock| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2065 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2066 |
(anObject isNil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2067 |
or:[anObject isSymbol |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2068 |
or:[anObject class == SmallInteger |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2069 |
or:[anObject == true |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2070 |
or:[anObject == false]]]]) |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2071 |
ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2072 |
self error:'cannot place trap on this object' mayProceed:true. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2073 |
^ self. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2074 |
]. |
660 | 2075 |
|
2076 |
ObjectCopyHolders isNil ifTrue:[ |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2077 |
ObjectCopyHolders := WeakIdentityDictionary new. |
660 | 2078 |
]. |
2079 |
copyHolder := ObjectCopyHolders at:anObject ifAbsent:nil. |
|
2080 |
copyHolder isNil ifTrue:[ |
|
2081 |
ObjectCopyHolders at:anObject put:(copyHolder := ValueHolder new). |
|
2082 |
]. |
|
2083 |
||
2084 |
copyHolder value:(anObject shallowCopy). |
|
2085 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2086 |
"/ 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
|
2087 |
"/ do no harm to the object ... consider this a kludge |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2088 |
sels := aCollectionOfSelectors copy. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2089 |
sels removeAll:#(#class #species #yourself #'sameContentsAs:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2090 |
#'instVarAt:' #'at:' #'basicAt:' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2091 |
#'shallowCopy' #'copy' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2092 |
#'=' #'==' #'~=' #'~~' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2093 |
#'size' |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2094 |
). |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2095 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2096 |
checkBlock := |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2097 |
[:con :retVal | |
660 | 2098 |
|oldValue| |
2099 |
||
2100 |
oldValue := copyHolder value. |
|
2101 |
||
2102 |
"/ compare with copy ... |
|
2103 |
(anObject sameContentsAs:oldValue) ifFalse:[ |
|
2104 |
"/ see oldValue vs. anObject |
|
2105 |
(aFilterBlock value:oldValue value:anObject) ifTrue:[ |
|
2106 |
copyHolder value:(anObject shallowCopy). |
|
2107 |
ObjectWrittenBreakpointSignal |
|
2108 |
raiseRequestWith:(oldValue -> anObject) |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2109 |
errorString:('object was modififed in: ' , con sender selector) |
660 | 2110 |
in:con sender |
2111 |
] |
|
2112 |
] |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2113 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2114 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2115 |
sels do:[:aSelector | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2116 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2117 |
wrap:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2118 |
selector:aSelector |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2119 |
onEntry:[:con | ] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2120 |
onExit:checkBlock |
660 | 2121 |
withOriginalClass:true |
2122 |
flushCaches:false. |
|
2123 |
]. |
|
2124 |
ObjectMemory flushCaches |
|
2125 |
||
2126 |
"Created: / 21.4.1998 / 15:34:05 / cg" |
|
2127 |
"Modified: / 21.4.1998 / 16:00:39 / cg" |
|
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2128 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2129 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2130 |
trapModificationsOf:anInstVarOrOffset in:anObject |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2131 |
"trap modifications in anObject" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2132 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2133 |
|idx selectors definingClass| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2134 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2135 |
anInstVarOrOffset isInteger ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2136 |
"/ indexed slot |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2137 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2138 |
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
|
2139 |
] ifFalse:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2140 |
"/ instVar by name |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2141 |
selectors := IdentitySet new. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2142 |
definingClass := anObject class whichClassDefinesInstVar:anInstVarOrOffset. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2143 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2144 |
definingClass withAllSuperclassesDo:[:aClass | |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2145 |
aClass methodDictionary keys addAllTo:selectors |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2146 |
]. |
3326 | 2147 |
idx := anObject class instVarIndexFor:anInstVarOrOffset. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2148 |
self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2149 |
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
|
2150 |
] |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2151 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2152 |
" |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2153 |
|a| |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2154 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2155 |
a := Array new:10. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2156 |
MessageTracer trapModificationsOf:2 in:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2157 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2158 |
a size. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2159 |
a at:1. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2160 |
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
|
2161 |
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
|
2162 |
a at:2. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2163 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2164 |
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
|
2165 |
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
|
2166 |
a at:3. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2167 |
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
|
2168 |
MessageTracer untrace:a. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2169 |
a at:3 put:5. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2170 |
" |
660 | 2171 |
! ! |
2172 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2173 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 2174 |
|
2175 |
trace:anObject selector:aSelector |
|
2176 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2177 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2178 |
Use untrap to remove this trace. |
|
2179 |
The current implementation does not allow integers or nil to be traced." |
|
2180 |
||
664 | 2181 |
self trace:anObject selector:aSelector on:Stderr |
88 | 2182 |
|
2183 |
" |
|
2184 |
|p| |
|
8 | 2185 |
|
88 | 2186 |
p := Point new. |
2187 |
MessageTracer trace:p selector:#x:. |
|
2188 |
p x:5. |
|
2189 |
p y:1. |
|
2190 |
p x:10. |
|
2191 |
MessageTracer untrap:p. |
|
2192 |
p x:7 |
|
2193 |
" |
|
2194 |
" |
|
2195 |
|a| |
|
2196 |
||
2197 |
a := #(6 1 9 66 2 17) copy. |
|
2198 |
MessageTracer trace:a selector:#at:put:. |
|
2199 |
MessageTracer trace:a selector:#at:. |
|
2200 |
a sort. |
|
2201 |
" |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2202 |
|
660 | 2203 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
88 | 2204 |
! |
2205 |
||
664 | 2206 |
trace:anObject selector:aSelector on:aStream |
2207 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2208 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
2209 |
Use untrap to remove this trace. |
|
2210 |
The current implementation does not allow integers or nil to be traced." |
|
2211 |
||
2212 |
self |
|
2213 |
trace:anObject |
|
2214 |
selectors:(Array with:aSelector) |
|
2215 |
on:aStream |
|
2216 |
||
2217 |
" |
|
2218 |
|p| |
|
2219 |
||
2220 |
p := Point new. |
|
2221 |
MessageTracer trace:p selector:#x: on:Stderr. |
|
2222 |
p x:5. |
|
2223 |
p y:1. |
|
2224 |
p x:10. |
|
2225 |
MessageTracer untrap:p. |
|
2226 |
p x:7 |
|
2227 |
" |
|
2228 |
" |
|
2229 |
|a| |
|
2230 |
||
2231 |
a := #(6 1 9 66 2 17) copy. |
|
2232 |
MessageTracer trace:a selector:#at:put: on:Stderr. |
|
2233 |
MessageTracer trace:a selector:#at:. on:Stderr |
|
2234 |
a sort. |
|
2235 |
" |
|
2236 |
||
2237 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
|
2238 |
! |
|
2239 |
||
660 | 2240 |
trace:anObject selectors:aCollectionOfSelectors |
2241 |
"arrange for a trace message to be output on Stderr, when any message |
|
2242 |
from aCollectionOfSelectors is sent to anObject. |
|
2243 |
Both entry and exit are traced. |
|
2244 |
Use untrap:/untrace: to remove this trace. |
|
2245 |
The current implementation does not allow integers or nil to be traced." |
|
2246 |
||
664 | 2247 |
self trace:anObject selectors:aCollectionOfSelectors on:Stderr |
88 | 2248 |
|
2249 |
" |
|
660 | 2250 |
|p| |
2251 |
||
2252 |
p := Point new. |
|
2253 |
MessageTracer trace:p selector:#x:. |
|
2254 |
p x:5. |
|
2255 |
p y:1. |
|
2256 |
p x:10. |
|
2257 |
MessageTracer untrap:p. |
|
2258 |
p x:7 |
|
2259 |
" |
|
2260 |
" |
|
2261 |
|a| |
|
2262 |
||
2263 |
a := #(6 1 9 66 2 17) copy. |
|
2264 |
MessageTracer trace:a selector:#at:put:. |
|
2265 |
MessageTracer trace:a selector:#at:. |
|
2266 |
a sort. |
|
88 | 2267 |
" |
2268 |
||
660 | 2269 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
88 | 2270 |
! |
2271 |
||
664 | 2272 |
trace:anObject selectors:aCollectionOfSelectors on:aStream |
2273 |
"arrange for a trace message to be output on Stderr, when any message |
|
2274 |
from aCollectionOfSelectors is sent to anObject. |
|
2275 |
Both entry and exit are traced. |
|
2276 |
Use untrap:/untrace: to remove this trace. |
|
2277 |
The current implementation does not allow integers or nil to be traced." |
|
2278 |
||
2279 |
aCollectionOfSelectors do:[:aSelector | |
|
3290 | 2280 |
|methodName| |
2281 |
||
664 | 2282 |
methodName := anObject class name , '>>' , aSelector. |
2283 |
self |
|
2284 |
wrap:anObject |
|
2285 |
selector:aSelector |
|
2286 |
onEntry:[:con | |
|
2287 |
aStream nextPutAll:'enter '; nextPutAll:methodName. |
|
2288 |
aStream nextPutAll:' receiver='. |
|
2289 |
con receiver printOn:aStream. |
|
2290 |
aStream nextPutAll:' args='. (con args) printOn:aStream. |
|
2291 |
aStream nextPutAll:' from:'. con sender printOn:aStream. |
|
2292 |
aStream cr; flush |
|
2293 |
] |
|
2294 |
onExit:[:con :retVal | |
|
2295 |
aStream nextPutAll:'leave '; nextPutAll:methodName. |
|
2296 |
aStream nextPutAll:' receiver='. con receiver printOn:aStream. |
|
2297 |
aStream nextPutAll:' returning:'. retVal printOn:aStream. |
|
2298 |
aStream cr; flush |
|
2299 |
] |
|
2300 |
withOriginalClass:true |
|
2301 |
flushCaches:false |
|
2302 |
]. |
|
2303 |
ObjectMemory flushCaches |
|
2304 |
||
2305 |
" |
|
2306 |
|p| |
|
2307 |
||
2308 |
p := Point new. |
|
2309 |
MessageTracer trace:p selectors:#(x:) on:Transcript. |
|
2310 |
p x:5. |
|
2311 |
p y:1. |
|
2312 |
p x:10. |
|
2313 |
MessageTracer untrap:p. |
|
2314 |
p x:7 |
|
2315 |
" |
|
2316 |
" |
|
2317 |
|a| |
|
2318 |
||
2319 |
a := #(6 1 9 66 2 17) copy. |
|
2320 |
MessageTracer trace:a selectors:#( at:put: at:) on:Transcript. |
|
2321 |
a sort. |
|
2322 |
" |
|
2323 |
||
2324 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2325 |
! |
|
2326 |
||
88 | 2327 |
traceAll:anObject |
2328 |
"trace all messages which are understood by anObject" |
|
27 | 2329 |
|
664 | 2330 |
self traceAll:anObject on:Stderr |
88 | 2331 |
|
2332 |
" |
|
2333 |
trace all (implemented) messages sent to Display |
|
2334 |
(other messages lead to an error, anyway) |
|
2335 |
" |
|
2336 |
||
2337 |
" |
|
2338 |
MessageTracer traceAll:Display |
|
2339 |
MessageTracer untrace:Display |
|
2340 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2341 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2342 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 2343 |
! |
2344 |
||
2345 |
traceAll:anObject from:aClass |
|
2346 |
"trace all messages defined in aClass sent to anObject" |
|
2347 |
||
664 | 2348 |
self traceAll:anObject from:aClass on:Stderr |
88 | 2349 |
|
2350 |
" |
|
2351 |
trace all methods in Display, which are implemented |
|
2352 |
in the DisplayWorkstation class. |
|
2353 |
" |
|
2354 |
||
2355 |
" |
|
2356 |
MessageTracer traceAll:Display from:XWorkstation |
|
2357 |
MessageTracer untrace:Display |
|
2358 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2359 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2360 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 2361 |
! |
2362 |
||
664 | 2363 |
traceAll:anObject from:aClass on:aStream |
2364 |
"trace all messages defined in aClass sent to anObject" |
|
2365 |
||
2366 |
self trace:anObject selectors:aClass selectors on:aStream |
|
2367 |
||
2368 |
" |
|
2369 |
trace all methods in Display, which are implemented |
|
2370 |
in the DisplayWorkstation class. |
|
2371 |
" |
|
2372 |
||
2373 |
" |
|
2374 |
MessageTracer traceAll:Display from:XWorkstation on:Transcript |
|
2375 |
MessageTracer untrace:Display |
|
2376 |
" |
|
2377 |
||
2378 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
|
2379 |
! |
|
2380 |
||
2381 |
traceAll:anObject on:aStream |
|
2382 |
"trace all messages which are understood by anObject" |
|
2383 |
||
2384 |
|allSelectors| |
|
2385 |
||
2386 |
allSelectors := IdentitySet new. |
|
972 | 2387 |
anObject class withAllSuperclassesDo:[:aClass | |
664 | 2388 |
aClass methodDictionary keys addAllTo:allSelectors |
2389 |
]. |
|
2390 |
self trace:anObject selectors:allSelectors on:aStream |
|
2391 |
||
2392 |
" |
|
2393 |
trace all (implemented) messages sent to Display |
|
2394 |
(other messages lead to an error, anyway) |
|
2395 |
" |
|
2396 |
||
2397 |
" |
|
2398 |
MessageTracer traceAll:Display on:Transcript |
|
2399 |
MessageTracer untrace:Display |
|
2400 |
" |
|
2401 |
||
2402 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
|
2403 |
! |
|
2404 |
||
2405 |
traceEntry:anObject selectors:aCollectionOfSelectors on:aStream |
|
2406 |
"arrange for a trace message to be output on Stderr, when any message |
|
2407 |
from aCollectionOfSelectors is sent to anObject. |
|
2408 |
Only entry is traced. |
|
2409 |
Use untrap:/untrace: to remove this trace. |
|
2410 |
The current implementation does not allow integers or nil to be traced." |
|
2411 |
||
2412 |
self |
|
2413 |
traceEntry:anObject selectors:aCollectionOfSelectors on:Stderr |
|
2414 |
||
2415 |
" |
|
2416 |
|p| |
|
2417 |
||
2418 |
p := Point new. |
|
2419 |
MessageTracer traceEntry:p selectors:#(x:). |
|
2420 |
p x:5. |
|
2421 |
p y:1. |
|
2422 |
p x:10. |
|
2423 |
MessageTracer untrap:p. |
|
2424 |
p x:7 |
|
2425 |
" |
|
2426 |
" |
|
2427 |
|a| |
|
2428 |
||
2429 |
a := #(6 1 9 66 2 17) copy. |
|
2430 |
MessageTracer traceEntry:a selectors:#( at:put: at:). |
|
2431 |
a sort. |
|
2432 |
" |
|
2433 |
||
2434 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2435 |
! |
|
2436 |
||
88 | 2437 |
traceSender:anObject selector:aSelector |
2438 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2439 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2440 |
Use untrap to remove this trace. |
|
2441 |
The current implementation does not allow integers or nil to be traced." |
|
2442 |
||
664 | 2443 |
^ self traceSender:anObject selector:aSelector on:Stderr |
88 | 2444 |
|
2445 |
" |
|
2446 |
|p| |
|
27 | 2447 |
|
88 | 2448 |
p := Point new. |
2449 |
MessageTracer traceSender:p selector:#x:. |
|
2450 |
p x:5. |
|
2451 |
p y:1. |
|
2452 |
p x:10. |
|
2453 |
MessageTracer untrap:p. |
|
2454 |
p x:7 |
|
2455 |
" |
|
2456 |
" |
|
2457 |
|a| |
|
2458 |
||
2459 |
a := #(6 1 9 66 2 17) copy. |
|
2460 |
MessageTracer traceSender:a selector:#at:put:. |
|
2461 |
MessageTracer traceSender:a selector:#at:. |
|
2462 |
a sort. |
|
2463 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2464 |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2465 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
11 | 2466 |
! |
2467 |
||
664 | 2468 |
traceSender:anObject selector:aSelector on:aStream |
2469 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2470 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2471 |
Use untrap to remove this trace. |
|
2472 |
The current implementation does not allow integers or nil to be traced." |
|
2473 |
||
2474 |
|methodName| |
|
2475 |
||
2476 |
methodName := anObject class name , '>>' , aSelector. |
|
2477 |
self wrap:anObject |
|
2478 |
selector:aSelector |
|
2479 |
onEntry:[:con | |
|
2480 |
aStream nextPutAll:methodName. |
|
2481 |
aStream nextPutAll:' from '. |
|
2482 |
con sender printOn:aStream. |
|
2483 |
aStream cr; flush. |
|
2484 |
] |
|
2485 |
onExit:LeaveTraceBlock. |
|
2486 |
||
2487 |
" |
|
2488 |
|p| |
|
2489 |
||
2490 |
p := Point new. |
|
2491 |
MessageTracer traceSender:p selector:#x: on:Transcript. |
|
2492 |
p x:5. |
|
2493 |
p y:1. |
|
2494 |
p x:10. |
|
2495 |
MessageTracer untrap:p. |
|
2496 |
p x:7 |
|
2497 |
" |
|
2498 |
" |
|
2499 |
|a| |
|
2500 |
||
2501 |
a := #(6 1 9 66 2 17) copy. |
|
2502 |
MessageTracer traceSender:a selector:#at:put: on:Transcript. |
|
2503 |
MessageTracer traceSender:a selector:#at:. on:Transcript |
|
2504 |
a sort. |
|
2505 |
" |
|
2506 |
||
2507 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
|
2508 |
! |
|
2509 |
||
88 | 2510 |
untrace:anObject |
2511 |
"remove any traces on anObject" |
|
2512 |
||
2513 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2514 |
trace facilities ..." |
|
2515 |
||
2516 |
^ self untrap:anObject |
|
2517 |
! |
|
2518 |
||
2519 |
untrace:anObject selector:aSelector |
|
2520 |
"remove traces of aSelector sent to anObject" |
|
2521 |
||
2522 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2523 |
trace facilities ..." |
|
2524 |
||
2525 |
^ self untrap:anObject selector:aSelector |
|
2526 |
! ! |
|
2527 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2528 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 2529 |
|
8 | 2530 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
2531 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
2532 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2533 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
2534 |
when the method is left, and get the context and the methods return value as arguments. |
|
2535 |
The current implementation does not allow integers or nil to be wrapped." |
|
2536 |
||
2537 |
"I have not yet enough experience, if the wrapped original method should |
|
2538 |
run as an instance of the original, or of the catching class; |
|
2539 |
The latter has the advantage of catching recursive and other sends, while |
|
2540 |
it might lead into trouble when the message is sent from a debugger or a long |
|
2541 |
return is done out of the original method ... |
|
2542 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
2543 |
" |
|
660 | 2544 |
^ self |
2545 |
wrap:anObject |
|
2546 |
selector:aSelector |
|
2547 |
onEntry:entryBlock |
|
2548 |
onExit:exitBlock |
|
2549 |
withOriginalClass:true |
|
2550 |
flushCaches:true |
|
2551 |
||
2552 |
"Modified: / 21.4.1998 / 15:29:50 / cg" |
|
8 | 2553 |
! |
2554 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2555 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock additionalEntryCode:additionalEntryCode additionalExitCode:additionalExitCode additionalVariables:additionalVariables withOriginalClass:withOriginalClass flushCaches:flushCaches |
8 | 2556 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
2557 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2558 |
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
|
2559 |
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
|
2560 |
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
|
2561 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2562 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 2563 |
|
1452 | 2564 |
|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
|
2565 |
originalMethod| |
8 | 2566 |
|
2567 |
" |
|
27 | 2568 |
some are not allowed (otherwise we get into trouble ...) |
2569 |
" |
|
660 | 2570 |
(aSelector == #class |
2571 |
or:[aSelector == #changeClassTo:]) ifTrue:[ |
|
256 | 2572 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
2573 |
^ self |
|
27 | 2574 |
]. |
2575 |
||
2576 |
WrappedMethod autoload. "/ just to make sure ... |
|
2577 |
||
2578 |
" |
|
8 | 2579 |
create a new (anonymous) subclass of the receivers class |
2580 |
but only if not already being trapped. |
|
2581 |
" |
|
2582 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2583 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 2584 |
newClass := orgClass |
8 | 2585 |
] ifFalse:[ |
256 | 2586 |
myMetaclass := orgClass class. |
8 | 2587 |
|
256 | 2588 |
newClass := myMetaclass copy new. |
2589 |
newClass setSuperclass:orgClass. |
|
2590 |
newClass instSize:orgClass instSize. |
|
2591 |
newClass flags:orgClass flags. |
|
667 | 2592 |
newClass isMeta ifFalse:[newClass setClassVariableString:'']. |
256 | 2593 |
newClass setInstanceVariableString:''. |
2594 |
newClass setName:orgClass name. |
|
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
2595 |
newClass setCategory:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2596 |
newClass methodDictionary:MethodDictionary new. |
8 | 2597 |
]. |
2598 |
||
2599 |
" |
|
2600 |
create a method, executing the trap-blocks and the original method via a super-send |
|
2601 |
" |
|
2602 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
2603 |
s := WriteStream on:String new. |
|
2604 |
s nextPutAll:spec. |
|
3286 | 2605 |
s nextPutAll:' <context: #return>'. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2606 |
s nextPutAll:' |retVal stubClass '. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2607 |
additionalVariables notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2608 |
s nextPutAll:additionalVariables. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2609 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2610 |
s nextPutAll:'| '. |
8 | 2611 |
withOriginalClass ifTrue:[ |
256 | 2612 |
s nextPutAll:'stubClass := self class. '. |
2613 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 2614 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2615 |
additionalEntryCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2616 |
s nextPutAll:additionalEntryCode. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2617 |
]. |
8 | 2618 |
entryBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2619 |
s nextPutAll:'#literal1 yourself value:thisContext. '. "/ #literal1 will be replaced by the entryBlock |
8 | 2620 |
]. |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2621 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 2622 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 2623 |
exitBlock notNil ifTrue:[ |
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2624 |
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
|
2625 |
]. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2626 |
additionalExitCode notNil ifTrue:[ |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2627 |
s nextPutAll:additionalExitCode. |
8 | 2628 |
]. |
2629 |
withOriginalClass ifTrue:[ |
|
256 | 2630 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 2631 |
]. |
2632 |
s nextPutAll:'^ retVal'; cr. |
|
2633 |
||
1452 | 2634 |
ParserFlags |
2635 |
withSTCCompilation:#never |
|
2636 |
do:[ |
|
2637 |
Class withoutUpdatingChangesDo:[ |
|
3286 | 2638 |
trapMethod := Compiler |
2639 |
compile:s contents |
|
2640 |
forClass:newClass |
|
1452 | 2641 |
inCategory:'breakpointed' |
3286 | 2642 |
notifying:nil |
2643 |
install:false |
|
1452 | 2644 |
skipIfSame:false |
3286 | 2645 |
silent:true. |
1452 | 2646 |
] |
2647 |
]. |
|
8 | 2648 |
|
646 | 2649 |
trapMethod == #Error ifTrue:[ |
2650 |
Transcript showCR:('cannot place trap on method: ' , aSelector). |
|
2651 |
^ self |
|
2652 |
]. |
|
2653 |
||
29 | 2654 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
2655 |
implClass isNil ifTrue:[ |
|
256 | 2656 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 2657 |
] ifFalse:[ |
955
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2658 |
originalMethod := (implClass compiledMethodAt:aSelector). |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2659 |
originalMethod notNil ifTrue:[ |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2660 |
trapMethod setPackage:originalMethod package. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2661 |
]. |
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2662 |
|
0516771efa2a
preserve a methods packageID when wrapping
Claus Gittinger <cg@exept.de>
parents:
950
diff
changeset
|
2663 |
trapMethod changeLiteral:#originalMethod to:originalMethod. |
29 | 2664 |
]. |
8 | 2665 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2666 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 2667 |
]. |
2668 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2669 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 2670 |
]. |
2671 |
" |
|
2672 |
change the source of this new method |
|
2673 |
(to avoid confusion in the debugger ...) |
|
2674 |
" |
|
2675 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 2676 |
trapMethod changeClassTo:WrappedMethod. |
2396 | 2677 |
trapMethod register. |
8 | 2678 |
|
2679 |
" |
|
2680 |
install this new method |
|
2681 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2682 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2683 |
dict := dict at:aSelector putOrAppend:trapMethod. |
660 | 2684 |
flushCaches ifTrue:[ |
2685 |
newClass methodDictionary:dict. |
|
2686 |
] ifFalse:[ |
|
2687 |
newClass setMethodDictionary:dict. |
|
2688 |
]. |
|
8 | 2689 |
|
2690 |
" |
|
2691 |
and finally, the big trick: |
|
2692 |
" |
|
660 | 2693 |
newClass ~~ orgClass ifTrue:[ |
2694 |
anObject changeClassTo:newClass |
|
2695 |
]. |
|
8 | 2696 |
|
2697 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2698 |
[exBegin] |
8 | 2699 |
|p| |
2700 |
||
2701 |
p := Point new copy. |
|
2702 |
MessageTracer |
|
256 | 2703 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2704 |
selector:#y: |
256 | 2705 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2706 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2707 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 2708 |
Transcript showCR:retVal printString. |
2709 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2710 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2711 |
withOriginalClass:true. |
256 | 2712 |
Transcript showCR:'sending x: ...'. |
8 | 2713 |
p x:1. |
256 | 2714 |
Transcript showCR:'sending y: ...'. |
8 | 2715 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2716 |
MessageTracer untrap:p. |
256 | 2717 |
Transcript showCR:'sending x: ...'. |
8 | 2718 |
p x:2. |
256 | 2719 |
Transcript showCR:'sending y: ...'. |
8 | 2720 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2721 |
[exEnd] |
8 | 2722 |
" |
2723 |
||
2724 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2725 |
[exBegin] |
8 | 2726 |
|p| |
2727 |
||
2728 |
p := Point new copy. |
|
2729 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2730 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2731 |
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
|
2732 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2733 |
withOriginalClass:false. |
256 | 2734 |
Transcript showCR:'sending x: ...'. |
8 | 2735 |
p x:1. |
256 | 2736 |
Transcript showCR:'sending y: ...'. |
8 | 2737 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2738 |
MessageTracer untrap:p. |
256 | 2739 |
Transcript showCR:'sending x: ...'. |
8 | 2740 |
p x:2. |
256 | 2741 |
Transcript showCR:'sending y: ...'. |
8 | 2742 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2743 |
[exEnd] |
8 | 2744 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
2745 |
|
2396 | 2746 |
"Modified: / 25-06-1996 / 22:11:21 / stefan" |
2747 |
"Created: / 21-04-1998 / 15:30:27 / cg" |
|
8 | 2748 |
! |
2749 |
||
993
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2750 |
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
|
2751 |
"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
|
2752 |
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
|
2753 |
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
|
2754 |
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
|
2755 |
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
|
2756 |
before the wrapped method will be called. |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2757 |
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
|
2758 |
|
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2759 |
^ self |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2760 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2761 |
additionalEntryCode:nil additionalExitCode:nil additionalVariables:nil |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2762 |
withOriginalClass:withOriginalClass flushCaches:flushCaches |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2763 |
! |
ebcbcdd21e05
experimental instVar-written traps
Claus Gittinger <cg@exept.de>
parents:
972
diff
changeset
|
2764 |
|
88 | 2765 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
2766 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 2767 |
|
88 | 2768 |
aCollection do:[:aSelector | |
660 | 2769 |
self |
2770 |
wrap:anObject selector:aSelector |
|
2771 |
onEntry:entryBlock onExit:exitBlock |
|
2772 |
withOriginalClass:true |
|
2773 |
flushCaches:false |
|
2774 |
]. |
|
2775 |
ObjectMemory flushCaches |
|
2776 |
||
2777 |
"Modified: / 21.4.1998 / 15:40:28 / cg" |
|
8 | 2778 |
! |
2779 |
||
88 | 2780 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
2781 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 2782 |
|
2783 |
|allSelectors| |
|
2784 |
||
2785 |
allSelectors := IdentitySet new. |
|
972 | 2786 |
anObject class withAllSuperclassesDo:[:aClass | |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2787 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 2788 |
]. |
88 | 2789 |
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
|
2790 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2791 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 2792 |
! ! |
2793 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2794 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2795 |
|
1369 | 2796 |
allWrappedMethods |
3130 | 2797 |
^ Smalltalk allMethodsForWhich:[:mthd | mthd isWrapped] |
1369 | 2798 |
! |
2799 |
||
2800 |
areAnyMethodsWrapped |
|
1472
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2801 |
Smalltalk allMethodsDo:[:mthd | |
6bf86c3d084e
code cleanup: use new Smalltalk>>allMethodsDo:
Claus Gittinger <cg@exept.de>
parents:
1452
diff
changeset
|
2802 |
mthd isWrapped ifTrue:[ ^ true ] |
1369 | 2803 |
]. |
2804 |
^ false |
|
2805 |
! |
|
2806 |
||
579 | 2807 |
isCounting:aMethod |
2808 |
"return true if aMethod is counted" |
|
2809 |
||
3308 | 2810 |
MethodCounts notNil ifTrue:[ |
2811 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
2812 |
aMethod isWrapped ifTrue:[ |
|
2813 |
(MethodCounts includesKey:aMethod originalMethod)ifTrue:[^ true]. |
|
2814 |
]. |
|
2815 |
]. |
|
2816 |
MethodCountsPerReceiverClass notNil ifTrue:[ |
|
2817 |
(MethodCountsPerReceiverClass includesKey:aMethod) ifTrue:[^ true]. |
|
2818 |
aMethod isWrapped ifTrue:[ |
|
2819 |
(MethodCountsPerReceiverClass includesKey:aMethod originalMethod)ifTrue:[^ true]. |
|
2820 |
]. |
|
579 | 2821 |
]. |
2822 |
^ false |
|
2823 |
||
2824 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
2825 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2826 |
! |
|
2827 |
||
3308 | 2828 |
isCountingByReceiverClass:aMethod |
2829 |
"return true if aMethod is counted with per receiver class statistics" |
|
2830 |
||
2831 |
MethodCountsPerReceiverClass isNil ifTrue:[^ false]. |
|
2832 |
(MethodCountsPerReceiverClass includesKey:aMethod) ifTrue:[^ true]. |
|
2833 |
aMethod isWrapped ifTrue:[ |
|
2834 |
^ MethodCountsPerReceiverClass includesKey:aMethod originalMethod |
|
2835 |
]. |
|
2836 |
^ false |
|
2837 |
! |
|
2838 |
||
579 | 2839 |
isTiming:aMethod |
2840 |
"return true if aMethod is timed" |
|
2841 |
||
2842 |
MethodTiming isNil ifTrue:[^ false]. |
|
2843 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
2844 |
aMethod isWrapped ifTrue:[ |
|
2845 |
^ MethodTiming includesKey:aMethod originalMethod |
|
2846 |
]. |
|
2847 |
^ false |
|
2848 |
||
2849 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2850 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
2851 |
! |
|
2852 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2853 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2854 |
"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
|
2855 |
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
|
2856 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2857 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2858 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2859 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2860 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2861 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2862 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2863 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2864 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2865 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2866 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2867 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2868 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2869 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2870 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2871 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 2872 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2873 |
dummyEmptyMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2874 |
"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
|
2875 |
a dummy method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2876 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2877 |
"Created: / 30.7.1998 / 16:58:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2878 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2879 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2880 |
getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2881 |
"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
|
2882 |
a timed method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2883 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2884 |
|m times| |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2885 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2886 |
TimeForWrappers := 0. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2887 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2888 |
"/ wrap the dummy method ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2889 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2890 |
m := self class compiledMethodAt:#dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2891 |
m := self timeMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2892 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2893 |
"/ invoke it a few times ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2894 |
"/ (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
|
2895 |
"/ depends on whether there is already some statistic data) |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2896 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2897 |
10 timesRepeat:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2898 |
self dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2899 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2900 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2901 |
"/ fetch min time & unwrap |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2902 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2903 |
times := self executionTimesOfMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2904 |
self stopTimingMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2905 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
2906 |
^ (TimeForWrappers := times avgTime) |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2907 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2908 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2909 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2910 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2911 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
2912 |
"Modified: / 05-03-2007 / 15:44:24 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2913 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2914 |
|
88 | 2915 |
printEntryFull:aContext |
664 | 2916 |
self printEntryFull:aContext level:0 on:Stderr |
88 | 2917 |
! |
27 | 2918 |
|
88 | 2919 |
printEntryFull:aContext level:lvl |
664 | 2920 |
self printEntryFull:aContext level:lvl on:Stderr |
2921 |
! |
|
2922 |
||
2923 |
printEntryFull:aContext level:lvl on:aStream |
|
2924 |
aStream |
|
2925 |
spaces:lvl; |
|
734 | 2926 |
nextPutAll:'enter '. |
2927 |
self printFull:aContext on:aStream withSender:true. |
|
88 | 2928 |
! |
27 | 2929 |
|
664 | 2930 |
printEntryFull:aContext on:aStream |
2931 |
self printEntryFull:aContext level:0 on:aStream |
|
2932 |
! |
|
2933 |
||
2934 |
printEntrySender:aContext on:aStream |
|
2935 |
|sender mClass mClassName| |
|
2936 |
||
2937 |
mClass := aContext methodClass. |
|
2938 |
mClass isNil ifTrue:[ |
|
2939 |
mClassName := '???' |
|
2940 |
] ifFalse:[ |
|
2941 |
mClassName := mClass name |
|
2942 |
]. |
|
734 | 2943 |
|
664 | 2944 |
aStream |
2945 |
nextPutAll:mClassName; |
|
2946 |
space; |
|
665 | 2947 |
bold; |
664 | 2948 |
nextPutAll:aContext selector; |
665 | 2949 |
normal; |
664 | 2950 |
nextPutAll:' from '. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2951 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2952 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2953 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2954 |
(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
|
2955 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2956 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2957 |
]. |
664 | 2958 |
sender printOn:aStream. |
666 | 2959 |
aStream cr; flush. |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2960 |
|
695 | 2961 |
"Modified: / 30.7.1998 / 20:40:14 / cg" |
88 | 2962 |
! |
2963 |
||
2964 |
printExit:aContext with:retVal |
|
664 | 2965 |
self printExit:aContext with:retVal level:0 on:Stderr |
27 | 2966 |
! |
2967 |
||
88 | 2968 |
printExit:aContext with:retVal level:lvl |
664 | 2969 |
self printExit:aContext with:retVal level:lvl on:Stderr |
2970 |
! |
|
2971 |
||
2972 |
printExit:aContext with:retVal level:lvl on:aStream |
|
2973 |
|mClass mClassName| |
|
2974 |
||
2975 |
mClass := aContext methodClass. |
|
2976 |
mClass isNil ifTrue:[ |
|
2977 |
mClassName := '???' |
|
2978 |
] ifFalse:[ |
|
2979 |
mClassName := mClass name |
|
2980 |
]. |
|
2981 |
aStream |
|
2982 |
spaces:lvl; |
|
2983 |
nextPutAll:'leave '; |
|
2984 |
nextPutAll:mClassName; |
|
2985 |
space; |
|
665 | 2986 |
bold; |
664 | 2987 |
nextPutAll:aContext selector; |
665 | 2988 |
normal; |
666 | 2989 |
nextPutAll:' rec=['. |
664 | 2990 |
|
1486
d7ae9a86ea38
print same receiver on entry and exit
Stefan Vogel <sv@exept.de>
parents:
1472
diff
changeset
|
2991 |
self printObject:aContext receiver on:aStream. |
666 | 2992 |
aStream nextPutAll:'] return: ['. |
664 | 2993 |
retVal printOn:aStream. |
666 | 2994 |
aStream nextPutAll:']'; cr; flush. |
664 | 2995 |
! |
2996 |
||
2997 |
printExit:aContext with:retVal on:aStream |
|
2998 |
self printExit:aContext with:retVal level:0 on:aStream |
|
2999 |
! |
|
3000 |
||
734 | 3001 |
printFull:aContext on:aStream withSender:withSender |
1071 | 3002 |
self |
3003 |
printFull:aContext on:aStream |
|
3004 |
withSenderContext:(withSender ifTrue:[aContext sender] |
|
3005 |
ifFalse:[nil]) |
|
3006 |
! |
|
3007 |
||
3008 |
printFull:aContext on:aStream withSenderContext:aSenderContextOrNil |
|
3009 |
|mClass mClassName| |
|
734 | 3010 |
|
3011 |
mClass := aContext methodClass. |
|
3012 |
mClass isNil ifTrue:[ |
|
3013 |
mClassName := '???' |
|
3014 |
] ifFalse:[ |
|
3015 |
mClassName := mClass name |
|
3016 |
]. |
|
3017 |
||
3018 |
aStream |
|
3019 |
nextPutAll:mClassName; |
|
3020 |
space; |
|
3021 |
bold; |
|
3022 |
nextPutAll:aContext selector; |
|
3023 |
normal; |
|
3024 |
nextPutAll:' rec=['. |
|
3025 |
||
735 | 3026 |
self printObject:aContext receiver on:aStream. |
3027 |
||
734 | 3028 |
aStream nextPutAll:'] '. |
3029 |
(aContext args) keysAndValuesDo:[:idx :arg | |
|
3030 |
aStream nextPutAll:'arg'. idx printOn:aStream. aStream nextPutAll:'=['. |
|
735 | 3031 |
self printObject:arg on:aStream. |
734 | 3032 |
aStream nextPutAll:'] '. |
3033 |
]. |
|
3034 |
||
1071 | 3035 |
aSenderContextOrNil notNil ifTrue:[ |
3036 |
self printSender:aSenderContextOrNil on:aStream. |
|
734 | 3037 |
]. |
3038 |
aStream cr; flush. |
|
3039 |
! |
|
3040 |
||
735 | 3041 |
printObject:anObject on:aStream |
3042 |
|s| |
|
3043 |
||
3044 |
s := anObject printString. |
|
2085
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
3045 |
s size > 40 ifTrue:[ |
21d40e42e3fa
Better traces of object printStrings
Stefan Vogel <sv@exept.de>
parents:
2004
diff
changeset
|
3046 |
s := s chopTo:40. |
735 | 3047 |
]. |
3048 |
aStream nextPutAll:s |
|
3049 |
! |
|
3050 |
||
1071 | 3051 |
printSender:aSenderContext on:aStream |
3052 |
|sender| |
|
3053 |
||
3054 |
sender := aSenderContext. |
|
3055 |
sender notNil ifTrue:[ |
|
3056 |
(sender selector startsWith:'perform:') ifTrue:[ |
|
3057 |
sender := sender sender. |
|
3058 |
]. |
|
3059 |
]. |
|
3060 |
aStream nextPutAll:'from:'. |
|
3061 |
aStream bold. |
|
3062 |
sender printOn:aStream. |
|
3063 |
aStream normal. |
|
3064 |
! |
|
3065 |
||
3066 |
printUpdateEntryFull:aContext level:lvl on:aStream |
|
3175 | 3067 |
|con sndr| |
1071 | 3068 |
|
3069 |
con := aContext. |
|
3070 |
||
3173 | 3071 |
"/ [ |
3175 | 3072 |
"/ con notNil and:[con selector ~~ #'changed:with:'] |
3173 | 3073 |
"/ ] whileTrue:[ |
3074 |
"/ con := con sender. |
|
3075 |
"/ ]. |
|
3076 |
con := con findNextContextWithSelector:#'changed:with:' or:nil or:nil. |
|
3077 |
||
1071 | 3078 |
con isNil ifTrue:[ |
3175 | 3079 |
^ self printEntryFull:aContext level:lvl on:aStream. |
1071 | 3080 |
]. |
3081 |
||
3173 | 3082 |
"/ con is #'changed:with:' |
3175 | 3083 |
((sndr := con sender) notNil |
3084 |
and:[ sndr selector == #'changed:']) ifTrue:[ |
|
3085 |
con := sndr. |
|
1071 | 3086 |
]. |
3175 | 3087 |
((sndr := con sender) notNil |
3088 |
and:[ sndr selector == #'changed']) ifTrue:[ |
|
3089 |
con := sndr. |
|
1071 | 3090 |
]. |
3175 | 3091 |
((sndr := con sender) notNil) ifTrue:[ |
3092 |
con := sndr. |
|
1071 | 3093 |
]. |
3094 |
||
3095 |
aStream spaces:lvl; nextPutAll:'enter '. |
|
3096 |
self |
|
3175 | 3097 |
printFull:aContext |
3098 |
on:aStream |
|
3099 |
withSenderContext:con |
|
1071 | 3100 |
! |
3101 |
||
697 | 3102 |
traceEntryFull:aContext on:aStream |
3103 |
aStream nextPutLine:'-----------------------------------------'. |
|
3104 |
aContext fullPrintAllOn:aStream |
|
3105 |
||
3106 |
"Created: / 30.7.1998 / 20:39:57 / cg" |
|
3107 |
"Modified: / 30.7.1998 / 20:42:23 / cg" |
|
3108 |
! |
|
3109 |
||
664 | 3110 |
traceFullBlockFor:aStream |
3111 |
"avoid generation of fullBlocks" |
|
3112 |
||
3113 |
aStream == Transcript ifTrue:[ |
|
3114 |
^ TraceFullBlock2 |
|
3115 |
]. |
|
3116 |
aStream == Stderr ifTrue:[ |
|
3117 |
^ TraceFullBlock |
|
3118 |
]. |
|
3119 |
^ [:con | con fullPrintAllOn:aStream] |
|
3120 |
||
3121 |
||
3122 |
||
3123 |
! |
|
3124 |
||
3125 |
traceSenderBlockFor:aStream |
|
3126 |
"avoid generation of fullBlocks" |
|
3127 |
||
3128 |
aStream == Transcript ifTrue:[ |
|
3129 |
^ TraceSenderBlock2 |
|
3130 |
]. |
|
3131 |
aStream == Stderr ifTrue:[ |
|
3132 |
^ TraceSenderBlock |
|
3133 |
]. |
|
3134 |
^ [:con | MessageTracer printEntrySender:con on:aStream] |
|
3135 |
||
3136 |
||
3137 |
||
88 | 3138 |
! ! |
13 | 3139 |
|
1082 | 3140 |
!MessageTracer methodsFor:'trace helpers'! |
88 | 3141 |
|
3142 |
trace:aBlock detail:fullDetail |
|
3143 |
"trace execution of aBlock." |
|
3144 |
||
3145 |
traceDetail := fullDetail. |
|
735 | 3146 |
tracedBlock := aBlock. |
3147 |
||
88 | 3148 |
ObjectMemory stepInterruptHandler:self. |
3149 |
^ [ |
|
735 | 3150 |
ObjectMemory flushInlineCaches. |
3151 |
StepInterruptPending := 1. |
|
3152 |
InterruptPending := 1. |
|
3153 |
aBlock value |
|
1139
56861678ff27
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
1082
diff
changeset
|
3154 |
] ensure:[ |
735 | 3155 |
tracedBlock := nil. |
3156 |
StepInterruptPending := nil. |
|
3157 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 3158 |
] |
3159 |
||
3160 |
" |
|
735 | 3161 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:false |
3162 |
||
3163 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3164 |
||
3165 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3166 |
||
3167 |
PrintingMessageTracer new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
8 | 3168 |
" |
3169 |
! ! |
|
27 | 3170 |
|
1082 | 3171 |
!MessageTracer::InteractionCollector methodsFor:'trace helpers'! |
1008
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3172 |
|
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3173 |
stepInterrupt |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3174 |
StepInterruptPending := nil. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3175 |
ObjectMemory flushInlineCaches. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3176 |
StepInterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3177 |
InterruptPending := 1. |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3178 |
! ! |
19836654299a
Smalltalk change-notifications (in addition-for now)
Claus Gittinger <cg@exept.de>
parents:
993
diff
changeset
|
3179 |
|
1957
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3180 |
!MessageTracer::MethodTimingInfo methodsFor:'accessing'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3181 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3182 |
avgTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3183 |
sumTimes notNil ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3184 |
^ sumTimes / count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3185 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3186 |
^ nil |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3187 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3188 |
"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
|
3189 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3190 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3191 |
avgTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3192 |
|avg| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3193 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3194 |
avg := self avgTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3195 |
avg > 100 ifTrue:[ ^ avg roundTo:1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3196 |
avg > 10 ifTrue:[ ^ avg roundTo:0.1 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3197 |
avg > 1 ifTrue:[ ^ avg roundTo:0.01 ]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3198 |
^ avg roundTo:0.001 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3199 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3200 |
"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
|
3201 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3202 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3203 |
count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3204 |
^ count |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3205 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3206 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3207 |
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
|
3208 |
count := countArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3209 |
minTime := minTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3210 |
maxTime := maxTimeArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3211 |
sumTimes := sumTimesArg. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3212 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3213 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3214 |
maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3215 |
^ maxTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3216 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3217 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3218 |
maxTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3219 |
|max| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3220 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3221 |
max := self maxTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3222 |
^ 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
|
3223 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3224 |
"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
|
3225 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3226 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3227 |
minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3228 |
^ minTime |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3229 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3230 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3231 |
minTimeRounded |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3232 |
|min| |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3233 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3234 |
min := self minTime. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3235 |
^ 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
|
3236 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3237 |
"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
|
3238 |
! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3239 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3240 |
sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3241 |
^ sumTimes |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3242 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3243 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3244 |
!MessageTracer::MethodTimingInfo methodsFor:'initialization'! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3245 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3246 |
rememberExecutionTime:t |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3247 |
(count isNil or:[count == 0]) ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3248 |
minTime := maxTime := sumTimes := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3249 |
count := 1. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3250 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3251 |
t < minTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3252 |
minTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3253 |
] ifFalse:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3254 |
t > maxTime ifTrue:[ |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3255 |
maxTime := t. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3256 |
] |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3257 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3258 |
sumTimes := (sumTimes + t). |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3259 |
count := count + 1 |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3260 |
]. |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3261 |
|
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3262 |
"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
|
3263 |
! ! |
79be76350837
dont use anon-arrays to represent info
Claus Gittinger <cg@exept.de>
parents:
1486
diff
changeset
|
3264 |
|
2972 | 3265 |
!MessageTracer::PrintingMessageTracer methodsFor:'accessing'! |
3266 |
||
3267 |
output:something |
|
3268 |
output := something. |
|
3269 |
! ! |
|
3270 |
||
1082 | 3271 |
!MessageTracer::PrintingMessageTracer methodsFor:'trace helpers'! |
734 | 3272 |
|
3273 |
stepInterrupt |
|
3274 |
"called for every send while tracing" |
|
3275 |
||
3258 | 3276 |
|ignore sel con r outStream senderContext| |
734 | 3277 |
|
3278 |
StepInterruptPending := nil. |
|
3258 | 3279 |
con := senderContext := thisContext sender. |
734 | 3280 |
ignore := false. |
2972 | 3281 |
outStream := output ? Stderr. |
734 | 3282 |
|
3283 |
con receiver == Processor ifTrue:[ |
|
3284 |
(sel := con selector) == #threadSwitch: ifTrue:[ |
|
3285 |
ignore := true. |
|
3286 |
]. |
|
3287 |
sel == #timerInterrupt ifTrue:[ |
|
3288 |
ignore := true. |
|
3289 |
] |
|
3290 |
]. |
|
3291 |
||
3292 |
con lineNumber == 1 ifFalse:[ |
|
3293 |
ignore := true |
|
3294 |
]. |
|
3295 |
||
3296 |
ignore ifFalse:[ |
|
3297 |
con markForInterruptOnUnwind. |
|
3298 |
||
3299 |
((r := con receiver) ~~ self |
|
3300 |
and:[r ~~ tracedBlock]) ifTrue:[ |
|
3301 |
traceDetail == #fullIndent ifTrue:[ |
|
3302 |
[con notNil |
|
3303 |
and:[(r := con receiver) ~~ self |
|
3304 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
2972 | 3305 |
' ' printOn:outStream. |
734 | 3306 |
con := con sender. |
3307 |
]. |
|
3258 | 3308 |
con := senderContext. |
2972 | 3309 |
self class printFull:con on:outStream withSender:false. |
734 | 3310 |
] ifFalse:[ |
3311 |
traceDetail == #indent ifTrue:[ |
|
3312 |
[con notNil |
|
3313 |
and:[(r := con receiver) ~~ self |
|
3314 |
and:[r ~~ tracedBlock]]] whileTrue:[ |
|
2972 | 3315 |
' ' printOn:outStream. |
734 | 3316 |
con := con sender. |
3317 |
]. |
|
3258 | 3318 |
con := senderContext. |
2972 | 3319 |
con printOn:outStream. |
3320 |
outStream cr. |
|
734 | 3321 |
] ifFalse:[ |
3322 |
traceDetail == true ifTrue:[ |
|
2972 | 3323 |
self class printFull:con on:outStream withSender:true. |
734 | 3324 |
] ifFalse:[ |
2972 | 3325 |
con printOn:outStream. |
3326 |
outStream cr. |
|
734 | 3327 |
] |
3328 |
] |
|
3329 |
]. |
|
3330 |
]. |
|
3331 |
]. |
|
3332 |
||
3333 |
ObjectMemory flushInlineCaches. |
|
3334 |
StepInterruptPending := 1. |
|
3335 |
InterruptPending := 1. |
|
3336 |
||
3337 |
" |
|
3338 |
self new trace:[#(6 5 4 3 2 1) sort] detail:false |
|
3339 |
||
3340 |
self new trace:[#(6 5 4 3 2 1) sort] detail:true |
|
3341 |
||
3342 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#indent |
|
3343 |
||
3344 |
self new trace:[#(6 5 4 3 2 1) sort] detail:#fullIndent |
|
3345 |
self new trace:[ View new ] detail:#fullIndent |
|
3346 |
" |
|
3347 |
! ! |
|
3348 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
3349 |
!MessageTracer class methodsFor:'documentation'! |
98 | 3350 |
|
2243
886bcbcd310e
comment/format in: #trapMethod:
Claus Gittinger <cg@exept.de>
parents:
2085
diff
changeset
|
3351 |
version_CVS |
3326 | 3352 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.125 2013-06-30 08:11:02 cg Exp $' |
98 | 3353 |
! ! |
1320
f346fa1fdb3a
class category: sends a change notification;
Claus Gittinger <cg@exept.de>
parents:
1145
diff
changeset
|
3354 |
|
3130 | 3355 |
|
27 | 3356 |
MessageTracer initialize! |