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