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