author | Claus Gittinger <cg@exept.de> |
Thu, 08 Nov 2012 01:10:10 +0100 | |
changeset 2980 | 0202d500e04d |
parent 2979 | e4ccf860e34a |
child 3453 | ffbbed0fe172 |
permissions | -rw-r--r-- |
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 |
|
2959
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
42 |
instrumentation is ongoing. |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
43 |
|
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
44 |
Especially, instrumentationInfo objects are only updated in processes with a context. |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
45 |
This has two advantages: |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
46 |
- it blocks recursive calls, while inside instrumentation code |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
47 |
- it blocks measurements from other processes |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
48 |
(so code coverage is only measured when executed during a test run, not if |
9c8cf9e9915f
comment/format in: #documentation
Claus Gittinger <cg@exept.de>
parents:
2945
diff
changeset
|
49 |
executed by other processes) |
2979
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
50 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
51 |
the main entries are run: and runForCoverage: |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
52 |
the code must have been recompiled with instrumentation before |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
53 |
(see InstrumentingCompiler - class protocol) |
2629 | 54 |
" |
55 |
! ! |
|
56 |
||
57 |
!InstrumentationContext class methodsFor:'instance creation'! |
|
58 |
||
59 |
new |
|
60 |
"return an initialized instance" |
|
61 |
||
62 |
^ self basicNew initialize. |
|
63 |
! ! |
|
64 |
||
65 |
!InstrumentationContext class methodsFor:'instance access'! |
|
66 |
||
67 |
current |
|
2664 | 68 |
"the current context for this running thread. |
69 |
walks along the parent-process chain, up to a possible global context" |
|
2629 | 70 |
|
2664 | 71 |
^ self forProcess:(Processor activeProcess) |
2629 | 72 |
|
73 |
" |
|
74 |
InstrumentationContext current |
|
75 |
" |
|
76 |
||
77 |
"Created: / 08-08-2011 / 14:44:11 / cg" |
|
2664 | 78 |
! |
79 |
||
80 |
forProcess:aProcess |
|
81 |
"the context for this thread. |
|
82 |
walks along the parent-process chain, up to a possible global context" |
|
83 |
||
84 |
|p context| |
|
85 |
||
2874 | 86 |
aProcess == LastProcess ifTrue:[ |
87 |
^ LastInstrumentationContext |
|
2664 | 88 |
]. |
89 |
||
2874 | 90 |
"/ future (need a faster parentProcess query) |
91 |
p := aProcess. |
|
92 |
[p notNil] whileTrue:[ |
|
93 |
context := p environmentAt:#instrumentationContext ifAbsent:nil. |
|
94 |
context notNil ifTrue:[ |
|
95 |
aProcess environmentAt:#instrumentationContext put:context. |
|
96 |
context == 0 ifTrue:[ |
|
97 |
context := nil. |
|
2664 | 98 |
]. |
2874 | 99 |
LastProcess := aProcess. |
100 |
LastInstrumentationContext := context. |
|
101 |
^ context |
|
2664 | 102 |
]. |
2874 | 103 |
p := p parentProcess |
2664 | 104 |
]. |
2874 | 105 |
aProcess environmentAt:#instrumentationContext put:(GlobalInstrumentationContext ? 0). "/ could be nil |
106 |
LastProcess := aProcess. |
|
107 |
LastInstrumentationContext := GlobalInstrumentationContext. |
|
108 |
^ GlobalInstrumentationContext. |
|
2664 | 109 |
|
110 |
" |
|
111 |
InstrumentationContext current |
|
112 |
" |
|
113 |
||
114 |
"Created: / 17-08-2011 / 11:29:51 / cg" |
|
2629 | 115 |
! ! |
116 |
||
2706 | 117 |
!InstrumentationContext class methodsFor:'queries'! |
118 |
||
119 |
hasGlobalInstrumentationContext |
|
120 |
^ GlobalInstrumentationContext notNil |
|
121 |
||
122 |
" |
|
123 |
InstrumentationContext hasGlobalInstrumentationContext |
|
124 |
" |
|
125 |
||
126 |
"Created: / 21-09-2011 / 19:15:51 / cg" |
|
127 |
! ! |
|
128 |
||
2629 | 129 |
!InstrumentationContext class methodsFor:'running'! |
130 |
||
131 |
run:aBlock |
|
132 |
"run aBlock with instrumentation enabled" |
|
133 |
||
2657 | 134 |
self new run:aBlock. |
2629 | 135 |
|
136 |
" |
|
137 |
Smalltalk loadPackage:'exept:regression'. |
|
138 |
BTree withAllPrivateClasses |
|
139 |
do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler]. |
|
140 |
InstrumentationContext |
|
141 |
run:[ RegressionTests::BinaryTreeTester suite run ]. |
|
142 |
(Tools::NewSystemBrowser open) |
|
143 |
switchToClass:BTree; |
|
144 |
showCoverageInformation value:true |
|
145 |
" |
|
146 |
||
147 |
"Created: / 08-08-2011 / 15:47:10 / cg" |
|
2979
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
148 |
! |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
149 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
150 |
runForCoverage:aBlock |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
151 |
"run aBlock with instrumentation enabled, but only for coverage (i.e. not counting)" |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
152 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
153 |
self new runForCoverage:aBlock. |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
154 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
155 |
" |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
156 |
Smalltalk loadPackage:'exept:regression'. |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
157 |
BTree withAllPrivateClasses |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
158 |
do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler]. |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
159 |
InstrumentationContext |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
160 |
run:[ RegressionTests::BinaryTreeTester suite run ]. |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
161 |
(Tools::NewSystemBrowser open) |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
162 |
switchToClass:BTree; |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
163 |
showCoverageInformation value:true |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
164 |
" |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
165 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
166 |
"Created: / 08-08-2011 / 15:47:10 / cg" |
2629 | 167 |
! ! |
168 |
||
2664 | 169 |
!InstrumentationContext class methodsFor:'utilities'! |
170 |
||
2942 | 171 |
flushAllPerProcessInstrumentationContexts |
172 |
Process allInstancesDo:[:eachProcess | |
|
173 |
eachProcess environmentAt:#instrumentationContext put:nil |
|
174 |
]. |
|
175 |
||
176 |
" |
|
177 |
self flushAllPerProcessInstrumentationContexts |
|
178 |
" |
|
179 |
! |
|
180 |
||
181 |
globalInstrumentationContext |
|
182 |
^ GlobalInstrumentationContext |
|
183 |
! |
|
184 |
||
2706 | 185 |
setGlobalInstrumentationContext:aContextOrNil |
186 |
"setup for global instrumentation: instrumentation is performed for all processes" |
|
187 |
||
188 |
GlobalInstrumentationContext := aContextOrNil. |
|
2874 | 189 |
LastInstrumentationContext := LastProcess := nil. |
2706 | 190 |
|
191 |
"Created: / 21-09-2011 / 19:07:00 / cg" |
|
192 |
! |
|
193 |
||
2664 | 194 |
setInstrumentationContext:aContextOrNil in:aProcess |
2706 | 195 |
"setup for process specific instrumentation: |
196 |
instrumentation is aProcess" |
|
197 |
||
2664 | 198 |
"in order to keep the knowledge about which environment-variable is used |
199 |
at least local..." |
|
200 |
||
2706 | 201 |
aProcess environmentAt:#instrumentationContext put:aContextOrNil. |
2874 | 202 |
LastInstrumentationContext := LastProcess := nil. |
2664 | 203 |
|
204 |
"Created: / 17-08-2011 / 11:53:19 / cg" |
|
205 |
! ! |
|
206 |
||
2629 | 207 |
!InstrumentationContext methodsFor:'accessing'! |
208 |
||
2710 | 209 |
coverageOnly |
210 |
"if on, only keep track of coverage (not counting); |
|
2874 | 211 |
if off, we also count how often the code has been entered, |
212 |
and by which sender" |
|
2710 | 213 |
|
2980
0202d500e04d
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2979
diff
changeset
|
214 |
^ coverageOnly ? false |
2710 | 215 |
|
216 |
"Created: / 23-08-2011 / 21:25:46 / cg" |
|
217 |
! |
|
218 |
||
219 |
coverageOnly:aBoolean |
|
220 |
"if on, only keep track of coverage (not counting); |
|
221 |
if off, we also count how often the code has been entered" |
|
222 |
||
223 |
coverageOnly := aBoolean. |
|
224 |
||
225 |
"Created: / 23-08-2011 / 21:25:37 / cg" |
|
226 |
! |
|
227 |
||
2629 | 228 |
enabled |
229 |
^ enabled |
|
230 |
! |
|
231 |
||
232 |
enabled:aBoolean |
|
233 |
enabled := aBoolean. |
|
234 |
||
235 |
"Modified (format): / 08-08-2011 / 14:47:12 / cg" |
|
236 |
! |
|
237 |
||
238 |
inInstrumentedCode |
|
239 |
^ inInstrumentedCode ? false |
|
240 |
||
241 |
"Modified: / 07-08-2011 / 16:57:15 / cg" |
|
242 |
! |
|
243 |
||
244 |
inInstrumentedCode:aBoolean |
|
245 |
inInstrumentedCode := aBoolean. |
|
246 |
||
247 |
"Modified (format): / 08-08-2011 / 19:43:19 / cg" |
|
248 |
! ! |
|
249 |
||
250 |
!InstrumentationContext methodsFor:'initialization'! |
|
251 |
||
252 |
initialize |
|
253 |
"Invoked when a new instance is created." |
|
254 |
||
255 |
inInstrumentedCode := false. |
|
256 |
enabled := true. |
|
257 |
||
258 |
"/ super initialize. -- commented since inherited method does nothing |
|
259 |
||
260 |
"Modified: / 08-08-2011 / 15:44:59 / cg" |
|
261 |
! ! |
|
262 |
||
263 |
!InstrumentationContext methodsFor:'installing'! |
|
264 |
||
2706 | 265 |
beActiveEverywhere |
266 |
"become the current instrumentaion context for all processes." |
|
267 |
||
268 |
self class setGlobalInstrumentationContext:self. |
|
2874 | 269 |
LastInstrumentationContext := LastProcess := nil. |
2706 | 270 |
|
271 |
" |
|
272 |
InstrumentationContext new beActiveEverywhere |
|
273 |
" |
|
274 |
||
275 |
"Created: / 21-09-2011 / 19:08:43 / cg" |
|
276 |
! |
|
277 |
||
2629 | 278 |
beActiveIn:aProcess |
279 |
"become the current instrumentaion context for a process." |
|
280 |
||
2672 | 281 |
self class setInstrumentationContext:self in:aProcess. |
2874 | 282 |
LastInstrumentationContext := LastProcess := nil. |
2629 | 283 |
|
284 |
" |
|
285 |
InstrumentationContext new beActiveIn:(Processor activeProcess) |
|
286 |
" |
|
287 |
||
288 |
"Created: / 08-08-2011 / 14:46:09 / cg" |
|
289 |
! ! |
|
290 |
||
291 |
!InstrumentationContext methodsFor:'queries'! |
|
292 |
||
293 |
enabledAndNotInInstrumentedCode |
|
294 |
^ enabled and:[ inInstrumentedCode not ] |
|
295 |
||
296 |
"Created: / 08-08-2011 / 15:44:30 / cg" |
|
297 |
! ! |
|
298 |
||
2657 | 299 |
!InstrumentationContext methodsFor:'running'! |
300 |
||
301 |
run:aBlock |
|
302 |
"run aBlock with instrumentation enabled" |
|
303 |
||
2664 | 304 |
|activeProcess| |
305 |
||
306 |
activeProcess := Processor activeProcess. |
|
307 |
||
2657 | 308 |
[ |
2664 | 309 |
self beActiveIn:activeProcess. |
2657 | 310 |
aBlock value |
311 |
] ensure:[ |
|
2664 | 312 |
self class setInstrumentationContext:nil in:activeProcess |
2657 | 313 |
]. |
2664 | 314 |
|
315 |
"Modified: / 17-08-2011 / 11:53:54 / cg" |
|
2979
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
316 |
! |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
317 |
|
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
318 |
runForCoverage:aBlock |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
319 |
"run aBlock with instrumentation enabled< but onlz for coverage (i.e. not counting)" |
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
320 |
|
2980
0202d500e04d
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2979
diff
changeset
|
321 |
coverageOnly := true. |
2979
e4ccf860e34a
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2959
diff
changeset
|
322 |
self run:aBlock |
2657 | 323 |
! ! |
324 |
||
2629 | 325 |
!InstrumentationContext class methodsFor:'documentation'! |
326 |
||
327 |
version |
|
2980
0202d500e04d
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2979
diff
changeset
|
328 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.13 2012-11-08 00:10:10 cg Exp $' |
2629 | 329 |
! |
330 |
||
331 |
version_CVS |
|
2980
0202d500e04d
class: InstrumentationContext
Claus Gittinger <cg@exept.de>
parents:
2979
diff
changeset
|
332 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.13 2012-11-08 00:10:10 cg Exp $' |
2629 | 333 |
! ! |