2629
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2010 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libcomp' }"
|
|
13 |
|
|
14 |
Object variableSubclass:#InstrumentationContext
|
2710
|
15 |
instanceVariableNames:'inInstrumentedCode enabled coverageOnly'
|
2874
|
16 |
classVariableNames:'LastProcess LastInstrumentationContext
|
2664
|
17 |
GlobalInstrumentationContext'
|
2629
|
18 |
poolDictionaries:''
|
|
19 |
category:'System-Compiler-Instrumentation'
|
|
20 |
!
|
|
21 |
|
|
22 |
!InstrumentationContext class methodsFor:'documentation'!
|
|
23 |
|
|
24 |
copyright
|
|
25 |
"
|
|
26 |
COPYRIGHT (c) 2010 by eXept Software AG
|
|
27 |
All Rights Reserved
|
|
28 |
|
|
29 |
This software is furnished under a license and may be used
|
|
30 |
only in accordance with the terms of that license and with the
|
|
31 |
inclusion of the above copyright notice. This software may not
|
|
32 |
be provided or otherwise made available to, or used by, any
|
|
33 |
other person. No title to or ownership of the software is
|
|
34 |
hereby transferred.
|
|
35 |
"
|
|
36 |
!
|
|
37 |
|
|
38 |
documentation
|
|
39 |
"
|
|
40 |
installed as a thread-local variable (instrumentationContext) by the
|
|
41 |
beActiveIn:aProcess method, instances of me keep some meta state while
|
|
42 |
instrumentation is ongoing.
|
|
43 |
Especially, only in processes with a context are instrumentationInfo objects
|
|
44 |
updated. This has two advantages:
|
|
45 |
- it blocks recursive calls, while inside instrumentation code
|
|
46 |
- it blocks instrumentation from other processes (so only test-code is instrumented)
|
|
47 |
"
|
|
48 |
! !
|
|
49 |
|
|
50 |
!InstrumentationContext class methodsFor:'instance creation'!
|
|
51 |
|
|
52 |
new
|
|
53 |
"return an initialized instance"
|
|
54 |
|
|
55 |
^ self basicNew initialize.
|
|
56 |
! !
|
|
57 |
|
|
58 |
!InstrumentationContext class methodsFor:'instance access'!
|
|
59 |
|
|
60 |
current
|
2664
|
61 |
"the current context for this running thread.
|
|
62 |
walks along the parent-process chain, up to a possible global context"
|
2629
|
63 |
|
2664
|
64 |
^ self forProcess:(Processor activeProcess)
|
2629
|
65 |
|
|
66 |
"
|
|
67 |
InstrumentationContext current
|
|
68 |
"
|
|
69 |
|
|
70 |
"Created: / 08-08-2011 / 14:44:11 / cg"
|
2664
|
71 |
!
|
|
72 |
|
|
73 |
forProcess:aProcess
|
|
74 |
"the context for this thread.
|
|
75 |
walks along the parent-process chain, up to a possible global context"
|
|
76 |
|
|
77 |
|p context|
|
|
78 |
|
2874
|
79 |
aProcess == LastProcess ifTrue:[
|
|
80 |
^ LastInstrumentationContext
|
2664
|
81 |
].
|
|
82 |
|
2874
|
83 |
"/ future (need a faster parentProcess query)
|
|
84 |
p := aProcess.
|
|
85 |
[p notNil] whileTrue:[
|
|
86 |
context := p environmentAt:#instrumentationContext ifAbsent:nil.
|
|
87 |
context notNil ifTrue:[
|
|
88 |
aProcess environmentAt:#instrumentationContext put:context.
|
|
89 |
context == 0 ifTrue:[
|
|
90 |
context := nil.
|
2664
|
91 |
].
|
2874
|
92 |
LastProcess := aProcess.
|
|
93 |
LastInstrumentationContext := context.
|
|
94 |
^ context
|
2664
|
95 |
].
|
2874
|
96 |
p := p parentProcess
|
2664
|
97 |
].
|
2874
|
98 |
aProcess environmentAt:#instrumentationContext put:(GlobalInstrumentationContext ? 0). "/ could be nil
|
|
99 |
LastProcess := aProcess.
|
|
100 |
LastInstrumentationContext := GlobalInstrumentationContext.
|
|
101 |
^ GlobalInstrumentationContext.
|
2664
|
102 |
|
|
103 |
"
|
|
104 |
InstrumentationContext current
|
|
105 |
"
|
|
106 |
|
|
107 |
"Created: / 17-08-2011 / 11:29:51 / cg"
|
2629
|
108 |
! !
|
|
109 |
|
2706
|
110 |
!InstrumentationContext class methodsFor:'queries'!
|
|
111 |
|
|
112 |
hasGlobalInstrumentationContext
|
|
113 |
^ GlobalInstrumentationContext notNil
|
|
114 |
|
|
115 |
"
|
|
116 |
InstrumentationContext hasGlobalInstrumentationContext
|
|
117 |
"
|
|
118 |
|
|
119 |
"Created: / 21-09-2011 / 19:15:51 / cg"
|
|
120 |
! !
|
|
121 |
|
2629
|
122 |
!InstrumentationContext class methodsFor:'running'!
|
|
123 |
|
|
124 |
run:aBlock
|
|
125 |
"run aBlock with instrumentation enabled"
|
|
126 |
|
2657
|
127 |
self new run:aBlock.
|
2629
|
128 |
|
|
129 |
"
|
|
130 |
Smalltalk loadPackage:'exept:regression'.
|
|
131 |
BTree withAllPrivateClasses
|
|
132 |
do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler].
|
|
133 |
InstrumentationContext
|
|
134 |
run:[ RegressionTests::BinaryTreeTester suite run ].
|
|
135 |
(Tools::NewSystemBrowser open)
|
|
136 |
switchToClass:BTree;
|
|
137 |
showCoverageInformation value:true
|
|
138 |
"
|
|
139 |
|
|
140 |
"Created: / 08-08-2011 / 15:47:10 / cg"
|
|
141 |
! !
|
|
142 |
|
2664
|
143 |
!InstrumentationContext class methodsFor:'utilities'!
|
|
144 |
|
2942
|
145 |
flushAllPerProcessInstrumentationContexts
|
|
146 |
Process allInstancesDo:[:eachProcess |
|
|
147 |
eachProcess environmentAt:#instrumentationContext put:nil
|
|
148 |
].
|
|
149 |
|
|
150 |
"
|
|
151 |
self flushAllPerProcessInstrumentationContexts
|
|
152 |
"
|
|
153 |
!
|
|
154 |
|
|
155 |
globalInstrumentationContext
|
|
156 |
^ GlobalInstrumentationContext
|
|
157 |
!
|
|
158 |
|
2706
|
159 |
setGlobalInstrumentationContext:aContextOrNil
|
|
160 |
"setup for global instrumentation: instrumentation is performed for all processes"
|
|
161 |
|
|
162 |
GlobalInstrumentationContext := aContextOrNil.
|
2874
|
163 |
LastInstrumentationContext := LastProcess := nil.
|
2706
|
164 |
|
|
165 |
"Created: / 21-09-2011 / 19:07:00 / cg"
|
|
166 |
!
|
|
167 |
|
2664
|
168 |
setInstrumentationContext:aContextOrNil in:aProcess
|
2706
|
169 |
"setup for process specific instrumentation:
|
|
170 |
instrumentation is aProcess"
|
|
171 |
|
2664
|
172 |
"in order to keep the knowledge about which environment-variable is used
|
|
173 |
at least local..."
|
|
174 |
|
2706
|
175 |
aProcess environmentAt:#instrumentationContext put:aContextOrNil.
|
2874
|
176 |
LastInstrumentationContext := LastProcess := nil.
|
2664
|
177 |
|
|
178 |
"Created: / 17-08-2011 / 11:53:19 / cg"
|
|
179 |
! !
|
|
180 |
|
2629
|
181 |
!InstrumentationContext methodsFor:'accessing'!
|
|
182 |
|
2710
|
183 |
coverageOnly
|
|
184 |
"if on, only keep track of coverage (not counting);
|
2874
|
185 |
if off, we also count how often the code has been entered,
|
|
186 |
and by which sender"
|
2710
|
187 |
|
2945
|
188 |
^ coverageOnly ? true
|
2710
|
189 |
|
|
190 |
"Created: / 23-08-2011 / 21:25:46 / cg"
|
|
191 |
!
|
|
192 |
|
|
193 |
coverageOnly:aBoolean
|
|
194 |
"if on, only keep track of coverage (not counting);
|
|
195 |
if off, we also count how often the code has been entered"
|
|
196 |
|
|
197 |
coverageOnly := aBoolean.
|
|
198 |
|
|
199 |
"Created: / 23-08-2011 / 21:25:37 / cg"
|
|
200 |
!
|
|
201 |
|
2629
|
202 |
enabled
|
|
203 |
^ enabled
|
|
204 |
!
|
|
205 |
|
|
206 |
enabled:aBoolean
|
|
207 |
enabled := aBoolean.
|
|
208 |
|
|
209 |
"Modified (format): / 08-08-2011 / 14:47:12 / cg"
|
|
210 |
!
|
|
211 |
|
|
212 |
inInstrumentedCode
|
|
213 |
^ inInstrumentedCode ? false
|
|
214 |
|
|
215 |
"Modified: / 07-08-2011 / 16:57:15 / cg"
|
|
216 |
!
|
|
217 |
|
|
218 |
inInstrumentedCode:aBoolean
|
|
219 |
inInstrumentedCode := aBoolean.
|
|
220 |
|
|
221 |
"Modified (format): / 08-08-2011 / 19:43:19 / cg"
|
|
222 |
! !
|
|
223 |
|
|
224 |
!InstrumentationContext methodsFor:'initialization'!
|
|
225 |
|
|
226 |
initialize
|
|
227 |
"Invoked when a new instance is created."
|
|
228 |
|
|
229 |
inInstrumentedCode := false.
|
|
230 |
enabled := true.
|
|
231 |
|
|
232 |
"/ super initialize. -- commented since inherited method does nothing
|
|
233 |
|
|
234 |
"Modified: / 08-08-2011 / 15:44:59 / cg"
|
|
235 |
! !
|
|
236 |
|
|
237 |
!InstrumentationContext methodsFor:'installing'!
|
|
238 |
|
2706
|
239 |
beActiveEverywhere
|
|
240 |
"become the current instrumentaion context for all processes."
|
|
241 |
|
|
242 |
self class setGlobalInstrumentationContext:self.
|
2874
|
243 |
LastInstrumentationContext := LastProcess := nil.
|
2706
|
244 |
|
|
245 |
"
|
|
246 |
InstrumentationContext new beActiveEverywhere
|
|
247 |
"
|
|
248 |
|
|
249 |
"Created: / 21-09-2011 / 19:08:43 / cg"
|
|
250 |
!
|
|
251 |
|
2629
|
252 |
beActiveIn:aProcess
|
|
253 |
"become the current instrumentaion context for a process."
|
|
254 |
|
2672
|
255 |
self class setInstrumentationContext:self in:aProcess.
|
2874
|
256 |
LastInstrumentationContext := LastProcess := nil.
|
2629
|
257 |
|
|
258 |
"
|
|
259 |
InstrumentationContext new beActiveIn:(Processor activeProcess)
|
|
260 |
"
|
|
261 |
|
|
262 |
"Created: / 08-08-2011 / 14:46:09 / cg"
|
|
263 |
! !
|
|
264 |
|
|
265 |
!InstrumentationContext methodsFor:'queries'!
|
|
266 |
|
|
267 |
enabledAndNotInInstrumentedCode
|
|
268 |
^ enabled and:[ inInstrumentedCode not ]
|
|
269 |
|
|
270 |
"Created: / 08-08-2011 / 15:44:30 / cg"
|
|
271 |
! !
|
|
272 |
|
2657
|
273 |
!InstrumentationContext methodsFor:'running'!
|
|
274 |
|
|
275 |
run:aBlock
|
|
276 |
"run aBlock with instrumentation enabled"
|
|
277 |
|
2664
|
278 |
|activeProcess|
|
|
279 |
|
|
280 |
activeProcess := Processor activeProcess.
|
|
281 |
|
2657
|
282 |
[
|
2664
|
283 |
self beActiveIn:activeProcess.
|
2657
|
284 |
aBlock value
|
|
285 |
] ensure:[
|
2664
|
286 |
self class setInstrumentationContext:nil in:activeProcess
|
2657
|
287 |
].
|
2664
|
288 |
|
|
289 |
"Modified: / 17-08-2011 / 11:53:54 / cg"
|
2657
|
290 |
! !
|
|
291 |
|
2629
|
292 |
!InstrumentationContext class methodsFor:'documentation'!
|
|
293 |
|
|
294 |
version
|
2945
|
295 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.10 2012-10-17 23:40:02 cg Exp $'
|
2629
|
296 |
!
|
|
297 |
|
|
298 |
version_CVS
|
2945
|
299 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.10 2012-10-17 23:40:02 cg Exp $'
|
2629
|
300 |
! !
|