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