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
|
|
15 |
instanceVariableNames:'inInstrumentedCode enabled'
|
2664
|
16 |
classVariableNames:'CachedProcessToInstrumentationContextMapping
|
|
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 |
|
|
79 |
CachedProcessToInstrumentationContextMapping isNil ifTrue:[
|
|
80 |
CachedProcessToInstrumentationContextMapping := WeakIdentityDictionary new.
|
|
81 |
].
|
|
82 |
|
|
83 |
context := CachedProcessToInstrumentationContextMapping at:aProcess ifAbsent:nil.
|
|
84 |
context == 0 ifTrue:[ ^ nil]. "/ special entry for a known nil value
|
|
85 |
context isNil ifTrue:[
|
|
86 |
"/ future (need a faster parentProcess query)
|
|
87 |
p := aProcess.
|
|
88 |
[p notNil] whileTrue:[
|
|
89 |
context := p environmentAt:#instrumentationContext ifAbsent:nil.
|
|
90 |
context notNil ifTrue:[
|
|
91 |
CachedProcessToInstrumentationContextMapping at:aProcess put:context.
|
|
92 |
^ context
|
|
93 |
].
|
|
94 |
p := p parentProcess
|
|
95 |
].
|
|
96 |
CachedProcessToInstrumentationContextMapping at:aProcess put:(GlobalInstrumentationContext ? 0). "/ known to be nil
|
|
97 |
context := GlobalInstrumentationContext.
|
|
98 |
].
|
|
99 |
^ context
|
|
100 |
|
|
101 |
"
|
|
102 |
InstrumentationContext current
|
|
103 |
"
|
|
104 |
|
|
105 |
"Created: / 17-08-2011 / 11:29:51 / cg"
|
2629
|
106 |
! !
|
|
107 |
|
|
108 |
!InstrumentationContext class methodsFor:'running'!
|
|
109 |
|
|
110 |
run:aBlock
|
|
111 |
"run aBlock with instrumentation enabled"
|
|
112 |
|
2657
|
113 |
self new run:aBlock.
|
2629
|
114 |
|
|
115 |
"
|
|
116 |
Smalltalk loadPackage:'exept:regression'.
|
|
117 |
BTree withAllPrivateClasses
|
|
118 |
do:[:cls | cls recompileUsingCompilerClass:InstrumentingCompiler].
|
|
119 |
InstrumentationContext
|
|
120 |
run:[ RegressionTests::BinaryTreeTester suite run ].
|
|
121 |
(Tools::NewSystemBrowser open)
|
|
122 |
switchToClass:BTree;
|
|
123 |
showCoverageInformation value:true
|
|
124 |
"
|
|
125 |
|
|
126 |
"Created: / 08-08-2011 / 15:47:10 / cg"
|
|
127 |
! !
|
|
128 |
|
2664
|
129 |
!InstrumentationContext class methodsFor:'utilities'!
|
|
130 |
|
|
131 |
setInstrumentationContext:aContextOrNil in:aProcess
|
|
132 |
"in order to keep the knowledge about which environment-variable is used
|
|
133 |
at least local..."
|
|
134 |
|
|
135 |
aProcess environmentAt:#instrumentationContext put:aContextOrNil
|
|
136 |
|
|
137 |
"Created: / 17-08-2011 / 11:53:19 / cg"
|
|
138 |
! !
|
|
139 |
|
2629
|
140 |
!InstrumentationContext methodsFor:'accessing'!
|
|
141 |
|
|
142 |
enabled
|
|
143 |
^ enabled
|
|
144 |
!
|
|
145 |
|
|
146 |
enabled:aBoolean
|
|
147 |
enabled := aBoolean.
|
|
148 |
|
|
149 |
"Modified (format): / 08-08-2011 / 14:47:12 / cg"
|
|
150 |
!
|
|
151 |
|
|
152 |
inInstrumentedCode
|
|
153 |
^ inInstrumentedCode ? false
|
|
154 |
|
|
155 |
"Modified: / 07-08-2011 / 16:57:15 / cg"
|
|
156 |
!
|
|
157 |
|
|
158 |
inInstrumentedCode:aBoolean
|
|
159 |
inInstrumentedCode := aBoolean.
|
|
160 |
|
|
161 |
"Modified (format): / 08-08-2011 / 19:43:19 / cg"
|
|
162 |
! !
|
|
163 |
|
|
164 |
!InstrumentationContext methodsFor:'initialization'!
|
|
165 |
|
|
166 |
initialize
|
|
167 |
"Invoked when a new instance is created."
|
|
168 |
|
|
169 |
inInstrumentedCode := false.
|
|
170 |
enabled := true.
|
|
171 |
|
|
172 |
"/ super initialize. -- commented since inherited method does nothing
|
|
173 |
|
|
174 |
"Modified: / 08-08-2011 / 15:44:59 / cg"
|
|
175 |
! !
|
|
176 |
|
|
177 |
!InstrumentationContext methodsFor:'installing'!
|
|
178 |
|
|
179 |
beActiveIn:aProcess
|
|
180 |
"become the current instrumentaion context for a process."
|
|
181 |
|
2664
|
182 |
self class setInstrumentationContext:self in:aProcess
|
2629
|
183 |
|
|
184 |
"
|
|
185 |
InstrumentationContext new beActiveIn:(Processor activeProcess)
|
|
186 |
"
|
|
187 |
|
|
188 |
"Created: / 08-08-2011 / 14:46:09 / cg"
|
|
189 |
! !
|
|
190 |
|
|
191 |
!InstrumentationContext methodsFor:'queries'!
|
|
192 |
|
|
193 |
enabledAndNotInInstrumentedCode
|
|
194 |
^ enabled and:[ inInstrumentedCode not ]
|
|
195 |
|
|
196 |
"Created: / 08-08-2011 / 15:44:30 / cg"
|
|
197 |
! !
|
|
198 |
|
2657
|
199 |
!InstrumentationContext methodsFor:'running'!
|
|
200 |
|
|
201 |
run:aBlock
|
|
202 |
"run aBlock with instrumentation enabled"
|
|
203 |
|
2664
|
204 |
|activeProcess|
|
|
205 |
|
|
206 |
activeProcess := Processor activeProcess.
|
|
207 |
|
2657
|
208 |
[
|
2664
|
209 |
self beActiveIn:activeProcess.
|
2657
|
210 |
aBlock value
|
|
211 |
] ensure:[
|
2664
|
212 |
self class setInstrumentationContext:nil in:activeProcess
|
2657
|
213 |
].
|
2664
|
214 |
|
|
215 |
"Modified: / 17-08-2011 / 11:53:54 / cg"
|
2657
|
216 |
! !
|
|
217 |
|
2629
|
218 |
!InstrumentationContext class methodsFor:'documentation'!
|
|
219 |
|
|
220 |
version
|
2664
|
221 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.3 2011-08-17 14:32:52 cg Exp $'
|
2629
|
222 |
!
|
|
223 |
|
|
224 |
version_CVS
|
2664
|
225 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.3 2011-08-17 14:32:52 cg Exp $'
|
2629
|
226 |
! !
|