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