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