author | Claus Gittinger <cg@exept.de> |
Fri, 31 Jul 1998 00:39:58 +0200 | |
changeset 697 | 062ee48ece19 |
parent 696 | d754acb87c1b |
child 698 | 7761fb1646ee |
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 |
" |
|
12 |
||
120 | 13 |
Object subclass:#MessageTracer |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
14 |
instanceVariableNames:'traceDetail' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
15 |
classVariableNames:'BreakpointSignal CallingLevel BreakBlock TraceSenderBlock |
664 | 16 |
TraceSenderBlock2 LeaveBreakBlock LeaveTraceBlock MethodCounts |
17 |
MethodMemoryUsage MethodTiming TraceFullBlock TraceFullBlock2 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
18 |
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
|
19 |
poolDictionaries:'' |
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
20 |
category:'System-Debugging-Support' |
8 | 21 |
! |
22 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
23 |
!MessageTracer class methodsFor:'documentation'! |
8 | 24 |
|
9 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
11 | 28 |
All Rights Reserved |
9 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
8 | 39 |
documentation |
40 |
" |
|
11 | 41 |
This class provides a common home for the tracing |
42 |
facilities (originally, they where in Object, but have been moved to |
|
8 | 43 |
allow easier separation of development vs. runtime configurations. |
44 |
||
11 | 45 |
tracing execution of a block: |
46 |
||
236 | 47 |
MessageTracer trace:[ ... ] |
11 | 48 |
|
236 | 49 |
MessageTracer traceFull:[ ... ] |
11 | 50 |
|
236 | 51 |
(for system developper only:) |
11 | 52 |
|
236 | 53 |
MessageTracer debugTrace:[ ... ] |
11 | 54 |
|
55 |
||
8 | 56 |
trapping sends to a specific object: |
57 |
||
236 | 58 |
MessageTracer trap:anObject selector:aSelector |
59 |
... |
|
60 |
MessageTracer untrap:anObject selector:aSelector |
|
61 |
or: |
|
62 |
MessageTracer untrap:anObject |
|
11 | 63 |
|
8 | 64 |
|
65 |
||
27 | 66 |
trapping some messages sent to a specific object: |
67 |
||
236 | 68 |
MessageTracer trap:anObject selectors:aCollectionOfSelectors |
69 |
... |
|
70 |
MessageTracer untrap:anObject |
|
27 | 71 |
|
72 |
||
73 |
||
74 |
trapping any message sent to a specific object: |
|
75 |
||
236 | 76 |
MessageTracer trapAll:anObject |
77 |
... |
|
78 |
MessageTracer untrap:anObject |
|
27 | 79 |
|
80 |
||
81 |
||
8 | 82 |
trapping evaluation of a specific method: |
83 |
||
236 | 84 |
MessageTracer trapMethod:aMethod |
85 |
... |
|
86 |
MessageTracer unwrapMethod:aMethod |
|
8 | 87 |
|
88 |
||
89 |
||
12 | 90 |
trapping evaluation of a specific method with |
91 |
receiver being an instance of some class: |
|
92 |
||
236 | 93 |
MessageTracer trapMethod:aMethod forInstancesOf:aClass |
94 |
... |
|
95 |
MessageTracer unwrapMethod:aMethod |
|
12 | 96 |
|
97 |
||
98 |
||
8 | 99 |
tracing sends to a specific object: |
100 |
||
236 | 101 |
MessageTracer trace:anObject selector:aSelector |
102 |
... |
|
103 |
MessageTracer untrace:anObject selector:aSelector |
|
104 |
or: |
|
105 |
MessageTracer untrace:anObject |
|
11 | 106 |
|
8 | 107 |
|
108 |
||
109 |
tracing sender only: |
|
110 |
||
236 | 111 |
MessageTracer traceSender:anObject selector:aSelector |
112 |
... |
|
113 |
MessageTracer untrace:anObject selector:aSelector |
|
114 |
or: |
|
115 |
MessageTracer untrace:anObject |
|
11 | 116 |
|
8 | 117 |
|
118 |
||
119 |
tracing evaluation of a specific method: |
|
120 |
||
236 | 121 |
MessageTracer traceMethod:aMethod |
122 |
... |
|
123 |
MessageTracer unwrapmethod:aMethod |
|
18 | 124 |
|
125 |
see more in examples and in method comments. |
|
236 | 126 |
|
127 |
[author:] |
|
128 |
Claus Gittinger |
|
8 | 129 |
" |
12 | 130 |
! |
131 |
||
132 |
examples |
|
133 |
" |
|
134 |
For the common cases, you will find a menu entry in the SystemBrowser. |
|
135 |
Howeever, more special cases (especially with condition checks) can be |
|
136 |
set up by evaluating the lower level entries. |
|
137 |
||
138 |
||
139 |
trapping specific methods: |
|
140 |
(by class/selector): |
|
244 | 141 |
[exBegin] |
12 | 142 |
MessageTracer trapClass:Collection selector:#select:. |
591 | 143 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
144 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
145 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 146 |
MessageTracer untrapClass:Collection |
244 | 147 |
[exEnd] |
12 | 148 |
|
149 |
(by method): |
|
244 | 150 |
[exBegin] |
12 | 151 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
591 | 152 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
153 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
154 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
12 | 155 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
244 | 156 |
[exEnd] |
12 | 157 |
|
27 | 158 |
(by method & instance class): |
244 | 159 |
[exBegin] |
27 | 160 |
MessageTracer trapMethod:(SequenceableCollection compiledMethodAt:#select:) |
244 | 161 |
forInstancesOf:SortedCollection. |
591 | 162 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
163 |
(Array new:10) select:[:e | ]. 'not caught - not a SortedCollection'. |
|
164 |
OrderedCollection new select:[:e | ]. 'not caught - not a SortedCollection'. |
|
165 |
SortedCollection new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
27 | 166 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#select:). |
244 | 167 |
[exEnd] |
27 | 168 |
|
12 | 169 |
tracing specific methods: |
170 |
(by class/selector): |
|
244 | 171 |
[exBegin] |
12 | 172 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
173 |
#(6 1 9 66 2 17) copy sort. |
|
174 |
MessageTracer untraceClass:SequenceableCollection |
|
244 | 175 |
[exEnd] |
12 | 176 |
|
177 |
(by method): |
|
244 | 178 |
[exBegin] |
12 | 179 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
180 |
#(6 1 9 66 2 17) copy sort. |
|
181 |
MessageTracer unwrapMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
244 | 182 |
[exEnd] |
27 | 183 |
|
184 |
object trapping: |
|
244 | 185 |
[exBegin] |
27 | 186 |
|o| |
187 |
||
188 |
o := OrderedCollection new. |
|
189 |
MessageTracer trapAll:o. |
|
190 |
o collect:[:el | el]. |
|
244 | 191 |
[exEnd] |
661 | 192 |
|
193 |
trapping modifications to an objects instVars: |
|
194 |
[exBegin] |
|
195 |
|o| |
|
196 |
||
197 |
o := Point new. |
|
198 |
MessageTracer trapModificationsIn:o. |
|
199 |
o x:1. |
|
200 |
o y:2. |
|
201 |
o x:1. |
|
202 |
o y:2. |
|
203 |
MessageTracer untrap:o |
|
204 |
[exEnd] |
|
205 |
||
206 |
trapping modifications of a particular instVar: |
|
207 |
[exBegin] |
|
208 |
|o| |
|
209 |
||
210 |
o := Point new. |
|
211 |
MessageTracer trapModificationsIn:o filter:[:old :new | old x ~~ new x]. |
|
212 |
o x:1. |
|
213 |
o y:2. |
|
214 |
o x:1. |
|
215 |
o y:2. |
|
216 |
MessageTracer untrap:o |
|
217 |
[exEnd] |
|
12 | 218 |
" |
8 | 219 |
! ! |
220 |
||
664 | 221 |
!MessageTracer class methodsFor:'Signal constants'! |
222 |
||
223 |
breakpointSignal |
|
224 |
^ BreakpointSignal |
|
225 |
! |
|
226 |
||
227 |
objectWrittenBreakpointSignal |
|
228 |
^ ObjectWrittenBreakpointSignal |
|
229 |
||
230 |
"Created: / 21.4.1998 / 14:38:49 / cg" |
|
231 |
! ! |
|
232 |
||
233 |
!MessageTracer class methodsFor:'class initialization'! |
|
11 | 234 |
|
235 |
initialize |
|
236 |
BreakpointSignal isNil ifTrue:[ |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
237 |
BreakpointSignal := HaltSignal newSignalMayProceed:true. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
238 |
BreakpointSignal nameClass:self message:#breakpointSignal. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
239 |
BreakpointSignal notifierString:'breakpoint encountered'. |
27 | 240 |
|
660 | 241 |
ObjectWrittenBreakpointSignal := BreakpointSignal newSignalMayProceed:true. |
242 |
ObjectWrittenBreakpointSignal nameClass:self message:#objectWrittenBreakpointSignal. |
|
243 |
ObjectWrittenBreakpointSignal notifierString:'object modified'. |
|
244 |
||
695 | 245 |
"/ the following have been written as cheapBlocks (by purpose) |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
246 |
BreakBlock := [:con | BreakpointSignal raiseIn:con]. |
664 | 247 |
TraceSenderBlock := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Stderr) ]. |
248 |
TraceSenderBlock2 := [:con | MessageTracer printEntrySender:con on:(Smalltalk at:#Transcript) ]. |
|
695 | 249 |
TraceFullBlock := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Stderr) ]. |
250 |
TraceFullBlock2 := [:con | MessageTracer traceEntryFull:con on:(Smalltalk at:#Transcript) ]. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
251 |
LeaveBreakBlock := [:con :retVal | ]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
252 |
LeaveTraceBlock := [:con :retVal | ]. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
253 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
254 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
255 |
ObjectMemory addDependent:self. |
156 | 256 |
|
257 |
" |
|
258 |
BreakpointSignal := nil. |
|
259 |
MessageTracer initialize |
|
260 |
" |
|
261 |
||
695 | 262 |
"Modified: / 30.7.1998 / 20:41:29 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
263 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
264 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
265 |
update:something with:parameter from:changedObject |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
266 |
"sent when restarted after a snapIn" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
267 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
268 |
(something == #restarted) ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
269 |
TimeForWrappers := nil |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
270 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
271 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
272 |
"Created: / 30.7.1998 / 17:00:09 / cg" |
11 | 273 |
! ! |
274 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
275 |
!MessageTracer class methodsFor:'class tracing'! |
88 | 276 |
|
277 |
untraceAllClasses |
|
278 |
"remove all traces of messages sent to any class" |
|
279 |
||
280 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
281 |
trace facilities ..." |
|
282 |
||
283 |
^ self untrapAllClasses |
|
284 |
! |
|
285 |
||
286 |
untraceClass:aClass |
|
287 |
"remove all traces of messages sent to instances of aClass" |
|
288 |
||
289 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
290 |
trace facilities ..." |
|
291 |
||
292 |
^ self untrapClass:aClass |
|
293 |
! ! |
|
294 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
295 |
!MessageTracer class methodsFor:'class wrapping'! |
88 | 296 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
297 |
wrapClass:orgClass selector:aSelector onEntry:entryBlock onExit:exitBlock |
88 | 298 |
"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
|
299 |
aSelector is sent to instances of orgClass or subclasses. |
88 | 300 |
EntryBlock will be called on entry, and get the current context passed as argument. |
301 |
ExitBlock will be called, when the method is left, and get context and the methods return value as arguments. |
|
302 |
" |
|
303 |
||
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
304 |
|myMetaclass trapMethod s spec implClass newClass save dict| |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
305 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
306 |
WrappedMethod autoload. "/ just to make sure ... |
88 | 307 |
|
308 |
" |
|
309 |
create a new method, which calls the original one, |
|
310 |
but only if not already being trapped. |
|
311 |
" |
|
312 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
313 |
||
314 |
s := WriteStream on:String new. |
|
315 |
s nextPutAll:spec. |
|
316 |
s cr. |
|
317 |
s nextPutAll:'|retVal stubClass|'; cr. |
|
318 |
entryBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
319 |
s nextPutAll:'#literal1 yourself value:thisContext.'; cr. |
88 | 320 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
321 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a literal to be replaced by theoriginal method |
88 | 322 |
s nextPutAll:('retVal := super ' , spec , '.'); cr. |
323 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
324 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal.'; cr. |
88 | 325 |
]. |
326 |
s nextPutAll:'^ retVal'; cr. |
|
327 |
||
328 |
save := Compiler stcCompilation. |
|
329 |
Compiler stcCompilation:#never. |
|
330 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
331 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
332 |
trapMethod := Compiler compile:s contents |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
333 |
forClass:orgClass |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
334 |
inCategory:'trapping' |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
335 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
336 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
337 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
338 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
339 |
] |
88 | 340 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
341 |
Compiler stcCompilation:save |
88 | 342 |
]. |
343 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
344 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
345 |
implClass isNil ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
346 |
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
|
347 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
348 |
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
|
349 |
]. |
88 | 350 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
351 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
88 | 352 |
]. |
353 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
354 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
88 | 355 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
356 |
|
88 | 357 |
" |
358 |
change the source of this new method |
|
359 |
(to avoid confusion in the debugger ...) |
|
360 |
" |
|
361 |
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
|
362 |
trapMethod changeClassTo:WrappedMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
363 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
364 |
dict := orgClass methodDictionary. |
88 | 365 |
|
366 |
" |
|
367 |
if not already trapping, create a new class |
|
368 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
369 |
orgClass category == #'* trapping *' ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
370 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
371 |
orgClass methodDictionary:dict. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
372 |
newClass := orgClass superclass. |
88 | 373 |
] ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
374 |
myMetaclass := orgClass class. |
88 | 375 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
376 |
newClass := myMetaclass copy new. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
377 |
newClass setSuperclass:orgClass superclass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
378 |
newClass instSize:orgClass instSize. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
379 |
newClass flags:orgClass flags. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
380 |
newClass setClassVariableString:orgClass classVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
381 |
newClass setInstanceVariableString:orgClass instanceVariableString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
382 |
newClass setName:orgClass name. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
383 |
newClass category:orgClass category. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
384 |
newClass methodDictionary:dict. |
88 | 385 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
386 |
orgClass setSuperclass:newClass. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
387 |
orgClass setClassVariableString:''. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
388 |
orgClass setInstanceVariableString:''. |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
389 |
orgClass category:#'* trapping *'. |
88 | 390 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
391 |
dict := MethodDictionary new:1. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
392 |
dict at:aSelector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
393 |
orgClass methodDictionary:dict. |
88 | 394 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
395 |
trapMethod changeLiteral:(newClass superclass) to:newClass. |
88 | 396 |
|
397 |
ObjectMemory flushCaches. |
|
398 |
||
399 |
" |
|
400 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
401 |
wrapClass:Point |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
402 |
selector:#scaleBy: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
403 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
404 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
405 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
406 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
407 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
408 |
]. |
88 | 409 |
(1@2) scaleBy:5. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
410 |
MessageTracer untrapClass:Point selector:#scaleBy:. |
88 | 411 |
(1@2) scaleBy:5. |
412 |
" |
|
413 |
" |
|
414 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
415 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
416 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
417 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
418 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
419 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
420 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
421 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
422 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
423 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
424 |
]. |
258 | 425 |
Transcript showCR:'5 factorial traced'. |
88 | 426 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
427 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 428 |
Transcript showCR:'5 factorial normal'. |
88 | 429 |
5 factorial. |
430 |
" |
|
431 |
" |
|
432 |
|lvl| |
|
433 |
||
434 |
lvl := 0. |
|
435 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
436 |
wrapClass:Integer |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
437 |
selector:#factorial |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
438 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
439 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
440 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
441 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
442 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
443 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
444 |
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
|
445 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
446 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
447 |
]. |
258 | 448 |
Transcript showCR:'5 factorial traced'. |
88 | 449 |
5 factorial. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
450 |
MessageTracer untrapClass:Integer selector:#factorial. |
258 | 451 |
Transcript showCR:'5 factorial normal'. |
88 | 452 |
5 factorial. |
453 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
454 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
455 |
"Modified: 25.6.1996 / 22:01:05 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
456 |
"Modified: 10.9.1996 / 20:07:01 / cg" |
88 | 457 |
! ! |
458 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
459 |
!MessageTracer class methodsFor:'cleanup'! |
27 | 460 |
|
461 |
cleanup |
|
462 |
"if you forgot which classes/methods where wrapped and/or trapped, |
|
463 |
this cleans up everything ..." |
|
464 |
||
465 |
self untrapAllClasses. |
|
466 |
self unwrapAllMethods |
|
467 |
||
468 |
" |
|
469 |
MessageTracer cleanup |
|
470 |
" |
|
471 |
! ! |
|
472 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
473 |
!MessageTracer class methodsFor:'execution trace '! |
88 | 474 |
|
475 |
debugTrace:aBlock |
|
476 |
"trace execution of aBlock. This is for system debugging only" |
|
11 | 477 |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
478 |
Smalltalk sendTraceOn. |
88 | 479 |
^ aBlock valueNowOrOnUnwindDo:[ |
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
480 |
Smalltalk sendTraceOff. |
88 | 481 |
] |
11 | 482 |
|
88 | 483 |
" |
484 |
MessageTracer debugTrace:[#(6 5 4 3 2 1) sort] |
|
485 |
" |
|
196
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
486 |
|
330cc5c849de
debugOn/Off is now called sendTraceOn/Off
Claus Gittinger <cg@exept.de>
parents:
172
diff
changeset
|
487 |
"Modified: 18.3.1996 / 19:49:36 / cg" |
88 | 488 |
! |
11 | 489 |
|
490 |
trace:aBlock |
|
491 |
"evaluate aBlock sending trace information to stdout. |
|
27 | 492 |
Return the value of the block." |
11 | 493 |
|
17 | 494 |
^ self new trace:aBlock detail:false. |
11 | 495 |
|
496 |
" |
|
497 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] |
|
498 |
" |
|
499 |
! |
|
500 |
||
501 |
traceFull:aBlock |
|
502 |
"evaluate aBlock sending trace information to stdout. |
|
503 |
Return the value of the block. |
|
27 | 504 |
The trace information is more detailed." |
11 | 505 |
|
17 | 506 |
^ self new trace:aBlock detail:true. |
11 | 507 |
|
508 |
" |
|
509 |
MessageTracer traceFull:[#(6 5 4 3 2 1) sort] |
|
510 |
" |
|
88 | 511 |
! ! |
512 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
513 |
!MessageTracer class methodsFor:'method breakpointing'! |
88 | 514 |
|
515 |
trapClass:aClass selector:aSelector |
|
516 |
"arrange for the debugger to be entered when a message with aSelector is |
|
517 |
sent to instances of aClass (or subclass instances). Use untrapClass to remove this trap. |
|
518 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
519 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
520 |
entry/leave blocks." |
|
521 |
||
522 |
self trapMethod:(aClass compiledMethodAt:aSelector) |
|
523 |
||
524 |
" |
|
525 |
MessageTracer trapClass:Collection selector:#select:. |
|
591 | 526 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
527 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
528 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 529 |
MessageTracer untrapClass:Collection |
530 |
" |
|
11 | 531 |
! |
532 |
||
88 | 533 |
trapMethod:aMethod |
534 |
"arrange for the debugger to be entered when aMethod is about to be executed. |
|
495 | 535 |
The trap is enabled for any process - see #trapMethodInCurrentProcess: for a more |
536 |
selective breakPoint. |
|
88 | 537 |
Use unwrapMethod or untrapClass to remove this trap. |
538 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
539 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
540 |
entry/leave blocks." |
|
541 |
||
542 |
^ self wrapMethod:aMethod |
|
495 | 543 |
onEntry:BreakBlock |
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
544 |
onExit:LeaveBreakBlock. |
88 | 545 |
|
546 |
" |
|
547 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
|
591 | 548 |
Dictionary new select:[:e | ]. 'not caught - Dictionary has its own select'. |
549 |
(Array new:10) select:[:e | ]. 'not caught - SeqColl has its own select'. |
|
550 |
Set new select:[:e | ]. 'caught - Set inherits this from Collection'. |
|
88 | 551 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
552 |
" |
|
495 | 553 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
554 |
"Modified: 22.10.1996 / 17:39:58 / cg" |
88 | 555 |
! |
11 | 556 |
|
88 | 557 |
trapMethod:aMethod forInstancesOf:aClass |
558 |
"arrange for the debugger to be entered when aMethod is about to be executed |
|
559 |
for an instance of aClass. |
|
560 |
Use unwrapMethod or untrapClass to remove this trap. |
|
561 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
562 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
563 |
entry/leave blocks." |
|
564 |
||
565 |
^ self wrapMethod:aMethod |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
566 |
onEntry:[:context | |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
567 |
(context receiver isMemberOf:aClass) ifTrue:[ |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
568 |
BreakpointSignal raiseIn:context |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
569 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
570 |
] |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
571 |
onExit:LeaveBreakBlock. |
88 | 572 |
|
573 |
" |
|
574 |
MessageTracer trapMethod:(View compiledMethodAt:#redraw) forInstancesOf:myView. |
|
575 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
576 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
577 |
"Modified: 22.10.1996 / 17:40:03 / cg" |
88 | 578 |
! |
579 |
||
496 | 580 |
trapMethod:aMethod inProcess:aProcess |
495 | 581 |
"arrange for the debugger to be entered when aMethod is about to be executed, |
582 |
but only, if executed in the current process. |
|
583 |
This allows for breakpoints to be set on system-critical code. |
|
584 |
The trap is enabled for any process. |
|
585 |
Use unwrapMethod or untrapClass to remove this trap. |
|
586 |
Be careful, to not place a trap on code needed in the debugger (i.e. on scrollBars etc.); |
|
587 |
if there is a need to trap those, use the low-level wrap-methods, and put a check into the |
|
588 |
entry/leave blocks." |
|
589 |
||
590 |
^ self wrapMethod:aMethod |
|
496 | 591 |
onEntry:[:con | (Processor activeProcess == aProcess) |
495 | 592 |
ifTrue:[ |
593 |
BreakpointSignal raiseIn:con |
|
594 |
] |
|
595 |
] |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
596 |
onExit:LeaveBreakBlock. |
495 | 597 |
|
496 | 598 |
"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
|
599 |
"Modified: 22.10.1996 / 17:40:06 / cg" |
495 | 600 |
! |
601 |
||
88 | 602 |
untrapAllClasses |
603 |
"remove any traps on any class" |
|
604 |
||
605 |
Smalltalk allBehaviorsDo:[:aClass | |
|
606 |
self untrapClass:aClass |
|
11 | 607 |
] |
608 |
||
609 |
" |
|
88 | 610 |
MessageTracer untrapAllClasses |
611 |
" |
|
612 |
! |
|
613 |
||
614 |
untrapClass:aClass |
|
615 |
"remove any traps on aClass" |
|
616 |
||
617 |
"this is done by just patching the class back to the original" |
|
618 |
||
619 |
|orgClass| |
|
620 |
||
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
621 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
622 |
^ self |
88 | 623 |
]. |
624 |
orgClass := aClass superclass. |
|
625 |
||
626 |
aClass setSuperclass:orgClass superclass. |
|
627 |
aClass setClassVariableString:orgClass classVariableString. |
|
628 |
aClass setInstanceVariableString:orgClass instanceVariableString. |
|
629 |
aClass category:orgClass category. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
630 |
aClass methodDictionary:orgClass methodDictionary. |
88 | 631 |
|
632 |
ObjectMemory flushCaches. |
|
633 |
||
634 |
" |
|
635 |
MessageTracer untrapClass:Point |
|
11 | 636 |
" |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
637 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
638 |
"Modified: 5.6.1996 / 13:57:39 / stefan" |
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
639 |
"Modified: 10.9.1996 / 20:06:23 / cg" |
88 | 640 |
! |
641 |
||
642 |
untrapClass:aClass selector:aSelector |
|
643 |
"remove trap of aSelector sent to aClass" |
|
644 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
645 |
|dict| |
88 | 646 |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
647 |
aClass category == #'* trapping *' ifFalse:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
648 |
^ self |
88 | 649 |
]. |
650 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
651 |
dict := aClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
652 |
dict at:aSelector ifAbsent:[^ self]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
653 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
654 |
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
|
655 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
656 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
657 |
"the last trapped method" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
658 |
^ self untrapClass:aClass |
88 | 659 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
660 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
661 |
aClass methodDictionary:dict. |
88 | 662 |
|
663 |
" |
|
664 |
MessageTracer trapClass:Point selector:#copy. |
|
665 |
(1@2) copy. |
|
666 |
(1@2) deepCopy. |
|
667 |
MessageTracer trapClass:Point selector:#deepCopy. |
|
668 |
(1@2) copy. |
|
669 |
(1@2) deepCopy. |
|
670 |
MessageTracer untrapClass:Point selector:#copy. |
|
671 |
(1@2) copy. |
|
672 |
(1@2) deepCopy. |
|
673 |
MessageTracer untrapClass:Point selector:#deepCopy. |
|
674 |
(1@2) copy. |
|
675 |
(1@2) deepCopy. |
|
676 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
677 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
678 |
"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
|
679 |
"Modified: 10.9.1996 / 20:06:29 / cg" |
88 | 680 |
! |
681 |
||
682 |
untrapMethod:aMethod |
|
683 |
"remove break on aMethod" |
|
684 |
||
685 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
686 |
trace facilities ..." |
|
687 |
||
688 |
^ self unwrapMethod:aMethod |
|
11 | 689 |
! ! |
690 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
691 |
!MessageTracer class methodsFor:'method counting'! |
155 | 692 |
|
693 |
countMethod:aMethod |
|
694 |
"arrange for a aMethods execution to be counted. |
|
695 |
Use unwrapMethod to remove this." |
|
696 |
||
697 |
MethodCounts isNil ifTrue:[ |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
698 |
MethodCounts := IdentityDictionary new. |
155 | 699 |
]. |
700 |
MethodCounts at:aMethod put:0. |
|
701 |
||
702 |
^ self wrapMethod:aMethod |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
703 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
704 |
|cnt| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
705 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
706 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
707 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
708 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
709 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
710 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
711 |
] |
155 | 712 |
|
713 |
" |
|
714 |
MessageTracer countMethod:(Integer compiledMethodAt:#factorial). |
|
715 |
5 factorial. |
|
716 |
MessageTracer executionCountOf:(Integer compiledMethodAt:#factorial) printNL. |
|
717 |
MessageTracer stopCountingMethod:(Integer compiledMethodAt:#factorial) |
|
718 |
" |
|
719 |
||
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
720 |
"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
|
721 |
"Modified: / 27.7.1998 / 10:47:46 / cg" |
155 | 722 |
! |
723 |
||
724 |
executionCountOfMethod:aMethod |
|
725 |
"return the current count" |
|
726 |
||
727 |
|count| |
|
728 |
||
729 |
MethodCounts isNil ifTrue:[^ 0]. |
|
730 |
aMethod isWrapped ifTrue:[ |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
731 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
732 |
count notNil ifTrue:[^ count]. |
155 | 733 |
]. |
734 |
^ MethodCounts at:aMethod ifAbsent:0 |
|
735 |
||
736 |
"Created: 15.12.1995 / 11:01:56 / cg" |
|
737 |
"Modified: 15.12.1995 / 15:45:15 / cg" |
|
738 |
! |
|
739 |
||
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
740 |
resetCountOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
741 |
"return the current count" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
742 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
743 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
744 |
aMethod isWrapped ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
745 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
746 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
747 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
748 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
749 |
"Created: / 30.7.1998 / 17:42:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
750 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
751 |
|
155 | 752 |
stopCountingMethod:aMethod |
753 |
"remove counting of aMethod" |
|
754 |
||
755 |
^ self unwrapMethod:aMethod |
|
756 |
||
757 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
758 |
! ! |
|
759 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
760 |
!MessageTracer class methodsFor:'method memory usage'! |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
761 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
762 |
countMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
763 |
"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
|
764 |
Use unwrapMethod to remove this." |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
765 |
|
501 | 766 |
|oldPriority oldScavengeCount oldNewUsed| |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
767 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
768 |
MethodCounts isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
769 |
MethodCounts := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
770 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
771 |
MethodMemoryUsage isNil ifTrue:[ |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
772 |
MethodMemoryUsage := IdentityDictionary new. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
773 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
774 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
775 |
MethodCounts at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
776 |
MethodMemoryUsage at:aMethod put:0. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
777 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
778 |
^ self wrapMethod:aMethod |
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
779 |
onEntry:[:con | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
780 |
oldPriority := Processor activeProcess changePriority:(Processor userInterruptPriority). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
781 |
oldNewUsed := ObjectMemory newSpaceUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
782 |
oldScavengeCount := ObjectMemory scavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
783 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
784 |
onExit:[:con :retVal | |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
785 |
|cnt memUse scavenges| |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
786 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
787 |
memUse := ObjectMemory newSpaceUsed - oldNewUsed. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
788 |
scavenges := ObjectMemory scavengeCount - oldScavengeCount. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
789 |
scavenges ~= 0 ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
790 |
memUse := memUse + (ObjectMemory newSpaceSize * scavenges) |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
791 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
792 |
|
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
793 |
MethodCounts notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
794 |
cnt := MethodCounts at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
795 |
MethodCounts at:aMethod put:(cnt + 1). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
796 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
797 |
MethodMemoryUsage notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
798 |
cnt := MethodMemoryUsage at:aMethod ifAbsent:0. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
799 |
MethodMemoryUsage at:aMethod put:(cnt + memUse). |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
800 |
]. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
801 |
Processor activeProcess priority:oldPriority. |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
802 |
aMethod changed:#statistics |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
803 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
804 |
onUnwind:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
805 |
oldPriority notNil ifTrue:[ |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
806 |
Processor activeProcess priority:oldPriority |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
807 |
] |
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
808 |
] |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
809 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
810 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
811 |
MessageTracer countMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial). |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
812 |
3 factorial. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
813 |
(MessageTracer memoryUsageOfMethod:(Integer compiledMethodAt:#factorial)) printNL. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
814 |
MessageTracer stopCountingMemoryUsageOfMethod:(Integer compiledMethodAt:#factorial) |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
815 |
" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
816 |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
817 |
"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
|
818 |
"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
|
819 |
"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
|
820 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
821 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
822 |
isCountingMemoryUsage:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
823 |
"return true if aMethod is counting memoryUsage" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
824 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
825 |
MethodMemoryUsage isNil ifTrue:[^ false]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
826 |
(MethodMemoryUsage includesKey:aMethod) ifTrue:[^ true]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
827 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
828 |
^ MethodMemoryUsage includesKey:aMethod originalMethod |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
829 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
830 |
^ false |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
831 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
832 |
"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
|
833 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
834 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
835 |
memoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
836 |
"return the current count" |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
837 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
838 |
|count memUse| |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
839 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
840 |
(MethodCounts isNil or:[MethodMemoryUsage isNil]) ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
841 |
aMethod isWrapped ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
842 |
count := MethodCounts at:aMethod originalMethod ifAbsent:nil. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
843 |
memUse := MethodMemoryUsage at:aMethod originalMethod ifAbsent:nil. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
844 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
845 |
memUse isNil ifTrue:[ |
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
846 |
count := MethodCounts at:aMethod ifAbsent:0. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
847 |
memUse := MethodMemoryUsage at:aMethod ifAbsent:0. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
848 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
849 |
count = 0 ifTrue:[^ 0]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
850 |
^ memUse//count |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
851 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
852 |
"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
|
853 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
854 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
855 |
resetMemoryUsageOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
856 |
"reset the current usage" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
857 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
858 |
MethodCounts notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
859 |
MethodMemoryUsage notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
860 |
aMethod isWrapped ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
861 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
862 |
MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
863 |
] |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
864 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
865 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
866 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
867 |
"Created: / 30.7.1998 / 17:43:07 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
868 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
869 |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
870 |
stopCountingMemoryUsageOfMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
871 |
"remove counting memory of aMethod" |
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 |
^ self unwrapMethod:aMethod |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
874 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
875 |
"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
|
876 |
! ! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
877 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
878 |
!MessageTracer class methodsFor:'method timing'! |
327 | 879 |
|
880 |
executionTimesOfMethod:aMethod |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
881 |
"return the current gathered execution time statistics" |
327 | 882 |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
883 |
|count info minT maxT avg ret| |
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
884 |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
885 |
count := 0. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
886 |
minT := maxT := avg := nil. |
327 | 887 |
MethodTiming notNil ifTrue:[ |
888 |
aMethod isWrapped ifTrue:[ |
|
889 |
info := MethodTiming at:aMethod originalMethod ifAbsent:nil. |
|
890 |
info notNil ifTrue:[ |
|
891 |
count := info at:1. |
|
579 | 892 |
count ~~ 0 ifTrue:[ |
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
893 |
minT := info at:2. |
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
894 |
maxT := info at:3. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
895 |
avg := (info at:4) / count |
579 | 896 |
] |
327 | 897 |
]. |
898 |
]. |
|
899 |
]. |
|
900 |
||
696 | 901 |
minT notNil ifTrue:[ |
902 |
minT > 10 ifTrue:[ |
|
903 |
minT := minT roundTo:0.1 |
|
904 |
] ifFalse:[ |
|
905 |
minT := minT roundTo:0.01 |
|
906 |
] |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
907 |
]. |
696 | 908 |
maxT notNil ifTrue:[ |
909 |
maxT > 10 ifTrue:[ |
|
910 |
maxT := maxT roundTo:0.1 |
|
911 |
] ifFalse:[ |
|
912 |
maxT := maxT roundTo:0.01 |
|
913 |
]. |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
914 |
]. |
696 | 915 |
avg notNil ifTrue:[ |
916 |
avg > 10 ifTrue:[ |
|
917 |
avg := avg roundTo:0.1 |
|
918 |
] ifFalse:[ |
|
919 |
avg := avg roundTo:0.01 |
|
920 |
]. |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
921 |
]. |
327 | 922 |
ret := IdentityDictionary new. |
923 |
ret at:#count put:count. |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
924 |
ret at:#minTime put:minT. |
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
925 |
ret at:#maxTime put:maxT. |
327 | 926 |
ret at:#avgTime put:avg. |
927 |
^ ret |
|
928 |
||
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
929 |
"Created: / 17.6.1996 / 17:07:30 / cg" |
696 | 930 |
"Modified: / 30.7.1998 / 18:20:45 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
931 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
932 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
933 |
resetExecutionTimesOfMethod:aMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
934 |
"reset the gathered execution times statistics for aMethod; |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
935 |
the method remains wrapped." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
936 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
937 |
MethodTiming notNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
938 |
aMethod isWrapped ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
939 |
MethodTiming removeKey:aMethod originalMethod ifAbsent:nil. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
940 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
941 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
942 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
943 |
"Created: / 30.7.1998 / 17:12:35 / cg" |
327 | 944 |
! |
945 |
||
946 |
stopTimingMethod:aMethod |
|
947 |
"remove timing of aMethod" |
|
948 |
||
949 |
^ self unwrapMethod:aMethod |
|
950 |
||
951 |
"Modified: 15.12.1995 / 15:43:53 / cg" |
|
952 |
"Created: 17.6.1996 / 17:04:03 / cg" |
|
953 |
! |
|
954 |
||
955 |
timeMethod:aMethod |
|
956 |
"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
|
957 |
Use unwrapMethod: or stopTimingMethod: to remove this." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
958 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
959 |
|t0| |
327 | 960 |
|
961 |
MethodTiming isNil ifTrue:[ |
|
962 |
MethodTiming := IdentityDictionary new. |
|
963 |
]. |
|
964 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
579 | 965 |
MethodTiming at:aMethod put:(Array with:0 |
966 |
with:0 |
|
967 |
with:0 |
|
968 |
with:0). |
|
327 | 969 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
970 |
TimeForWrappers isNil ifTrue:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
971 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
972 |
]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
973 |
|
327 | 974 |
^ self wrapMethod:aMethod |
975 |
onEntry:[:con | |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
976 |
t0 := OperatingSystem getMicrosecondTime. |
327 | 977 |
] |
978 |
onExit:[:con :retVal | |
|
668
7cd41a86e7b2
renamed min/max - bad names on NeXT
Claus Gittinger <cg@exept.de>
parents:
667
diff
changeset
|
979 |
|info t cnt minT maxT sumTimes| |
327 | 980 |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
981 |
t := OperatingSystem getMicrosecondTime - t0. |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
982 |
t := t - TimeForWrappers. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
983 |
t < 0 ifTrue:[t := 0]. |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
984 |
t := t / 1000.0. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
985 |
|
327 | 986 |
info := MethodTiming at:aMethod ifAbsent:nil. |
987 |
info isNil ifTrue:[ |
|
988 |
MethodTiming at:aMethod put:(Array with:1 |
|
989 |
with:t |
|
990 |
with:t |
|
991 |
with:t) |
|
992 |
] ifFalse:[ |
|
993 |
cnt := info at:1. |
|
994 |
sumTimes := info at:4. |
|
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
995 |
|
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
996 |
cnt == 0 ifTrue:[ |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
997 |
info at:2 put:t. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
998 |
info at:3 put:t. |
327 | 999 |
] ifFalse:[ |
693
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1000 |
minT := info at:2. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1001 |
maxT := info at:3. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1002 |
t < minT ifTrue:[ |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1003 |
info at:2 put:t. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1004 |
] ifFalse:[ |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1005 |
t > maxT ifTrue:[ |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1006 |
info at:3 put:t. |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1007 |
] |
cd020921a251
use microsecond resolution in method timing
Claus Gittinger <cg@exept.de>
parents:
691
diff
changeset
|
1008 |
]. |
327 | 1009 |
]. |
1010 |
info at:4 put:(sumTimes + t). |
|
1011 |
info at:1 put:cnt + 1 |
|
1012 |
]. |
|
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1013 |
aMethod changed:#statistics |
327 | 1014 |
] |
1015 |
||
1016 |
" |
|
1017 |
MessageTracer timeMethod:(Integer compiledMethodAt:#factorial). |
|
1018 |
5 factorial. |
|
1019 |
5 factorial. |
|
1020 |
5 factorial. |
|
1021 |
(MessageTracer executionTimesOfMethod:(Integer compiledMethodAt:#factorial)) printCR. |
|
1022 |
MessageTracer stopTimingMethod:(Integer compiledMethodAt:#factorial) |
|
1023 |
" |
|
1024 |
||
691
17c3c522f1dc
send change notifications when a counted methods count
Claus Gittinger <cg@exept.de>
parents:
668
diff
changeset
|
1025 |
"Created: / 17.6.1996 / 17:03:50 / cg" |
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
1026 |
"Modified: / 30.7.1998 / 17:13:11 / cg" |
327 | 1027 |
! ! |
1028 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1029 |
!MessageTracer class methodsFor:'method tracing'! |
11 | 1030 |
|
664 | 1031 |
traceClass:aClass selector:aSelector |
1032 |
"arrange for a trace message to be output on Stderr, when a message with aSelector is |
|
1033 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1034 |
||
1035 |
self traceClass:aClass selector:aSelector on:Stderr |
|
1036 |
||
1037 |
" |
|
1038 |
MessageTracer traceClass:Integer selector:#factorial. |
|
1039 |
5 factorial. |
|
1040 |
MessageTracer untraceClass:Integer |
|
1041 |
" |
|
1042 |
" |
|
1043 |
MessageTracer traceClass:SequenceableCollection selector:#quickSortFrom:to:. |
|
1044 |
#(6 1 9 66 2 17) copy sort. |
|
1045 |
MessageTracer untraceClass:SequenceableCollection |
|
1046 |
" |
|
1047 |
" |
|
1048 |
MessageTracer traceClass:Array selector:#at:. |
|
1049 |
MessageTracer traceClass:Array selector:#at:put:. |
|
1050 |
#(6 1 9 66 2 17) copy sort. |
|
1051 |
MessageTracer untraceClass:Array |
|
1052 |
" |
|
1053 |
! |
|
1054 |
||
1055 |
traceClass:aClass selector:aSelector on:aStream |
|
1056 |
"arrange for a trace message to be output on aStream, when a message with aSelector is |
|
1057 |
sent to instances of aClass (or subclass instances). Use untraceClass to remove this." |
|
1058 |
||
1059 |
self traceMethod:(aClass compiledMethodAt:aSelector) on:aStream |
|
1060 |
||
1061 |
" |
|
1062 |
MessageTracer traceClass:Integer selector:#factorial on:Transcript. |
|
1063 |
5 factorial. |
|
1064 |
MessageTracer untraceClass:Integer |
|
1065 |
" |
|
1066 |
" |
|
1067 |
MessageTracer traceClass:Integer selector:#factorialR on:Transcript. |
|
1068 |
5 factorialR. |
|
1069 |
MessageTracer untraceClass:Integer |
|
1070 |
" |
|
1071 |
||
1072 |
! |
|
1073 |
||
88 | 1074 |
traceMethod:aMethod |
664 | 1075 |
"arrange for a trace message to be output on Stderr, |
1076 |
when aMethod is executed. Traces both entry and exit. |
|
88 | 1077 |
Use unwrapMethod to remove this." |
1078 |
||
664 | 1079 |
^ self traceMethod:aMethod on:Stderr |
11 | 1080 |
|
1081 |
" |
|
88 | 1082 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial). |
1083 |
5 factorial. |
|
1084 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1085 |
" |
|
1086 |
" |
|
664 | 1087 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR). |
1088 |
5 factorialR. |
|
1089 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1090 |
" |
|
1091 |
" |
|
88 | 1092 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
1093 |
#(6 1 9 66 2 17) copy sort. |
|
1094 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1095 |
" |
|
1096 |
" |
|
1097 |
dont do this: |
|
1098 |
" |
|
1099 |
" |
|
1100 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:). |
|
1101 |
MessageTracer traceMethod:(Object compiledMethodAt:#at:put:). |
|
1102 |
#(6 1 9 66 2 17) copy sort. |
|
1103 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:). |
|
1104 |
MessageTracer untraceMethod:(Object compiledMethodAt:#at:put:). |
|
11 | 1105 |
" |
1106 |
! |
|
1107 |
||
664 | 1108 |
traceMethod:aMethod on:aStream |
1109 |
"arrange for a trace message to be output on aStream, |
|
1110 |
when aMethod is executed. Traces both entry and exit. |
|
1111 |
Use unwrapMethod to remove this." |
|
1112 |
||
1113 |
|lvl inside| |
|
1114 |
||
1115 |
^ self wrapMethod:aMethod |
|
1116 |
onEntry:[:con | |
|
1117 |
inside isNil ifTrue:[ |
|
1118 |
inside := true. |
|
1119 |
CallingLevel isNil ifTrue:[ |
|
1120 |
CallingLevel := 0. |
|
1121 |
]. |
|
1122 |
lvl notNil ifTrue:[ |
|
1123 |
lvl := lvl + 1 |
|
1124 |
] ifFalse:[ |
|
1125 |
CallingLevel := lvl := CallingLevel + 1. |
|
1126 |
]. |
|
1127 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1128 |
inside := nil |
|
1129 |
] |
|
1130 |
] |
|
1131 |
onExit:[:con :retVal | |
|
1132 |
inside isNil ifTrue:[ |
|
1133 |
inside := true. |
|
1134 |
MessageTracer printExit:con with:retVal level:lvl on:aStream. |
|
1135 |
CallingLevel := lvl := lvl - 1. |
|
1136 |
inside := nil |
|
1137 |
] |
|
1138 |
] |
|
1139 |
||
1140 |
" |
|
1141 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1142 |
5 factorial. |
|
1143 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1144 |
" |
|
1145 |
" |
|
1146 |
MessageTracer traceMethod:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1147 |
5 factorialR. |
|
1148 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1149 |
" |
|
1150 |
" |
|
1151 |
MessageTracer traceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1152 |
#(6 1 9 66 2 17) copy sort. |
|
1153 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1154 |
" |
|
1155 |
! |
|
1156 |
||
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1157 |
traceMethodAll:aMethod |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1158 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1159 |
Only the sender is traced on entry. |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1160 |
Use untraceMethod to remove this trace." |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1161 |
|
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1162 |
^ self wrapMethod:aMethod |
572 | 1163 |
onEntry:[:con | ObjectMemory flushCaches. Smalltalk sendTraceOn.] |
1164 |
onExit:[:con :val | Smalltalk sendTraceOff.] |
|
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1165 |
|
572 | 1166 |
"Modified: 22.3.1997 / 17:02:04 / cg" |
162
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1167 |
! |
ed6f37d2cc33
added traceAll (full trace - longish output)
Claus Gittinger <cg@exept.de>
parents:
161
diff
changeset
|
1168 |
|
664 | 1169 |
traceMethodEntry:aMethod |
1170 |
"arrange for a trace message to be output on stdErr, |
|
1171 |
when aMethod is executed. Only entry is traced. |
|
1172 |
Use unwrapMethod to remove this." |
|
1173 |
||
1174 |
^ self traceMethodEntry:aMethod on:Stderr |
|
1175 |
||
1176 |
" |
|
1177 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial). |
|
1178 |
5 factorial. |
|
1179 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1180 |
" |
|
1181 |
" |
|
1182 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR). |
|
1183 |
5 factorialR. |
|
1184 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1185 |
" |
|
1186 |
" |
|
1187 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1188 |
#(6 1 9 66 2 17) copy sort. |
|
1189 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1190 |
" |
|
1191 |
! |
|
1192 |
||
1193 |
traceMethodEntry:aMethod on:aStream |
|
1194 |
"arrange for a trace message to be output on aStream, |
|
1195 |
when aMethod is executed. Only entry is traced. |
|
1196 |
Use unwrapMethod to remove this." |
|
1197 |
||
1198 |
|lvl inside| |
|
1199 |
||
1200 |
^ self wrapMethod:aMethod |
|
1201 |
onEntry:[:con | |
|
1202 |
inside isNil ifTrue:[ |
|
1203 |
inside := true. |
|
1204 |
CallingLevel isNil ifTrue:[ |
|
1205 |
CallingLevel := 0. |
|
1206 |
]. |
|
1207 |
lvl notNil ifTrue:[ |
|
1208 |
lvl := lvl + 1 |
|
1209 |
] ifFalse:[ |
|
1210 |
CallingLevel := lvl := CallingLevel + 1. |
|
1211 |
]. |
|
1212 |
MessageTracer printEntryFull:con level:lvl on:aStream. |
|
1213 |
inside := nil |
|
1214 |
] |
|
1215 |
] |
|
1216 |
onExit:[:con :retVal |] |
|
1217 |
||
1218 |
" |
|
1219 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorial) on:Transcript. |
|
1220 |
5 factorial. |
|
1221 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorial) |
|
1222 |
" |
|
1223 |
" |
|
1224 |
MessageTracer traceMethodEntry:(Integer compiledMethodAt:#factorialR) on:Transcript. |
|
1225 |
5 factorialR. |
|
1226 |
MessageTracer untraceMethod:(Integer compiledMethodAt:#factorialR) |
|
1227 |
" |
|
1228 |
" |
|
1229 |
MessageTracer traceMethodEntry:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:) on:Transcript. |
|
1230 |
#(6 1 9 66 2 17) copy sort. |
|
1231 |
MessageTracer untraceMethod:(SequenceableCollection compiledMethodAt:#quickSortFrom:to:). |
|
1232 |
" |
|
1233 |
! |
|
1234 |
||
156 | 1235 |
traceMethodFull:aMethod |
1236 |
"arrange for a full trace message to be output on Stderr, when amethod is executed. |
|
1237 |
Only the sender is traced on entry. |
|
1238 |
Use untraceMethod to remove this trace." |
|
1239 |
||
664 | 1240 |
^ self traceMethodFull:aMethod on:Stderr |
1241 |
||
1242 |
"Created: 15.12.1995 / 18:19:31 / cg" |
|
1243 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
|
1244 |
! |
|
1245 |
||
1246 |
traceMethodFull:aMethod on:aStream |
|
1247 |
"arrange for a full trace message to be output on Stderr, when aMethod is executed. |
|
1248 |
Only the sender is traced on entry. |
|
1249 |
Use untraceMethod to remove this trace." |
|
1250 |
||
1251 |
^ self |
|
1252 |
wrapMethod:aMethod |
|
1253 |
onEntry:(self traceFullBlockFor:aStream) |
|
1254 |
onExit:LeaveTraceBlock. |
|
156 | 1255 |
|
1256 |
"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
|
1257 |
"Modified: 22.10.1996 / 17:39:28 / cg" |
156 | 1258 |
! |
1259 |
||
88 | 1260 |
traceMethodSender:aMethod |
664 | 1261 |
"arrange for a trace message to be output on Stderr, |
1262 |
when amethod is executed. |
|
1263 |
Only the sender is traced on entry. |
|
1264 |
Use untraceMethod to remove this trace." |
|
1265 |
||
1266 |
^ self traceMethodSender:aMethod on:Stderr |
|
1267 |
! |
|
1268 |
||
1269 |
traceMethodSender:aMethod on:aStream |
|
88 | 1270 |
"arrange for a trace message to be output on Stderr, when amethod is executed. |
1271 |
Only the sender is traced on entry. |
|
1272 |
Use untraceMethod to remove this trace." |
|
35 | 1273 |
|
664 | 1274 |
^ self |
1275 |
wrapMethod:aMethod |
|
1276 |
onEntry:(self traceSenderBlockFor:aStream) |
|
1277 |
onExit:LeaveTraceBlock. |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1278 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1279 |
"Modified: 22.10.1996 / 17:39:33 / cg" |
88 | 1280 |
! |
1281 |
||
1282 |
untraceMethod:aMethod |
|
1283 |
"remove tracing of aMethod" |
|
1284 |
||
1285 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
1286 |
trace facilities ..." |
|
1287 |
||
1288 |
^ self unwrapMethod:aMethod |
|
11 | 1289 |
! ! |
1290 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1291 |
!MessageTracer class methodsFor:'method wrapping'! |
11 | 1292 |
|
88 | 1293 |
unwrapAllMethods |
1294 |
"just in case you dont know what methods have break/trace-points |
|
1295 |
on them; this removes them all" |
|
1296 |
||
1297 |
WrappedMethod allInstancesDo:[:aMethod | |
|
1298 |
self unwrapMethod:aMethod |
|
1299 |
] |
|
11 | 1300 |
! |
1301 |
||
88 | 1302 |
unwrapMethod:aMethod |
1303 |
"remove any wrapper on aMethod" |
|
1304 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1305 |
|selector class originalMethod dict mthd| |
88 | 1306 |
|
155 | 1307 |
MethodCounts notNil ifTrue:[ |
265 | 1308 |
aMethod isWrapped ifTrue:[ |
1309 |
MethodCounts removeKey:aMethod originalMethod ifAbsent:nil. |
|
1310 |
]. |
|
1311 |
MethodCounts removeKey:aMethod ifAbsent:nil. |
|
1312 |
MethodCounts isEmpty ifTrue:[MethodCounts := nil]. |
|
172
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1313 |
]. |
cf44aece60d4
clear memoryUsage when unwrapping
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
1314 |
MethodMemoryUsage notNil ifTrue:[ |
265 | 1315 |
aMethod isWrapped ifTrue:[ |
1316 |
MethodMemoryUsage removeKey:aMethod originalMethod ifAbsent:nil. |
|
1317 |
]. |
|
1318 |
MethodMemoryUsage removeKey:aMethod ifAbsent:nil. |
|
1319 |
MethodMemoryUsage isEmpty ifTrue:[MethodMemoryUsage := nil]. |
|
155 | 1320 |
]. |
327 | 1321 |
MethodTiming notNil ifTrue:[ |
1322 |
aMethod isWrapped ifTrue:[ |
|
1323 |
MethodTiming removeKey:aMethod originalMethod ifAbsent:nil. |
|
1324 |
]. |
|
1325 |
MethodTiming removeKey:aMethod ifAbsent:nil. |
|
1326 |
MethodTiming isEmpty ifTrue:[MethodTiming := nil]. |
|
1327 |
]. |
|
155 | 1328 |
|
88 | 1329 |
CallingLevel := 0. |
1330 |
||
1331 |
(aMethod isNil or:[aMethod isWrapped not]) ifTrue:[ |
|
265 | 1332 |
^ aMethod |
88 | 1333 |
]. |
1334 |
||
1335 |
" |
|
1336 |
get class/selector |
|
1337 |
" |
|
1338 |
class := aMethod containingClass. |
|
1339 |
class isNil ifTrue:[ |
|
536 | 1340 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
265 | 1341 |
^ aMethod |
88 | 1342 |
]. |
1343 |
selector := class selectorAtMethod:aMethod. |
|
1344 |
||
1345 |
originalMethod := aMethod originalMethod. |
|
1346 |
originalMethod isNil ifTrue:[ |
|
265 | 1347 |
self error:'oops, could not find original method'. |
1348 |
^ aMethod |
|
88 | 1349 |
]. |
1350 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1351 |
dict := class methodDictionary. |
506 | 1352 |
mthd := dict at:selector ifAbsent:nil. |
1353 |
mthd notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1354 |
dict at:selector put:originalMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1355 |
class methodDictionary:dict. |
88 | 1356 |
] ifFalse:[ |
667 | 1357 |
'MessageTracer [info]: no containing class for method found' infoPrintCR. |
1358 |
"/ self halt:'oops, unexpected error - cannot remove wrap'. |
|
1359 |
aMethod becomeSameAs:originalMethod. |
|
265 | 1360 |
^ aMethod |
88 | 1361 |
]. |
1362 |
||
1363 |
ObjectMemory flushCaches. |
|
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1364 |
class changed:#methodTrap with:selector. "/ tell browsers |
88 | 1365 |
^ originalMethod |
265 | 1366 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1367 |
"Modified: 5.6.1996 / 14:08:08 / stefan" |
584
2da6bb2c8017
send out change notifications when a trap is removed
Claus Gittinger <cg@exept.de>
parents:
579
diff
changeset
|
1368 |
"Modified: 24.4.1997 / 18:20:49 / cg" |
13 | 1369 |
! |
1370 |
||
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1371 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1372 |
^ 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
|
1373 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1374 |
"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
|
1375 |
! |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1376 |
|
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1377 |
wrapMethod:aMethod onEntry:entryBlock onExit:exitBlock onUnwind:unwindBlock |
88 | 1378 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
1379 |
aMethod is evaluated. |
|
1380 |
EntryBlock will be called on entry, and gets the current context passed as argument. |
|
1381 |
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
|
1382 |
the methods return value as arguments. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1383 |
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
|
1384 |
If there is an unwindBlock, the entry and exitBlocks will be called within the unwind block, |
572 | 1385 |
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
|
1386 |
" |
88 | 1387 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1388 |
|selector class trapMethod s spec src dict sel save| |
88 | 1389 |
|
1390 |
CallingLevel := 0. |
|
1391 |
||
1392 |
" |
|
1393 |
create a new method, which calls the original one, |
|
1394 |
but only if not already being trapped. |
|
1395 |
" |
|
1396 |
(aMethod isNil or:[aMethod isWrapped]) ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1397 |
^ aMethod |
88 | 1398 |
]. |
1399 |
aMethod isLazyMethod ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1400 |
aMethod makeRealMethod |
88 | 1401 |
]. |
1402 |
||
1403 |
" |
|
1404 |
get class/selector |
|
1405 |
" |
|
1406 |
class := aMethod containingClass. |
|
1407 |
class isNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1408 |
self error:'cannot place trap (no containing class found)'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1409 |
^ aMethod |
88 | 1410 |
]. |
1411 |
selector := class selectorAtMethod:aMethod. |
|
1412 |
||
1413 |
||
1414 |
WrappedMethod autoload. "/ for small systems |
|
1415 |
||
1416 |
" |
|
1417 |
get a new method-spec |
|
1418 |
" |
|
1419 |
spec := Parser methodSpecificationForSelector:selector. |
|
1420 |
||
1421 |
" |
|
1422 |
create a method, executing the trap-blocks and the original method via a direct call |
|
1423 |
" |
|
1424 |
s := WriteStream on:String new. |
|
1425 |
s nextPutAll:spec. |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1426 |
s nextPutAll:' |retVal context| '. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1427 |
s nextPutAll:' context := thisContext.'. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1428 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1429 |
s nextPutAll:'['. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1430 |
]. |
88 | 1431 |
entryBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1432 |
s nextPutAll:'#entryBlock yourself value:context. '. |
88 | 1433 |
]. |
1434 |
s nextPutAll:'retVal := #originalMethod yourself'; |
|
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1435 |
nextPutAll: ' valueWithReceiver:(context receiver)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1436 |
nextPutAll: ' arguments:(context args)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1437 |
nextPutAll: ' selector:(context selector)'; |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1438 |
nextPutAll: ' search:(context searchClass)'; |
88 | 1439 |
nextPutAll: ' sender:nil. '. |
1440 |
||
1441 |
exitBlock notNil ifTrue:[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1442 |
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
|
1443 |
]. |
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1444 |
unwindBlock notNil ifTrue:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1445 |
s nextPutAll:'] valueOnUnwindDo:#unwindBlock yourself.'. |
88 | 1446 |
]. |
1447 |
s nextPutAll:'^ retVal'; cr. |
|
1448 |
||
1449 |
src := s contents. |
|
1450 |
save := Compiler stcCompilation. |
|
1451 |
Compiler stcCompilation:#never. |
|
1452 |
[ |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1453 |
Class withoutUpdatingChangesDo:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1454 |
trapMethod := Compiler compile:src |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1455 |
forClass:UndefinedObject |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1456 |
inCategory:aMethod category |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1457 |
notifying:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1458 |
install:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1459 |
skipIfSame:false |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1460 |
silent:true. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1461 |
] |
88 | 1462 |
] valueNowOrOnUnwindDo:[ |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1463 |
Compiler stcCompilation:save |
88 | 1464 |
]. |
1465 |
||
1466 |
trapMethod changeClassTo:WrappedMethod. |
|
1467 |
||
1468 |
" |
|
1469 |
raising our eyebrows here ... |
|
1470 |
" |
|
1471 |
entryBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1472 |
trapMethod changeLiteral:#entryBlock to:entryBlock. |
88 | 1473 |
]. |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1474 |
trapMethod changeLiteral:#originalMethod to:aMethod. |
88 | 1475 |
exitBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1476 |
trapMethod changeLiteral:#exitBlock to:exitBlock. |
88 | 1477 |
]. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1478 |
unwindBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1479 |
trapMethod changeLiteral:#unwindBlock to:unwindBlock. |
164
ea53c919343f
New method to wrap with unwind-actions.
Stefan Vogel <sv@exept.de>
parents:
162
diff
changeset
|
1480 |
]. |
88 | 1481 |
" |
1482 |
change the source of this new method |
|
1483 |
(to avoid confusion in the debugger ...) |
|
1484 |
" |
|
1485 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
1486 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1487 |
dict := class methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1488 |
sel := dict at:selector ifAbsent:[0]. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1489 |
sel == 0 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1490 |
self halt:'oops, unexpected error'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1491 |
^ aMethod |
88 | 1492 |
]. |
1493 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1494 |
dict at:selector put:trapMethod. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1495 |
class methodDictionary:dict. |
88 | 1496 |
ObjectMemory flushCaches. |
1497 |
^ trapMethod |
|
1498 |
||
1499 |
" |
|
1500 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1501 |
wrapMethod:(Point compiledMethodAt:#scaleBy:) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1502 |
onEntry:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1503 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1504 |
Transcript show:'leave Point>>scaleBy:; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1505 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1506 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1507 |
]. |
88 | 1508 |
(1@2) scaleBy:5. |
1509 |
MessageTracer unwrapMethod:(Point compiledMethodAt:#scaleBy:). |
|
1510 |
(1@2) scaleBy:5. |
|
1511 |
" |
|
1512 |
" |
|
1513 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1514 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1515 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1516 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1517 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1518 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1519 |
Transcript show:'leave Integer>>factorial; returning:'. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1520 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1521 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1522 |
]. |
258 | 1523 |
Transcript showCR:'5 factorial traced'. |
88 | 1524 |
5 factorial. |
1525 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1526 |
Transcript showCR:'5 factorial normal'. |
88 | 1527 |
5 factorial. |
1528 |
" |
|
1529 |
" |
|
1530 |
|lvl| |
|
1531 |
||
1532 |
lvl := 0. |
|
1533 |
MessageTracer |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1534 |
wrapMethod:(Integer compiledMethodAt:#factorial) |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1535 |
onEntry:[:con | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1536 |
Transcript spaces:lvl. lvl := lvl + 2. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1537 |
Transcript showCR:('entering ' , con receiver printString , '>>factorial'). |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1538 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1539 |
onExit:[:con :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1540 |
lvl := lvl - 2. Transcript spaces:lvl. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1541 |
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
|
1542 |
Transcript showCR:retVal printString. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1543 |
Transcript endEntry |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1544 |
]. |
258 | 1545 |
Transcript showCR:'5 factorial traced'. |
88 | 1546 |
5 factorial. |
1547 |
MessageTracer unwrapMethod:(Integer compiledMethodAt:#factorial). |
|
258 | 1548 |
Transcript showCR:'5 factorial normal'. |
88 | 1549 |
5 factorial. |
1550 |
" |
|
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
1551 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
1552 |
"Modified: 25.6.1996 / 22:04:51 / stefan" |
572 | 1553 |
"Modified: 22.3.1997 / 17:00:43 / cg" |
88 | 1554 |
! ! |
1555 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1556 |
!MessageTracer class methodsFor:'object breakpointing'! |
88 | 1557 |
|
525 | 1558 |
objectHasWraps:anObject |
1559 |
"return true, if anObject has any wraps" |
|
1560 |
||
1561 |
^ anObject class category == #'* trapping *' |
|
1562 |
! |
|
1563 |
||
1564 |
realClassOf:anObject |
|
1565 |
"return anObjects real class" |
|
1566 |
||
1567 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1568 |
^ anObject class |
|
1569 |
]. |
|
1570 |
^ anObject class superclass |
|
1571 |
! |
|
1572 |
||
88 | 1573 |
trap:anObject selector:aSelector |
1574 |
"arrange for the debugger to be entered when a message with aSelector is |
|
1575 |
sent to anObject. Use untrap to remove this trap. |
|
1576 |
The current implementation does not allow integers or nil to be trapped." |
|
1577 |
||
1578 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1579 |
selector:aSelector |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1580 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1581 |
onExit:LeaveBreakBlock. |
88 | 1582 |
|
1583 |
" |
|
1584 |
|p| |
|
1585 |
||
1586 |
p := Point new. |
|
1587 |
MessageTracer trap:p selector:#x:. |
|
1588 |
p x:5 |
|
1589 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1590 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1591 |
"Modified: 22.10.1996 / 17:39:41 / cg" |
11 | 1592 |
! |
1593 |
||
88 | 1594 |
trap:anObject selectors:aCollection |
1595 |
self wrap:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1596 |
selectors:aCollection |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1597 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1598 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1599 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1600 |
"Modified: 22.10.1996 / 17:39:50 / cg" |
88 | 1601 |
! |
1602 |
||
1603 |
trapAll:anObject |
|
1604 |
"trap on all messages which are understood by anObject" |
|
1605 |
||
1606 |
self wrapAll:anObject |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1607 |
onEntry:BreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1608 |
onExit:LeaveBreakBlock. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1609 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1610 |
"Modified: 22.10.1996 / 17:39:54 / cg" |
88 | 1611 |
! |
1612 |
||
1613 |
trapAll:anObject from:aClass |
|
1614 |
"trap on all messages defined in aClass sent to anObject" |
|
1615 |
||
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1616 |
self trap:anObject selectors:aClass selectors |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1617 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1618 |
"Modified: 5.6.1996 / 13:46:06 / stefan" |
88 | 1619 |
! |
1620 |
||
1621 |
untrap:anObject |
|
1622 |
"remove any traps on anObject" |
|
1623 |
||
1624 |
"this is done by just patching the objects class back to the original" |
|
1625 |
||
1626 |
|orgClass| |
|
1627 |
||
1628 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1629 |
orgClass category == #'* trapping *' ifFalse:[ |
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1630 |
^ self |
88 | 1631 |
]. |
1632 |
||
660 | 1633 |
anObject changeClassTo:orgClass superclass. |
662 | 1634 |
ObjectCopyHolders notNil ifTrue:[ |
1635 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1636 |
]. |
|
88 | 1637 |
|
1638 |
" |
|
1639 |
|p| |
|
1640 |
||
1641 |
p := Point new copy. |
|
1642 |
MessageTracer trace:p selector:#x:. |
|
1643 |
MessageTracer trace:p selector:#y:. |
|
1644 |
p y:1. |
|
1645 |
p x:2. |
|
1646 |
MessageTracer untrap:p |
|
1647 |
p y:2. |
|
1648 |
p x:1. |
|
1649 |
" |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1650 |
|
660 | 1651 |
"Modified: / 21.4.1998 / 15:43:33 / cg" |
13 | 1652 |
! |
1653 |
||
88 | 1654 |
untrap:anObject selector:aSelector |
1655 |
"remove trap on aSelector from anObject" |
|
1656 |
||
501 | 1657 |
|orgClass dict| |
88 | 1658 |
|
1659 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
1660 |
orgClass category == #'* trapping *' ifFalse:[^ self]. |
88 | 1661 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1662 |
dict := orgClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1663 |
dict at:aSelector ifAbsent:[^ self]. |
88 | 1664 |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1665 |
dict size == 1 ifTrue:[ |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1666 |
"the last trap got removed" |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1667 |
anObject changeClassTo:orgClass superclass. |
662 | 1668 |
ObjectCopyHolders notNil ifTrue:[ |
1669 |
ObjectCopyHolders removeKey:anObject ifAbsent:nil. |
|
1670 |
]. |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1671 |
^ self |
88 | 1672 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1673 |
dict removeKey:aSelector. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1674 |
orgClass methodDictionary:dict. |
88 | 1675 |
ObjectMemory flushCaches. "avoid calling the old trap method" |
1676 |
||
1677 |
" |
|
1678 |
|p| |
|
1679 |
||
1680 |
p := Point new copy. |
|
1681 |
MessageTracer trace:p selector:#x:. |
|
1682 |
MessageTracer trace:p selector:#y:. |
|
1683 |
'trace both ...' errorPrintNL. |
|
1684 |
p x:2. |
|
1685 |
p y:1. |
|
1686 |
'trace only y ...' errorPrintNL. |
|
1687 |
MessageTracer untrap:p selector:#x:. |
|
1688 |
p x:2. |
|
1689 |
p y:1. |
|
1690 |
'trace none ...' errorPrintNL. |
|
1691 |
MessageTracer untrap:p selector:#y:. |
|
1692 |
p x:2. |
|
1693 |
p y:1. |
|
1694 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
1695 |
|
660 | 1696 |
"Modified: / 5.6.1996 / 13:56:08 / stefan" |
1697 |
"Modified: / 21.4.1998 / 15:43:55 / cg" |
|
525 | 1698 |
! |
1699 |
||
1700 |
wrappedSelectorsOf:anObject |
|
1701 |
"return the set of wrapped selectors (if any)" |
|
1702 |
||
1703 |
(anObject class category == #'* trapping *') ifFalse:[ |
|
1704 |
^ #() |
|
1705 |
]. |
|
1706 |
^ anObject class selectors |
|
11 | 1707 |
! ! |
1708 |
||
660 | 1709 |
!MessageTracer class methodsFor:'object modification traps'! |
1710 |
||
1711 |
trapModificationsIn:anObject |
|
1712 |
"trap modifications in anObject" |
|
1713 |
||
667 | 1714 |
anObject isNil ifTrue:[^ self]. |
1715 |
anObject isSymbol ifTrue:[^ self]. |
|
1716 |
anObject class == SmallInteger ifTrue:[^ self]. |
|
1717 |
anObject == true ifTrue:[^ self]. |
|
1718 |
anObject == false ifTrue:[^ self]. |
|
1719 |
||
660 | 1720 |
self |
663 | 1721 |
trapModificationsIn:anObject filter:[:old :new | true] |
660 | 1722 |
|
1723 |
" |
|
1724 |
|a| |
|
1725 |
||
1726 |
a := Array new:10. |
|
1727 |
MessageTracer trapModificationsIn:a. |
|
1728 |
||
1729 |
a size. |
|
1730 |
a at:1. |
|
1731 |
a at:2 put:nil. |
|
1732 |
a at:2 put:2. |
|
1733 |
a at:2. |
|
1734 |
a at:3. |
|
1735 |
a at:2 put:2. |
|
1736 |
a at:2 put:3. |
|
1737 |
MessageTracer untrace:a. |
|
1738 |
a at:3 put:5. |
|
1739 |
" |
|
1740 |
||
1741 |
"Created: / 21.4.1998 / 14:32:34 / cg" |
|
1742 |
"Modified: / 21.4.1998 / 14:58:24 / cg" |
|
1743 |
! |
|
1744 |
||
1745 |
trapModificationsIn:anObject filter:aFilterBlock |
|
1746 |
"trap modifications in anObject" |
|
1747 |
||
1748 |
|allSelectors| |
|
1749 |
||
1750 |
allSelectors := IdentitySet new. |
|
1751 |
anObject class withAllSuperclasses do:[:aClass | |
|
1752 |
aClass methodDictionary keys addAllTo:allSelectors |
|
1753 |
]. |
|
1754 |
allSelectors remove:#class. |
|
1755 |
||
1756 |
self trapModificationsIn:anObject selectors:allSelectors filter:aFilterBlock |
|
1757 |
||
1758 |
"trap if arrays 5th slot is modified: |
|
1759 |
||
1760 |
|a| |
|
1761 |
||
1762 |
a := Array new:10. |
|
1763 |
MessageTracer trapModificationsIn:a filter:[:old :new | (old at:5) ~~ (new at:5)]. |
|
1764 |
||
1765 |
a size. |
|
1766 |
a at:1. |
|
1767 |
a at:2 put:nil. |
|
1768 |
a at:2 put:2. |
|
1769 |
a at:2. |
|
1770 |
a at:3. |
|
1771 |
a at:2 put:2. |
|
1772 |
a at:2 put:3. |
|
1773 |
a at:5 put:3. |
|
1774 |
a at:5 put:3. |
|
1775 |
MessageTracer untrace:a. |
|
1776 |
a at:3 put:5. |
|
1777 |
" |
|
1778 |
||
1779 |
"Modified: / 21.4.1998 / 15:53:38 / cg" |
|
1780 |
! |
|
1781 |
||
1782 |
trapModificationsIn:anObject selector:aSelector filter:aFilterBlock |
|
1783 |
"install a trap for modifications in anObject by aSelector-messages. |
|
1784 |
the filterBlock will be invoked (after a modification) with the old and |
|
1785 |
new values as arguments and should return true, |
|
1786 |
if the debugger is really wanted." |
|
1787 |
||
1788 |
self |
|
1789 |
trapModificationsIn:anObject |
|
1790 |
selectors:(Array with:aSelector) |
|
1791 |
filter:aFilterBlock |
|
1792 |
||
1793 |
"Modified: / 21.4.1998 / 15:34:44 / cg" |
|
1794 |
! |
|
1795 |
||
1796 |
trapModificationsIn:anObject selectors:aCollectionOfSelectors filter:aFilterBlock |
|
1797 |
"install a trap for modifications in anObject by aSelector-messages. |
|
1798 |
the filterBlock will be invoked (after a modification) with the old and |
|
1799 |
new values as arguments and should return true, |
|
1800 |
if the debugger is really wanted." |
|
1801 |
||
1802 |
|copyHolder| |
|
1803 |
||
1804 |
ObjectCopyHolders isNil ifTrue:[ |
|
1805 |
ObjectCopyHolders := IdentityDictionary new. |
|
1806 |
]. |
|
1807 |
copyHolder := ObjectCopyHolders at:anObject ifAbsent:nil. |
|
1808 |
copyHolder isNil ifTrue:[ |
|
1809 |
ObjectCopyHolders at:anObject put:(copyHolder := ValueHolder new). |
|
1810 |
]. |
|
1811 |
||
1812 |
copyHolder value:(anObject shallowCopy). |
|
1813 |
||
1814 |
aCollectionOfSelectors do:[:aSelector | |
|
1815 |
|methodName| |
|
1816 |
||
1817 |
methodName := anObject class name , '>>' , aSelector. |
|
1818 |
self |
|
1819 |
wrap:anObject |
|
1820 |
selector:aSelector |
|
1821 |
onEntry:[:con | ] |
|
1822 |
onExit:[:con :retVal | |
|
1823 |
|oldValue| |
|
1824 |
||
1825 |
oldValue := copyHolder value. |
|
1826 |
||
1827 |
"/ compare with copy ... |
|
1828 |
(anObject sameContentsAs:oldValue) ifFalse:[ |
|
1829 |
"/ see oldValue vs. anObject |
|
1830 |
(aFilterBlock value:oldValue value:anObject) ifTrue:[ |
|
1831 |
copyHolder value:(anObject shallowCopy). |
|
1832 |
ObjectWrittenBreakpointSignal |
|
1833 |
raiseRequestWith:(oldValue -> anObject) |
|
1834 |
errorString:('object was modififed in ' , methodName) |
|
1835 |
in:con sender |
|
1836 |
] |
|
1837 |
] |
|
1838 |
] |
|
1839 |
withOriginalClass:true |
|
1840 |
flushCaches:false. |
|
1841 |
]. |
|
1842 |
ObjectMemory flushCaches |
|
1843 |
||
1844 |
"Created: / 21.4.1998 / 15:34:05 / cg" |
|
1845 |
"Modified: / 21.4.1998 / 16:00:39 / cg" |
|
1846 |
! ! |
|
1847 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
1848 |
!MessageTracer class methodsFor:'object tracing'! |
88 | 1849 |
|
1850 |
trace:anObject selector:aSelector |
|
1851 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1852 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
1853 |
Use untrap to remove this trace. |
|
1854 |
The current implementation does not allow integers or nil to be traced." |
|
1855 |
||
664 | 1856 |
self trace:anObject selector:aSelector on:Stderr |
88 | 1857 |
|
1858 |
" |
|
1859 |
|p| |
|
8 | 1860 |
|
88 | 1861 |
p := Point new. |
1862 |
MessageTracer trace:p selector:#x:. |
|
1863 |
p x:5. |
|
1864 |
p y:1. |
|
1865 |
p x:10. |
|
1866 |
MessageTracer untrap:p. |
|
1867 |
p x:7 |
|
1868 |
" |
|
1869 |
" |
|
1870 |
|a| |
|
1871 |
||
1872 |
a := #(6 1 9 66 2 17) copy. |
|
1873 |
MessageTracer trace:a selector:#at:put:. |
|
1874 |
MessageTracer trace:a selector:#at:. |
|
1875 |
a sort. |
|
1876 |
" |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
1877 |
|
660 | 1878 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
88 | 1879 |
! |
1880 |
||
664 | 1881 |
trace:anObject selector:aSelector on:aStream |
1882 |
"arrange for a trace message to be output on Stderr, when a message with |
|
1883 |
aSelector is sent to anObject. Both entry and exit are traced. |
|
1884 |
Use untrap to remove this trace. |
|
1885 |
The current implementation does not allow integers or nil to be traced." |
|
1886 |
||
1887 |
self |
|
1888 |
trace:anObject |
|
1889 |
selectors:(Array with:aSelector) |
|
1890 |
on:aStream |
|
1891 |
||
1892 |
" |
|
1893 |
|p| |
|
1894 |
||
1895 |
p := Point new. |
|
1896 |
MessageTracer trace:p selector:#x: on:Stderr. |
|
1897 |
p x:5. |
|
1898 |
p y:1. |
|
1899 |
p x:10. |
|
1900 |
MessageTracer untrap:p. |
|
1901 |
p x:7 |
|
1902 |
" |
|
1903 |
" |
|
1904 |
|a| |
|
1905 |
||
1906 |
a := #(6 1 9 66 2 17) copy. |
|
1907 |
MessageTracer trace:a selector:#at:put: on:Stderr. |
|
1908 |
MessageTracer trace:a selector:#at:. on:Stderr |
|
1909 |
a sort. |
|
1910 |
" |
|
1911 |
||
1912 |
"Modified: / 21.4.1998 / 15:37:05 / cg" |
|
1913 |
! |
|
1914 |
||
660 | 1915 |
trace:anObject selectors:aCollectionOfSelectors |
1916 |
"arrange for a trace message to be output on Stderr, when any message |
|
1917 |
from aCollectionOfSelectors is sent to anObject. |
|
1918 |
Both entry and exit are traced. |
|
1919 |
Use untrap:/untrace: to remove this trace. |
|
1920 |
The current implementation does not allow integers or nil to be traced." |
|
1921 |
||
664 | 1922 |
self trace:anObject selectors:aCollectionOfSelectors on:Stderr |
88 | 1923 |
|
1924 |
" |
|
660 | 1925 |
|p| |
1926 |
||
1927 |
p := Point new. |
|
1928 |
MessageTracer trace:p selector:#x:. |
|
1929 |
p x:5. |
|
1930 |
p y:1. |
|
1931 |
p x:10. |
|
1932 |
MessageTracer untrap:p. |
|
1933 |
p x:7 |
|
1934 |
" |
|
1935 |
" |
|
1936 |
|a| |
|
1937 |
||
1938 |
a := #(6 1 9 66 2 17) copy. |
|
1939 |
MessageTracer trace:a selector:#at:put:. |
|
1940 |
MessageTracer trace:a selector:#at:. |
|
1941 |
a sort. |
|
88 | 1942 |
" |
1943 |
||
660 | 1944 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
88 | 1945 |
! |
1946 |
||
664 | 1947 |
trace:anObject selectors:aCollectionOfSelectors on:aStream |
1948 |
"arrange for a trace message to be output on Stderr, when any message |
|
1949 |
from aCollectionOfSelectors is sent to anObject. |
|
1950 |
Both entry and exit are traced. |
|
1951 |
Use untrap:/untrace: to remove this trace. |
|
1952 |
The current implementation does not allow integers or nil to be traced." |
|
1953 |
||
1954 |
|methodName| |
|
1955 |
||
1956 |
aCollectionOfSelectors do:[:aSelector | |
|
1957 |
methodName := anObject class name , '>>' , aSelector. |
|
1958 |
self |
|
1959 |
wrap:anObject |
|
1960 |
selector:aSelector |
|
1961 |
onEntry:[:con | |
|
1962 |
aStream nextPutAll:'enter '; nextPutAll:methodName. |
|
1963 |
aStream nextPutAll:' receiver='. |
|
1964 |
con receiver printOn:aStream. |
|
1965 |
aStream nextPutAll:' args='. (con args) printOn:aStream. |
|
1966 |
aStream nextPutAll:' from:'. con sender printOn:aStream. |
|
1967 |
aStream cr; flush |
|
1968 |
] |
|
1969 |
onExit:[:con :retVal | |
|
1970 |
aStream nextPutAll:'leave '; nextPutAll:methodName. |
|
1971 |
aStream nextPutAll:' receiver='. con receiver printOn:aStream. |
|
1972 |
aStream nextPutAll:' returning:'. retVal printOn:aStream. |
|
1973 |
aStream cr; flush |
|
1974 |
] |
|
1975 |
withOriginalClass:true |
|
1976 |
flushCaches:false |
|
1977 |
]. |
|
1978 |
ObjectMemory flushCaches |
|
1979 |
||
1980 |
" |
|
1981 |
|p| |
|
1982 |
||
1983 |
p := Point new. |
|
1984 |
MessageTracer trace:p selectors:#(x:) on:Transcript. |
|
1985 |
p x:5. |
|
1986 |
p y:1. |
|
1987 |
p x:10. |
|
1988 |
MessageTracer untrap:p. |
|
1989 |
p x:7 |
|
1990 |
" |
|
1991 |
" |
|
1992 |
|a| |
|
1993 |
||
1994 |
a := #(6 1 9 66 2 17) copy. |
|
1995 |
MessageTracer trace:a selectors:#( at:put: at:) on:Transcript. |
|
1996 |
a sort. |
|
1997 |
" |
|
1998 |
||
1999 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2000 |
! |
|
2001 |
||
88 | 2002 |
traceAll:anObject |
2003 |
"trace all messages which are understood by anObject" |
|
27 | 2004 |
|
664 | 2005 |
self traceAll:anObject on:Stderr |
88 | 2006 |
|
2007 |
" |
|
2008 |
trace all (implemented) messages sent to Display |
|
2009 |
(other messages lead to an error, anyway) |
|
2010 |
" |
|
2011 |
||
2012 |
" |
|
2013 |
MessageTracer traceAll:Display |
|
2014 |
MessageTracer untrace:Display |
|
2015 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2016 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2017 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
88 | 2018 |
! |
2019 |
||
2020 |
traceAll:anObject from:aClass |
|
2021 |
"trace all messages defined in aClass sent to anObject" |
|
2022 |
||
664 | 2023 |
self traceAll:anObject from:aClass on:Stderr |
88 | 2024 |
|
2025 |
" |
|
2026 |
trace all methods in Display, which are implemented |
|
2027 |
in the DisplayWorkstation class. |
|
2028 |
" |
|
2029 |
||
2030 |
" |
|
2031 |
MessageTracer traceAll:Display from:XWorkstation |
|
2032 |
MessageTracer untrace:Display |
|
2033 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2034 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2035 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
27 | 2036 |
! |
2037 |
||
664 | 2038 |
traceAll:anObject from:aClass on:aStream |
2039 |
"trace all messages defined in aClass sent to anObject" |
|
2040 |
||
2041 |
self trace:anObject selectors:aClass selectors on:aStream |
|
2042 |
||
2043 |
" |
|
2044 |
trace all methods in Display, which are implemented |
|
2045 |
in the DisplayWorkstation class. |
|
2046 |
" |
|
2047 |
||
2048 |
" |
|
2049 |
MessageTracer traceAll:Display from:XWorkstation on:Transcript |
|
2050 |
MessageTracer untrace:Display |
|
2051 |
" |
|
2052 |
||
2053 |
"Modified: 5.6.1996 / 13:45:37 / stefan" |
|
2054 |
! |
|
2055 |
||
2056 |
traceAll:anObject on:aStream |
|
2057 |
"trace all messages which are understood by anObject" |
|
2058 |
||
2059 |
|allSelectors| |
|
2060 |
||
2061 |
allSelectors := IdentitySet new. |
|
2062 |
anObject class withAllSuperclasses do:[:aClass | |
|
2063 |
aClass methodDictionary keys addAllTo:allSelectors |
|
2064 |
]. |
|
2065 |
self trace:anObject selectors:allSelectors on:aStream |
|
2066 |
||
2067 |
" |
|
2068 |
trace all (implemented) messages sent to Display |
|
2069 |
(other messages lead to an error, anyway) |
|
2070 |
" |
|
2071 |
||
2072 |
" |
|
2073 |
MessageTracer traceAll:Display on:Transcript |
|
2074 |
MessageTracer untrace:Display |
|
2075 |
" |
|
2076 |
||
2077 |
"Modified: 5.6.1996 / 13:43:51 / stefan" |
|
2078 |
! |
|
2079 |
||
2080 |
traceEntry:anObject selectors:aCollectionOfSelectors on:aStream |
|
2081 |
"arrange for a trace message to be output on Stderr, when any message |
|
2082 |
from aCollectionOfSelectors is sent to anObject. |
|
2083 |
Only entry is traced. |
|
2084 |
Use untrap:/untrace: to remove this trace. |
|
2085 |
The current implementation does not allow integers or nil to be traced." |
|
2086 |
||
2087 |
self |
|
2088 |
traceEntry:anObject selectors:aCollectionOfSelectors on:Stderr |
|
2089 |
||
2090 |
" |
|
2091 |
|p| |
|
2092 |
||
2093 |
p := Point new. |
|
2094 |
MessageTracer traceEntry:p selectors:#(x:). |
|
2095 |
p x:5. |
|
2096 |
p y:1. |
|
2097 |
p x:10. |
|
2098 |
MessageTracer untrap:p. |
|
2099 |
p x:7 |
|
2100 |
" |
|
2101 |
" |
|
2102 |
|a| |
|
2103 |
||
2104 |
a := #(6 1 9 66 2 17) copy. |
|
2105 |
MessageTracer traceEntry:a selectors:#( at:put: at:). |
|
2106 |
a sort. |
|
2107 |
" |
|
2108 |
||
2109 |
"Modified: / 21.4.1998 / 15:41:57 / cg" |
|
2110 |
! |
|
2111 |
||
88 | 2112 |
traceSender:anObject selector:aSelector |
2113 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2114 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2115 |
Use untrap to remove this trace. |
|
2116 |
The current implementation does not allow integers or nil to be traced." |
|
2117 |
||
664 | 2118 |
^ self traceSender:anObject selector:aSelector on:Stderr |
88 | 2119 |
|
2120 |
" |
|
2121 |
|p| |
|
27 | 2122 |
|
88 | 2123 |
p := Point new. |
2124 |
MessageTracer traceSender:p selector:#x:. |
|
2125 |
p x:5. |
|
2126 |
p y:1. |
|
2127 |
p x:10. |
|
2128 |
MessageTracer untrap:p. |
|
2129 |
p x:7 |
|
2130 |
" |
|
2131 |
" |
|
2132 |
|a| |
|
2133 |
||
2134 |
a := #(6 1 9 66 2 17) copy. |
|
2135 |
MessageTracer traceSender:a selector:#at:put:. |
|
2136 |
MessageTracer traceSender:a selector:#at:. |
|
2137 |
a sort. |
|
2138 |
" |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2139 |
|
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2140 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
11 | 2141 |
! |
2142 |
||
664 | 2143 |
traceSender:anObject selector:aSelector on:aStream |
2144 |
"arrange for a trace message to be output on Stderr, when a message with |
|
2145 |
aSelector is sent to anObject. Only the sender is traced on entry. |
|
2146 |
Use untrap to remove this trace. |
|
2147 |
The current implementation does not allow integers or nil to be traced." |
|
2148 |
||
2149 |
|methodName| |
|
2150 |
||
2151 |
methodName := anObject class name , '>>' , aSelector. |
|
2152 |
self wrap:anObject |
|
2153 |
selector:aSelector |
|
2154 |
onEntry:[:con | |
|
2155 |
aStream nextPutAll:methodName. |
|
2156 |
aStream nextPutAll:' from '. |
|
2157 |
con sender printOn:aStream. |
|
2158 |
aStream cr; flush. |
|
2159 |
] |
|
2160 |
onExit:LeaveTraceBlock. |
|
2161 |
||
2162 |
" |
|
2163 |
|p| |
|
2164 |
||
2165 |
p := Point new. |
|
2166 |
MessageTracer traceSender:p selector:#x: on:Transcript. |
|
2167 |
p x:5. |
|
2168 |
p y:1. |
|
2169 |
p x:10. |
|
2170 |
MessageTracer untrap:p. |
|
2171 |
p x:7 |
|
2172 |
" |
|
2173 |
" |
|
2174 |
|a| |
|
2175 |
||
2176 |
a := #(6 1 9 66 2 17) copy. |
|
2177 |
MessageTracer traceSender:a selector:#at:put: on:Transcript. |
|
2178 |
MessageTracer traceSender:a selector:#at:. on:Transcript |
|
2179 |
a sort. |
|
2180 |
" |
|
2181 |
||
2182 |
"Modified: 10.1.1997 / 17:54:53 / cg" |
|
2183 |
! |
|
2184 |
||
88 | 2185 |
untrace:anObject |
2186 |
"remove any traces on anObject" |
|
2187 |
||
2188 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2189 |
trace facilities ..." |
|
2190 |
||
2191 |
^ self untrap:anObject |
|
2192 |
! |
|
2193 |
||
2194 |
untrace:anObject selector:aSelector |
|
2195 |
"remove traces of aSelector sent to anObject" |
|
2196 |
||
2197 |
"just a rename for your convenience - the same basic mechanism is used for all of these |
|
2198 |
trace facilities ..." |
|
2199 |
||
2200 |
^ self untrap:anObject selector:aSelector |
|
2201 |
! ! |
|
2202 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2203 |
!MessageTracer class methodsFor:'object wrapping'! |
88 | 2204 |
|
8 | 2205 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock |
2206 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
|
2207 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2208 |
entry, and get the current context passed as argument. ExitBlock will be called, |
|
2209 |
when the method is left, and get the context and the methods return value as arguments. |
|
2210 |
The current implementation does not allow integers or nil to be wrapped." |
|
2211 |
||
2212 |
"I have not yet enough experience, if the wrapped original method should |
|
2213 |
run as an instance of the original, or of the catching class; |
|
2214 |
The latter has the advantage of catching recursive and other sends, while |
|
2215 |
it might lead into trouble when the message is sent from a debugger or a long |
|
2216 |
return is done out of the original method ... |
|
2217 |
Time will show, you can experiment by setting the withOriginalClass: flag to false |
|
2218 |
" |
|
660 | 2219 |
^ self |
2220 |
wrap:anObject |
|
2221 |
selector:aSelector |
|
2222 |
onEntry:entryBlock |
|
2223 |
onExit:exitBlock |
|
2224 |
withOriginalClass:true |
|
2225 |
flushCaches:true |
|
2226 |
||
2227 |
"Modified: / 21.4.1998 / 15:29:50 / cg" |
|
8 | 2228 |
! |
2229 |
||
660 | 2230 |
wrap:anObject selector:aSelector onEntry:entryBlock onExit:exitBlock withOriginalClass:withOriginalClass flushCaches:flushCaches |
8 | 2231 |
"arrange for the two blocks entryBlock and exitBlock to be evaluated whenever |
2232 |
a message with aSelector is sent to anObject. EntryBlock will be called on |
|
2233 |
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
|
2234 |
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
|
2235 |
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
|
2236 |
before the wrapped method will be called. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2237 |
NOTICE: The current implementation does not allow integers or nil to be wrapped." |
8 | 2238 |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2239 |
|newClass orgClass myMetaclass trapMethod s spec implClass save dict| |
8 | 2240 |
|
2241 |
" |
|
27 | 2242 |
some are not allowed (otherwise we get into trouble ...) |
2243 |
" |
|
660 | 2244 |
(aSelector == #class |
2245 |
or:[aSelector == #changeClassTo:]) ifTrue:[ |
|
256 | 2246 |
Transcript showCR:'sorry, cannot place trap on: ' , aSelector. |
2247 |
^ self |
|
27 | 2248 |
]. |
2249 |
||
2250 |
WrappedMethod autoload. "/ just to make sure ... |
|
2251 |
||
2252 |
" |
|
8 | 2253 |
create a new (anonymous) subclass of the receivers class |
2254 |
but only if not already being trapped. |
|
2255 |
" |
|
2256 |
orgClass := anObject class. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2257 |
orgClass category == #'* trapping *' ifTrue:[ |
256 | 2258 |
newClass := orgClass |
8 | 2259 |
] ifFalse:[ |
256 | 2260 |
myMetaclass := orgClass class. |
8 | 2261 |
|
256 | 2262 |
newClass := myMetaclass copy new. |
2263 |
newClass setSuperclass:orgClass. |
|
2264 |
newClass instSize:orgClass instSize. |
|
2265 |
newClass flags:orgClass flags. |
|
667 | 2266 |
newClass isMeta ifFalse:[newClass setClassVariableString:'']. |
256 | 2267 |
newClass setInstanceVariableString:''. |
2268 |
newClass setName:orgClass name. |
|
457
8ba8e7ac735d
use #'* trapping *' instead of #trapping as category mark
Claus Gittinger <cg@exept.de>
parents:
352
diff
changeset
|
2269 |
newClass category:#'* trapping *'. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2270 |
newClass methodDictionary:MethodDictionary new. |
8 | 2271 |
]. |
2272 |
||
2273 |
" |
|
2274 |
create a method, executing the trap-blocks and the original method via a super-send |
|
2275 |
" |
|
2276 |
spec := Parser methodSpecificationForSelector:aSelector. |
|
2277 |
s := WriteStream on:String new. |
|
2278 |
s nextPutAll:spec. |
|
27 | 2279 |
s nextPutAll:' |retVal stubClass| '. |
8 | 2280 |
withOriginalClass ifTrue:[ |
256 | 2281 |
s nextPutAll:'stubClass := self class. '. |
2282 |
s nextPutAll:'self changeClassTo:(stubClass superclass). '. |
|
8 | 2283 |
]. |
2284 |
entryBlock notNil ifTrue:[ |
|
256 | 2285 |
s nextPutAll:'#literal1 yourself value:thisContext. '. |
8 | 2286 |
]. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2287 |
s nextPutAll:('retVal := #originalMethod. '). "/ just to get a place for the originalMethod |
27 | 2288 |
s nextPutAll:('retVal := super ' , spec , '. '). |
8 | 2289 |
exitBlock notNil ifTrue:[ |
256 | 2290 |
s nextPutAll:'#literal2 yourself value:thisContext value:retVal. '. |
8 | 2291 |
]. |
2292 |
withOriginalClass ifTrue:[ |
|
256 | 2293 |
s nextPutAll:'self changeClassTo:stubClass. '. |
8 | 2294 |
]. |
2295 |
s nextPutAll:'^ retVal'; cr. |
|
2296 |
||
37 | 2297 |
save := Compiler stcCompilation. |
2298 |
Compiler stcCompilation:#never. |
|
2299 |
[ |
|
256 | 2300 |
Class withoutUpdatingChangesDo:[ |
2301 |
trapMethod := Compiler compile:s contents |
|
2302 |
forClass:newClass |
|
2303 |
inCategory:'breakpointed' |
|
2304 |
notifying:nil |
|
2305 |
install:false |
|
2306 |
skipIfSame:false |
|
2307 |
silent:true. |
|
2308 |
] |
|
37 | 2309 |
] valueNowOrOnUnwindDo:[ |
256 | 2310 |
Compiler stcCompilation:save |
37 | 2311 |
]. |
8 | 2312 |
|
646 | 2313 |
trapMethod == #Error ifTrue:[ |
2314 |
Transcript showCR:('cannot place trap on method: ' , aSelector). |
|
2315 |
^ self |
|
2316 |
]. |
|
2317 |
||
29 | 2318 |
implClass := orgClass whichClassIncludesSelector:aSelector. |
2319 |
implClass isNil ifTrue:[ |
|
256 | 2320 |
Transcript showCR:aSelector , ' is not understood by ' , orgClass name. |
29 | 2321 |
] ifFalse:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2322 |
trapMethod changeLiteral:#originalMethod to:(implClass compiledMethodAt:aSelector). |
29 | 2323 |
]. |
8 | 2324 |
entryBlock notNil ifTrue:[ |
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2325 |
trapMethod changeLiteral:#literal1 to:entryBlock. |
8 | 2326 |
]. |
2327 |
exitBlock notNil ifTrue:[ |
|
352
ac12b5bc2754
Move method's literals form literalArray to indexed instvars.
Stefan Vogel <sv@exept.de>
parents:
327
diff
changeset
|
2328 |
trapMethod changeLiteral:#literal2 to:exitBlock. |
8 | 2329 |
]. |
2330 |
" |
|
2331 |
change the source of this new method |
|
2332 |
(to avoid confusion in the debugger ...) |
|
2333 |
" |
|
2334 |
trapMethod source:'this is a wrapper method - not the real one'. |
|
27 | 2335 |
trapMethod changeClassTo:WrappedMethod. |
8 | 2336 |
|
2337 |
" |
|
2338 |
install this new method |
|
2339 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2340 |
dict := newClass methodDictionary. |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2341 |
dict := dict at:aSelector putOrAppend:trapMethod. |
660 | 2342 |
flushCaches ifTrue:[ |
2343 |
newClass methodDictionary:dict. |
|
2344 |
] ifFalse:[ |
|
2345 |
newClass setMethodDictionary:dict. |
|
2346 |
]. |
|
8 | 2347 |
|
2348 |
" |
|
2349 |
and finally, the big trick: |
|
2350 |
" |
|
660 | 2351 |
newClass ~~ orgClass ifTrue:[ |
2352 |
anObject changeClassTo:newClass |
|
2353 |
]. |
|
8 | 2354 |
|
2355 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2356 |
[exBegin] |
8 | 2357 |
|p| |
2358 |
||
2359 |
p := Point new copy. |
|
2360 |
MessageTracer |
|
256 | 2361 |
wrap:p |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2362 |
selector:#y: |
256 | 2363 |
onEntry:nil |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2364 |
onExit:[:context :retVal | |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2365 |
Transcript show:'leave Point>>y:, returning:'. |
256 | 2366 |
Transcript showCR:retVal printString. |
2367 |
Transcript endEntry |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2368 |
] |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2369 |
withOriginalClass:true. |
256 | 2370 |
Transcript showCR:'sending x: ...'. |
8 | 2371 |
p x:1. |
256 | 2372 |
Transcript showCR:'sending y: ...'. |
8 | 2373 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2374 |
MessageTracer untrap:p. |
256 | 2375 |
Transcript showCR:'sending x: ...'. |
8 | 2376 |
p x:2. |
256 | 2377 |
Transcript showCR:'sending y: ...'. |
8 | 2378 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2379 |
[exEnd] |
8 | 2380 |
" |
2381 |
||
2382 |
" |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2383 |
[exBegin] |
8 | 2384 |
|p| |
2385 |
||
2386 |
p := Point new copy. |
|
2387 |
MessageTracer wrap:p |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2388 |
selector:#y: |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2389 |
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
|
2390 |
onExit:nil |
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2391 |
withOriginalClass:false. |
256 | 2392 |
Transcript showCR:'sending x: ...'. |
8 | 2393 |
p x:1. |
256 | 2394 |
Transcript showCR:'sending y: ...'. |
8 | 2395 |
p y:2. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2396 |
MessageTracer untrap:p. |
256 | 2397 |
Transcript showCR:'sending x: ...'. |
8 | 2398 |
p x:2. |
256 | 2399 |
Transcript showCR:'sending y: ...'. |
8 | 2400 |
p y:1. |
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2401 |
[exEnd] |
8 | 2402 |
" |
150
54b6185e9aa7
compile without updating changes-file (also disables historyManager for the wrap)
Claus Gittinger <cg@exept.de>
parents:
120
diff
changeset
|
2403 |
|
646 | 2404 |
"Modified: / 25.6.1996 / 22:11:21 / stefan" |
2405 |
"Modified: / 6.2.1998 / 02:48:13 / cg" |
|
660 | 2406 |
"Created: / 21.4.1998 / 15:30:27 / cg" |
8 | 2407 |
! |
2408 |
||
88 | 2409 |
wrap:anObject selectors:aCollection onEntry:entryBlock onExit:exitBlock |
2410 |
"install wrappers for anObject on all selectors from aCollection" |
|
8 | 2411 |
|
88 | 2412 |
aCollection do:[:aSelector | |
660 | 2413 |
self |
2414 |
wrap:anObject selector:aSelector |
|
2415 |
onEntry:entryBlock onExit:exitBlock |
|
2416 |
withOriginalClass:true |
|
2417 |
flushCaches:false |
|
2418 |
]. |
|
2419 |
ObjectMemory flushCaches |
|
2420 |
||
2421 |
"Modified: / 21.4.1998 / 15:40:28 / cg" |
|
8 | 2422 |
! |
2423 |
||
88 | 2424 |
wrapAll:anObject onEntry:entryBlock onExit:exitBlock |
2425 |
"install wrappers for anObject on all implemented selectors" |
|
27 | 2426 |
|
2427 |
|allSelectors| |
|
2428 |
||
2429 |
allSelectors := IdentitySet new. |
|
2430 |
anObject class withAllSuperclasses do:[:aClass | |
|
309
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2431 |
aClass methodDictionary keys addAllTo:allSelectors |
27 | 2432 |
]. |
88 | 2433 |
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
|
2434 |
|
d2a145453677
Use methodDictionary instyead of selector/method arrays.
Stefan Vogel <sv@exept.de>
parents:
265
diff
changeset
|
2435 |
"Modified: 5.6.1996 / 14:50:07 / stefan" |
88 | 2436 |
! ! |
2437 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2438 |
!MessageTracer class methodsFor:'queries'! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2439 |
|
579 | 2440 |
isCounting:aMethod |
2441 |
"return true if aMethod is counted" |
|
2442 |
||
2443 |
MethodCounts isNil ifTrue:[^ false]. |
|
2444 |
(MethodCounts includesKey:aMethod) ifTrue:[^ true]. |
|
2445 |
aMethod isWrapped ifTrue:[ |
|
2446 |
^ MethodCounts includesKey:aMethod originalMethod |
|
2447 |
]. |
|
2448 |
^ false |
|
2449 |
||
2450 |
"Created: 15.12.1995 / 11:07:58 / cg" |
|
2451 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2452 |
! |
|
2453 |
||
2454 |
isTiming:aMethod |
|
2455 |
"return true if aMethod is timed" |
|
2456 |
||
2457 |
MethodTiming isNil ifTrue:[^ false]. |
|
2458 |
(MethodTiming includesKey:aMethod) ifTrue:[^ true]. |
|
2459 |
aMethod isWrapped ifTrue:[ |
|
2460 |
^ MethodTiming includesKey:aMethod originalMethod |
|
2461 |
]. |
|
2462 |
^ false |
|
2463 |
||
2464 |
"Modified: 15.12.1995 / 15:42:10 / cg" |
|
2465 |
"Created: 17.6.1996 / 17:04:29 / cg" |
|
2466 |
! |
|
2467 |
||
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2468 |
isTrapped:aMethod |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2469 |
"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
|
2470 |
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
|
2471 |
this returns false)" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2472 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2473 |
aMethod isWrapped ifFalse:[^ false]. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2474 |
^ aMethod basicLiterals includesIdentical:LeaveBreakBlock |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2475 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2476 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2477 |
MessageTracer trapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2478 |
Transcript showCR:(Collection compiledMethodAt:#select:) isWrapped. |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2479 |
Transcript showCR:(MessageTracer isTrapped:(Collection compiledMethodAt:#select:)). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2480 |
MessageTracer unwrapMethod:(Collection compiledMethodAt:#select:). |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2481 |
" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2482 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2483 |
"Modified: 22.10.1996 / 17:40:37 / cg" |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2484 |
! ! |
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2485 |
|
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2486 |
!MessageTracer class methodsFor:'trace helpers'! |
88 | 2487 |
|
694
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2488 |
dummyEmptyMethod |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2489 |
"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
|
2490 |
a dummy method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2491 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2492 |
"Created: / 30.7.1998 / 16:58:08 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2493 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2494 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2495 |
getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2496 |
"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
|
2497 |
a timed method." |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2498 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2499 |
|m times| |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2500 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2501 |
TimeForWrappers := 0. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2502 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2503 |
"/ wrap the dummy method ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2504 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2505 |
m := self class compiledMethodAt:#dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2506 |
m := self timeMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2507 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2508 |
"/ invoke it a few times ... |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2509 |
"/ (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
|
2510 |
"/ depends on whether there is already some statistic data) |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2511 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2512 |
10 timesRepeat:[ |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2513 |
self dummyEmptyMethod. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2514 |
]. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2515 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2516 |
"/ fetch min time & unwrap |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2517 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2518 |
times := self executionTimesOfMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2519 |
self stopTimingMethod:m. |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2520 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2521 |
^ (TimeForWrappers := times at:#avgTime) |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2522 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2523 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2524 |
self getTimeForWrappers |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2525 |
" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2526 |
|
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2527 |
"Modified: / 30.7.1998 / 17:10:07 / cg" |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2528 |
! |
7c9f654a1054
much more detailed timing info;
Claus Gittinger <cg@exept.de>
parents:
693
diff
changeset
|
2529 |
|
88 | 2530 |
printEntryFull:aContext |
664 | 2531 |
self printEntryFull:aContext level:0 on:Stderr |
88 | 2532 |
! |
27 | 2533 |
|
88 | 2534 |
printEntryFull:aContext level:lvl |
664 | 2535 |
self printEntryFull:aContext level:lvl on:Stderr |
2536 |
! |
|
2537 |
||
2538 |
printEntryFull:aContext level:lvl on:aStream |
|
2539 |
|sender mClass mClassName| |
|
2540 |
||
2541 |
mClass := aContext methodClass. |
|
2542 |
mClass isNil ifTrue:[ |
|
2543 |
mClassName := '???' |
|
2544 |
] ifFalse:[ |
|
2545 |
mClassName := mClass name |
|
2546 |
]. |
|
2547 |
||
2548 |
aStream |
|
2549 |
spaces:lvl; |
|
2550 |
nextPutAll:'enter '; |
|
2551 |
nextPutAll:mClassName; |
|
2552 |
space; |
|
665 | 2553 |
bold; |
664 | 2554 |
nextPutAll:aContext selector; |
665 | 2555 |
normal; |
666 | 2556 |
nextPutAll:' rec=['. |
664 | 2557 |
|
2558 |
aContext receiver printOn:aStream. |
|
666 | 2559 |
aStream nextPutAll:'] '. |
2560 |
(aContext args) keysAndValuesDo:[:idx :arg | |
|
2561 |
|s| |
|
2562 |
||
2563 |
s := arg printString. |
|
2564 |
s > 20 ifTrue:[ |
|
2565 |
s := arg classNameWithArticle |
|
2566 |
]. |
|
2567 |
aStream nextPutAll:'arg'. idx printOn:aStream. aStream nextPutAll:'=['. |
|
2568 |
s printOn:aStream. |
|
2569 |
aStream nextPutAll:'] '. |
|
2570 |
]. |
|
664 | 2571 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2572 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2573 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2574 |
(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
|
2575 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2576 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2577 |
]. |
666 | 2578 |
|
2579 |
aStream nextPutAll:'from:'. |
|
664 | 2580 |
sender printOn:aStream. |
666 | 2581 |
aStream cr; flush. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2582 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2583 |
"Modified: 5.3.1997 / 12:40:55 / cg" |
88 | 2584 |
! |
27 | 2585 |
|
664 | 2586 |
printEntryFull:aContext on:aStream |
2587 |
self printEntryFull:aContext level:0 on:aStream |
|
2588 |
! |
|
2589 |
||
2590 |
printEntrySender:aContext on:aStream |
|
2591 |
|sender mClass mClassName| |
|
2592 |
||
2593 |
mClass := aContext methodClass. |
|
2594 |
mClass isNil ifTrue:[ |
|
2595 |
mClassName := '???' |
|
2596 |
] ifFalse:[ |
|
2597 |
mClassName := mClass name |
|
2598 |
]. |
|
2599 |
aStream |
|
2600 |
nextPutAll:mClassName; |
|
2601 |
space; |
|
665 | 2602 |
bold; |
664 | 2603 |
nextPutAll:aContext selector; |
665 | 2604 |
normal; |
664 | 2605 |
nextPutAll:' from '. |
538
5961061365d9
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
536
diff
changeset
|
2606 |
|
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2607 |
sender := aContext sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2608 |
sender notNil ifTrue:[ |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2609 |
(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
|
2610 |
sender := sender sender. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2611 |
]. |
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2612 |
]. |
664 | 2613 |
sender printOn:aStream. |
666 | 2614 |
aStream cr; flush. |
555
c92d12af9f1e
in trace: if sender is Object>>perform, print senders sender.
Claus Gittinger <cg@exept.de>
parents:
538
diff
changeset
|
2615 |
|
695 | 2616 |
"Modified: / 30.7.1998 / 20:40:14 / cg" |
88 | 2617 |
! |
2618 |
||
2619 |
printExit:aContext with:retVal |
|
664 | 2620 |
self printExit:aContext with:retVal level:0 on:Stderr |
27 | 2621 |
! |
2622 |
||
88 | 2623 |
printExit:aContext with:retVal level:lvl |
664 | 2624 |
self printExit:aContext with:retVal level:lvl on:Stderr |
2625 |
! |
|
2626 |
||
2627 |
printExit:aContext with:retVal level:lvl on:aStream |
|
2628 |
|mClass mClassName| |
|
2629 |
||
2630 |
mClass := aContext methodClass. |
|
2631 |
mClass isNil ifTrue:[ |
|
2632 |
mClassName := '???' |
|
2633 |
] ifFalse:[ |
|
2634 |
mClassName := mClass name |
|
2635 |
]. |
|
2636 |
aStream |
|
2637 |
spaces:lvl; |
|
2638 |
nextPutAll:'leave '; |
|
2639 |
nextPutAll:mClassName; |
|
2640 |
space; |
|
665 | 2641 |
bold; |
664 | 2642 |
nextPutAll:aContext selector; |
665 | 2643 |
normal; |
666 | 2644 |
nextPutAll:' rec=['. |
664 | 2645 |
|
2646 |
aContext receiver printOn:aStream. |
|
666 | 2647 |
aStream nextPutAll:'] return: ['. |
664 | 2648 |
retVal printOn:aStream. |
666 | 2649 |
aStream nextPutAll:']'; cr; flush. |
664 | 2650 |
! |
2651 |
||
2652 |
printExit:aContext with:retVal on:aStream |
|
2653 |
self printExit:aContext with:retVal level:0 on:aStream |
|
2654 |
! |
|
2655 |
||
697 | 2656 |
traceEntryFull:aContext on:aStream |
2657 |
aStream nextPutLine:'-----------------------------------------'. |
|
2658 |
aContext fullPrintAllOn:aStream |
|
2659 |
||
2660 |
"Created: / 30.7.1998 / 20:39:57 / cg" |
|
2661 |
"Modified: / 30.7.1998 / 20:42:23 / cg" |
|
2662 |
! |
|
2663 |
||
664 | 2664 |
traceFullBlockFor:aStream |
2665 |
"avoid generation of fullBlocks" |
|
2666 |
||
2667 |
aStream == Transcript ifTrue:[ |
|
2668 |
^ TraceFullBlock2 |
|
2669 |
]. |
|
2670 |
aStream == Stderr ifTrue:[ |
|
2671 |
^ TraceFullBlock |
|
2672 |
]. |
|
2673 |
^ [:con | con fullPrintAllOn:aStream] |
|
2674 |
||
2675 |
||
2676 |
||
2677 |
! |
|
2678 |
||
2679 |
traceSenderBlockFor:aStream |
|
2680 |
"avoid generation of fullBlocks" |
|
2681 |
||
2682 |
aStream == Transcript ifTrue:[ |
|
2683 |
^ TraceSenderBlock2 |
|
2684 |
]. |
|
2685 |
aStream == Stderr ifTrue:[ |
|
2686 |
^ TraceSenderBlock |
|
2687 |
]. |
|
2688 |
^ [:con | MessageTracer printEntrySender:con on:aStream] |
|
2689 |
||
2690 |
||
2691 |
||
88 | 2692 |
! ! |
13 | 2693 |
|
88 | 2694 |
!MessageTracer methodsFor:'trace helpers '! |
2695 |
||
2696 |
stepInterrupt |
|
2697 |
"called for every send while tracing" |
|
13 | 2698 |
|
88 | 2699 |
|con| |
13 | 2700 |
|
88 | 2701 |
StepInterruptPending := nil. |
2702 |
con := thisContext sender. |
|
2703 |
con lineNumber == 1 ifTrue:[ |
|
265 | 2704 |
traceDetail == true ifTrue:[ |
664 | 2705 |
self class printEntryFull:con on:Stderr. |
265 | 2706 |
] ifFalse:[ |
664 | 2707 |
con printOn:Stderr. |
2708 |
Stderr cr. |
|
265 | 2709 |
] |
88 | 2710 |
]. |
2711 |
ObjectMemory flushInlineCaches. |
|
2712 |
StepInterruptPending := 1. |
|
2713 |
InterruptPending := 1. |
|
2714 |
^ self |
|
265 | 2715 |
|
2716 |
"Modified: 20.5.1996 / 10:28:20 / cg" |
|
13 | 2717 |
! |
2718 |
||
88 | 2719 |
trace:aBlock detail:fullDetail |
2720 |
"trace execution of aBlock." |
|
2721 |
||
2722 |
traceDetail := fullDetail. |
|
2723 |
ObjectMemory stepInterruptHandler:self. |
|
2724 |
^ [ |
|
2725 |
ObjectMemory flushInlineCaches. |
|
2726 |
StepInterruptPending := 1. |
|
2727 |
InterruptPending := 1. |
|
2728 |
aBlock value |
|
2729 |
] valueNowOrOnUnwindDo:[ |
|
2730 |
StepInterruptPending := nil. |
|
2731 |
ObjectMemory stepInterruptHandler:nil. |
|
11 | 2732 |
] |
2733 |
||
2734 |
" |
|
88 | 2735 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:false |
2736 |
MessageTracer trace:[#(6 5 4 3 2 1) sort] detail:true |
|
8 | 2737 |
" |
2738 |
! ! |
|
27 | 2739 |
|
503
67f6584e0f9f
use different leaveBlocks for break & trace
Claus Gittinger <cg@exept.de>
parents:
501
diff
changeset
|
2740 |
!MessageTracer class methodsFor:'documentation'! |
98 | 2741 |
|
2742 |
version |
|
697 | 2743 |
^ '$Header: /cvs/stx/stx/libbasic3/MessageTracer.st,v 1.72 1998-07-30 22:39:58 cg Exp $' |
98 | 2744 |
! ! |
27 | 2745 |
MessageTracer initialize! |