Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Probe.java @ 21684:c072fbce5756
Truffle/Instrumentation: move Probe tracing out of DebugEngine and into Probe
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 02 Jun 2015 16:44:16 -0700 |
parents | d6d9631eb057 |
children | fd8a92655fbd |
comparison
equal
deleted
inserted
replaced
21670:5731adc3a10a | 21684:c072fbce5756 |
---|---|
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.api.instrument; | 25 package com.oracle.truffle.api.instrument; |
26 | 26 |
27 import java.io.*; | |
27 import java.lang.ref.*; | 28 import java.lang.ref.*; |
28 import java.util.*; | 29 import java.util.*; |
29 | 30 |
30 import com.oracle.truffle.api.*; | 31 import com.oracle.truffle.api.*; |
31 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; | 32 import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; |
98 * @see ProbeListener | 99 * @see ProbeListener |
99 * @see SyntaxTag | 100 * @see SyntaxTag |
100 */ | 101 */ |
101 public final class Probe { | 102 public final class Probe { |
102 | 103 |
104 private static final boolean TRACE = false; | |
105 private static final String TRACE_PREFIX = "PROBE: "; | |
106 private static final PrintStream OUT = System.out; | |
107 | |
108 private static void trace(String format, Object... args) { | |
109 if (TRACE) { | |
110 OUT.println(TRACE_PREFIX + String.format(format, args)); | |
111 } | |
112 } | |
113 | |
103 private static final List<ASTProber> astProbers = new ArrayList<>(); | 114 private static final List<ASTProber> astProbers = new ArrayList<>(); |
104 | 115 |
105 private static final List<ProbeListener> probeListeners = new ArrayList<>(); | 116 private static final List<ProbeListener> probeListeners = new ArrayList<>(); |
106 | 117 |
107 /** | 118 /** |
161 * {@link ASTProber}. | 172 * {@link ASTProber}. |
162 */ | 173 */ |
163 public static void applyASTProbers(Node node) { | 174 public static void applyASTProbers(Node node) { |
164 | 175 |
165 final Source source = findSource(node); | 176 final Source source = findSource(node); |
166 | 177 final String sourceName = source == null ? "<?>" : source.getShortName(); |
178 trace("START %s", sourceName); | |
167 for (ProbeListener listener : probeListeners) { | 179 for (ProbeListener listener : probeListeners) { |
168 listener.startASTProbing(source); | 180 listener.startASTProbing(source); |
169 } | 181 } |
170 for (ASTProber prober : astProbers) { | 182 for (ASTProber prober : astProbers) { |
171 prober.probeAST(node); | 183 prober.probeAST(node); |
172 } | 184 } |
173 for (ProbeListener listener : probeListeners) { | 185 for (ProbeListener listener : probeListeners) { |
174 listener.endASTProbing(source); | 186 listener.endASTProbing(source); |
175 } | 187 } |
188 trace("FINISHED %s", sourceName); | |
176 } | 189 } |
177 | 190 |
178 /** | 191 /** |
179 * Adds a {@link ProbeListener} to receive events. | 192 * Adds a {@link ProbeListener} to receive events. |
180 */ | 193 */ |
284 */ | 297 */ |
285 Probe(ProbeNode probeNode, SourceSection sourceSection) { | 298 Probe(ProbeNode probeNode, SourceSection sourceSection) { |
286 this.sourceSection = sourceSection; | 299 this.sourceSection = sourceSection; |
287 probes.add(new WeakReference<>(this)); | 300 probes.add(new WeakReference<>(this)); |
288 registerProbeNodeClone(probeNode); | 301 registerProbeNodeClone(probeNode); |
302 if (TRACE) { | |
303 final String location = this.sourceSection == null ? "<unknown>" : sourceSection.getShortDescription(); | |
304 trace("ADDED %s %s %s", "Probe@", location, getTagsDescription()); | |
305 } | |
289 for (ProbeListener listener : probeListeners) { | 306 for (ProbeListener listener : probeListeners) { |
290 listener.newProbeInserted(this); | 307 listener.newProbeInserted(this); |
291 } | 308 } |
292 } | 309 } |
293 | 310 |
329 this.isAfterTrapActive = true; | 346 this.isAfterTrapActive = true; |
330 tagTrapsChanged = true; | 347 tagTrapsChanged = true; |
331 } | 348 } |
332 if (tagTrapsChanged) { | 349 if (tagTrapsChanged) { |
333 invalidateProbeUnchanged(); | 350 invalidateProbeUnchanged(); |
351 } | |
352 if (TRACE) { | |
353 trace("TAGGED as %s: %s", tag, getShortDescription()); | |
334 } | 354 } |
335 } | 355 } |
336 } | 356 } |
337 | 357 |
338 /** | 358 /** |