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