Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.tools/src/com/oracle/truffle/tools/CoverageTracker.java @ 22093:0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 17 Aug 2015 15:24:00 -0700 |
parents | b2d1c8ff592a |
children | dc83cc1f94f2 3aad794eec0e |
comparison
equal
deleted
inserted
replaced
22092:1a1aa12ab310 | 22093:0f0e34039769 |
---|---|
37 * An {@link InstrumentationTool} that counts interpreter <em>execution calls</em> to AST nodes that | 37 * An {@link InstrumentationTool} that counts interpreter <em>execution calls</em> to AST nodes that |
38 * hold a specified {@linkplain SyntaxTag syntax tag}, tabulated by source and line number | 38 * hold a specified {@linkplain SyntaxTag syntax tag}, tabulated by source and line number |
39 * associated with each node. Syntax tags are presumed to be applied external to the tool. If no tag | 39 * associated with each node. Syntax tags are presumed to be applied external to the tool. If no tag |
40 * is specified, {@linkplain StandardSyntaxTag#STATEMENT STATEMENT} is used, corresponding to | 40 * is specified, {@linkplain StandardSyntaxTag#STATEMENT STATEMENT} is used, corresponding to |
41 * conventional behavior for code coverage tools. | 41 * conventional behavior for code coverage tools. |
42 * <p> | |
43 * No counts will be kept for execution in sources that hold the {@link SourceTag} | |
44 * {@link Tags#NO_COVERAGE}. | |
45 * <p> | 42 * <p> |
46 * <b>Tool Life Cycle</b> | 43 * <b>Tool Life Cycle</b> |
47 * <p> | 44 * <p> |
48 * See {@link InstrumentationTool} for the life cycle common to all such tools. | 45 * See {@link InstrumentationTool} for the life cycle common to all such tools. |
49 * <p> | 46 * <p> |
70 * | 67 * |
71 * @see Instrument | 68 * @see Instrument |
72 * @see SyntaxTag | 69 * @see SyntaxTag |
73 */ | 70 */ |
74 public final class CoverageTracker extends InstrumentationTool { | 71 public final class CoverageTracker extends InstrumentationTool { |
75 | |
76 public enum Tags implements SourceTag { | |
77 | |
78 /** | |
79 * Report no counts for sources holding this tag. | |
80 */ | |
81 NO_COVERAGE("No Coverage", "Coverage Tracker will igore"); | |
82 | |
83 private final String name; | |
84 private final String description; | |
85 | |
86 private Tags(String name, String description) { | |
87 this.name = name; | |
88 this.description = description; | |
89 } | |
90 | |
91 public String getName() { | |
92 return name; | |
93 } | |
94 | |
95 public String getDescription() { | |
96 return description; | |
97 } | |
98 } | |
99 | 72 |
100 /** Counting data. */ | 73 /** Counting data. */ |
101 private final Map<LineLocation, CoverageRecord> coverageMap = new HashMap<>(); | 74 private final Map<LineLocation, CoverageRecord> coverageMap = new HashMap<>(); |
102 | 75 |
103 /** Needed for disposal. */ | 76 /** Needed for disposal. */ |
289 if (countingTag == tag) { | 262 if (countingTag == tag) { |
290 | 263 |
291 final SourceSection srcSection = probe.getProbedSourceSection(); | 264 final SourceSection srcSection = probe.getProbedSourceSection(); |
292 if (srcSection == null) { | 265 if (srcSection == null) { |
293 // TODO (mlvdv) report this? | 266 // TODO (mlvdv) report this? |
294 } else if (!srcSection.getSource().isTaggedAs(Tags.NO_COVERAGE)) { | 267 return; |
295 // Get the source line where the | 268 } |
296 final LineLocation lineLocation = srcSection.getLineLocation(); | 269 // Get the source line where the |
297 CoverageRecord record = coverageMap.get(lineLocation); | 270 final LineLocation lineLocation = srcSection.getLineLocation(); |
298 if (record != null) { | 271 CoverageRecord record = coverageMap.get(lineLocation); |
299 // Another node starts on same line; count only the first (textually) | 272 if (record != null) { |
300 if (srcSection.getCharIndex() > record.srcSection.getCharIndex()) { | 273 // Another node starts on same line; count only the first (textually) |
301 // Existing record, corresponds to code earlier on line | 274 if (srcSection.getCharIndex() > record.srcSection.getCharIndex()) { |
302 return; | 275 // Existing record, corresponds to code earlier on line |
303 } else { | 276 return; |
304 // Existing record, corresponds to code at a later position; replace it | 277 } else { |
305 record.instrument.dispose(); | 278 // Existing record, corresponds to code at a later position; replace it |
306 } | 279 record.instrument.dispose(); |
307 } | 280 } |
308 | 281 } |
309 final CoverageRecord coverage = new CoverageRecord(srcSection); | 282 |
310 final Instrument instrument = Instrument.create(coverage, CoverageTracker.class.getSimpleName()); | 283 final CoverageRecord coverage = new CoverageRecord(srcSection); |
311 coverage.instrument = instrument; | 284 final Instrument instrument = Instrument.create(coverage, CoverageTracker.class.getSimpleName()); |
312 instruments.add(instrument); | 285 coverage.instrument = instrument; |
313 probe.attach(instrument); | 286 instruments.add(instrument); |
314 coverageMap.put(lineLocation, coverage); | 287 probe.attach(instrument); |
315 } | 288 coverageMap.put(lineLocation, coverage); |
316 } | 289 } |
317 } | 290 } |
318 } | 291 } |
319 | 292 |
320 } | 293 } |