Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/NodeExecCounter.java @ 22219:1c0f490984d5
Merge with f47b601edbc626dcfe8b3636933b4834c89f7779
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Wed, 16 Sep 2015 15:36:22 -0700 |
parents | dc83cc1f94f2 3aad794eec0e |
children | 20380d1d41f2 |
comparison
equal
deleted
inserted
replaced
22160:0599e2df6a9f | 22219:1c0f490984d5 |
---|---|
22 * or visit www.oracle.com if you need additional information or have any | 22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. | 23 * questions. |
24 */ | 24 */ |
25 package com.oracle.truffle.tools; | 25 package com.oracle.truffle.tools; |
26 | 26 |
27 import java.io.PrintStream; | |
28 import java.util.ArrayList; | |
29 import java.util.Arrays; | |
30 import java.util.Collection; | |
31 import java.util.Comparator; | |
32 import java.util.HashMap; | |
33 import java.util.List; | |
34 import java.util.Map; | |
35 import java.util.concurrent.atomic.AtomicLong; | |
36 | |
27 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; | 37 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; |
28 import com.oracle.truffle.api.frame.VirtualFrame; | 38 import com.oracle.truffle.api.frame.VirtualFrame; |
29 import com.oracle.truffle.api.instrument.ASTProber; | 39 import com.oracle.truffle.api.instrument.ASTProber; |
30 import com.oracle.truffle.api.instrument.Instrument; | 40 import com.oracle.truffle.api.instrument.Instrument; |
31 import com.oracle.truffle.api.instrument.InstrumentationTool; | 41 import com.oracle.truffle.api.instrument.InstrumentationTool; |
42 import com.oracle.truffle.api.instrument.Instrumenter; | |
32 import com.oracle.truffle.api.instrument.Probe; | 43 import com.oracle.truffle.api.instrument.Probe; |
33 import com.oracle.truffle.api.instrument.ProbeException; | 44 import com.oracle.truffle.api.instrument.ProbeException; |
34 import com.oracle.truffle.api.instrument.ProbeFailure; | 45 import com.oracle.truffle.api.instrument.ProbeFailure; |
35 import com.oracle.truffle.api.instrument.ProbeListener; | 46 import com.oracle.truffle.api.instrument.ProbeListener; |
36 import com.oracle.truffle.api.instrument.StandardInstrumentListener; | 47 import com.oracle.truffle.api.instrument.StandardInstrumentListener; |
38 import com.oracle.truffle.api.instrument.impl.DefaultProbeListener; | 49 import com.oracle.truffle.api.instrument.impl.DefaultProbeListener; |
39 import com.oracle.truffle.api.instrument.impl.DefaultStandardInstrumentListener; | 50 import com.oracle.truffle.api.instrument.impl.DefaultStandardInstrumentListener; |
40 import com.oracle.truffle.api.nodes.Node; | 51 import com.oracle.truffle.api.nodes.Node; |
41 import com.oracle.truffle.api.nodes.Node.Child; | 52 import com.oracle.truffle.api.nodes.Node.Child; |
42 import com.oracle.truffle.api.nodes.NodeVisitor; | 53 import com.oracle.truffle.api.nodes.NodeVisitor; |
43 import java.io.PrintStream; | |
44 import java.util.ArrayList; | |
45 import java.util.Arrays; | |
46 import java.util.Collection; | |
47 import java.util.Comparator; | |
48 import java.util.HashMap; | |
49 import java.util.List; | |
50 import java.util.Map; | |
51 import java.util.concurrent.atomic.AtomicLong; | |
52 | 54 |
53 /** | 55 /** |
54 * An {@link InstrumentationTool} that counts interpreter <em>execution calls</em> to AST nodes, | 56 * An {@link InstrumentationTool} that counts interpreter <em>execution calls</em> to AST nodes, |
55 * tabulated by the type of called nodes; counting can be enabled <em>all</em> nodes or restricted | 57 * tabulated by the type of called nodes; counting can be enabled <em>all</em> nodes or restricted |
56 * to nodes with a specified {@linkplain SyntaxTag tag} that is presumed to be applied external to | 58 * to nodes with a specified {@linkplain SyntaxTag tag} that is presumed to be applied external to |
168 | 170 |
169 /** | 171 /** |
170 * Create a per node-type execution counting tool for all nodes in subsequently created ASTs. | 172 * Create a per node-type execution counting tool for all nodes in subsequently created ASTs. |
171 */ | 173 */ |
172 public NodeExecCounter() { | 174 public NodeExecCounter() { |
173 this.countingTag = null; | 175 this(null); |
174 } | 176 } |
175 | 177 |
176 /** | 178 /** |
177 * Creates a per-type execution counting for nodes tagged as specified in subsequently created | 179 * Creates a per-type execution counting for nodes tagged as specified in subsequently created |
178 * ASTs. | 180 * ASTs. |
183 | 185 |
184 @Override | 186 @Override |
185 protected boolean internalInstall() { | 187 protected boolean internalInstall() { |
186 if (countingTag == null) { | 188 if (countingTag == null) { |
187 astProber = new ExecCounterASTProber(); | 189 astProber = new ExecCounterASTProber(); |
188 Probe.registerASTProber(astProber); | 190 getInstrumenter().registerASTProber(astProber); |
189 } else { | 191 } else { |
190 probeListener = new NodeExecCounterProbeListener(); | 192 probeListener = new NodeExecCounterProbeListener(); |
191 Probe.addProbeListener(probeListener); | 193 getInstrumenter().addProbeListener(probeListener); |
192 } | 194 } |
193 return true; | 195 return true; |
194 } | 196 } |
195 | 197 |
196 @Override | 198 @Override |
200 } | 202 } |
201 | 203 |
202 @Override | 204 @Override |
203 protected void internalDispose() { | 205 protected void internalDispose() { |
204 if (astProber != null) { | 206 if (astProber != null) { |
205 Probe.unregisterASTProber(astProber); | 207 getInstrumenter().unregisterASTProber(astProber); |
206 } | 208 } |
207 if (probeListener != null) { | 209 if (probeListener != null) { |
208 Probe.removeProbeListener(probeListener); | 210 getInstrumenter().removeProbeListener(probeListener); |
209 } | 211 } |
210 for (Instrument instrument : instruments) { | 212 for (Instrument instrument : instruments) { |
211 instrument.dispose(); | 213 instrument.dispose(); |
212 } | 214 } |
213 } | 215 } |
287 } | 289 } |
288 | 290 |
289 /** | 291 /** |
290 * A prober that attempts to probe and instrument every node. | 292 * A prober that attempts to probe and instrument every node. |
291 */ | 293 */ |
292 private class ExecCounterASTProber implements ASTProber, NodeVisitor { | 294 private class ExecCounterASTProber implements ASTProber { |
293 | 295 |
294 public boolean visit(Node node) { | 296 public void probeAST(final Instrumenter instrumenter, final Node startNode) { |
295 | 297 |
296 if (node.isInstrumentable()) { | 298 startNode.accept(new NodeVisitor() { |
297 try { | 299 |
298 final Instrument instrument = Instrument.create(instrumentListener, "NodeExecCounter"); | 300 public boolean visit(Node node) { |
299 instruments.add(instrument); | 301 |
300 node.probe().attach(instrument); | 302 if (node.isInstrumentable()) { |
301 } catch (ProbeException ex) { | 303 try { |
302 failures.add(ex.getFailure()); | 304 final Instrument instrument = Instrument.create(instrumentListener, "NodeExecCounter"); |
305 instruments.add(instrument); | |
306 instrumenter.probe(node).attach(instrument); | |
307 } catch (ProbeException ex) { | |
308 failures.add(ex.getFailure()); | |
309 } | |
310 } | |
311 return true; | |
303 } | 312 } |
304 } | 313 |
305 return true; | 314 }); |
306 } | |
307 | |
308 public void probeAST(Node node) { | |
309 node.accept(this); | |
310 } | 315 } |
311 } | 316 } |
312 | 317 |
313 /** | 318 /** |
314 * A listener that assumes ASTs have been tagged external to this tool, and which instruments | 319 * A listener that assumes ASTs have been tagged external to this tool, and which instruments |