use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class InputFilterTest method testFilterChildren1.
@Test
public void testFilterChildren1() {
SourceSectionFilter line1 = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).lineStartsIn(IndexRange.between(1, 2)).build();
SourceSectionFilter line2 = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).lineIs(2).build();
String code = "EXPRESSION(\nEXPRESSION(CONSTANT(0)))";
// attach after executing. uses single binding visitor
execute(code);
EventBinding<?> binding = instrumenter.attachExecutionEventFactory(line1, line2, factory);
execute(code);
assertOn(ENTER, (e) -> {
assertCharacters(e, code);
});
assertOn(INPUT_VALUE, (e) -> {
assertCharacters(e, code);
assertEquals("(0)", e.inputValue);
});
assertOn(RETURN_VALUE, (e) -> {
assertCharacters(e, code);
assertArrayEquals(new Object[] { "(0)" }, e.inputs);
assertEquals("((0))", e.result);
});
binding.dispose();
assertCleanedUp(code);
assertAllEventsConsumed();
// attach before executing. uses bindings visitor
binding = instrumenter.attachExecutionEventFactory(line1, line2, factory);
// add space to avoid caching
execute(code + " ");
assertOn(ENTER, (e) -> {
assertCharacters(e, code);
});
assertOn(INPUT_VALUE, (e) -> {
assertCharacters(e, code);
assertEquals("(0)", e.inputValue);
});
assertOn(RETURN_VALUE, (e) -> {
assertCharacters(e, code);
assertArrayEquals(new Object[] { "(0)" }, e.inputs);
assertEquals("((0))", e.result);
});
binding.dispose();
assertCleanedUp(code);
assertAllEventsConsumed();
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class InstrumentableNodeTest method testGetNodeObject.
@Test
public void testGetNodeObject() {
SourceSectionFilter filter = SourceSectionFilter.newBuilder().tagIs(ExpressionTag.class, ConstantTag.class).build();
instrumenter.attachExecutionEventFactory(filter, null, factory);
execute("EXPRESSION(CONSTANT(42))");
assertOn(ENTER, (e) -> {
assertProperties(e.context.getNodeObject(), "simpleName", "ExpressionNode");
});
assertOn(ENTER, (e) -> {
assertProperties(e.context.getNodeObject(), "simpleName", "ConstantNode", "constant", 42);
});
assertOn(RETURN_VALUE, (e) -> {
assertProperties(e.context.getNodeObject(), "simpleName", "ConstantNode", "constant", 42);
});
assertOn(RETURN_VALUE, (e) -> {
assertProperties(e.context.getNodeObject(), "simpleName", "ExpressionNode");
});
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class InstrumentableNodeTest method testLateMaterializeSyntax.
/*
* First instrument statements and then instrument expressions to test materialization at
* locations where there is already a wrapper.
*/
@Test
public void testLateMaterializeSyntax() {
Source source = createSource("MATERIALIZE_CHILD_EXPRESSION");
SourceSectionFilter filter;
filter = SourceSectionFilter.newBuilder().tagIs(StandardTags.StatementTag.class).build();
instrumenter.attachExecutionEventFactory(filter, null, factory);
execute(source);
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializeChildExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializeChildExpressionNode);
});
assertAllEventsConsumed();
filter = SourceSectionFilter.newBuilder().tagIs(StandardTags.ExpressionTag.class).build();
instrumenter.attachExecutionEventFactory(filter, null, factory);
execute(source);
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializedChildExpressionNode);
});
assertOn(ENTER, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof ExpressionNode);
});
assertOn(RETURN_VALUE, (e) -> {
assertTrue(e.context.getInstrumentedNode() instanceof MaterializedChildExpressionNode);
});
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class CoverageExample method onCreate.
@Override
protected void onCreate(final Env env) {
SourceSectionFilter.Builder builder = SourceSectionFilter.newBuilder();
SourceSectionFilter filter = builder.tagIs(EXPRESSION).build();
Instrumenter instrumenter = env.getInstrumenter();
instrumenter.attachExecutionEventFactory(filter, new CoverageEventFactory(env));
}
use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.
the class Profiler method reset.
// Reconfigure what's being collected; does not affect collected data
private void reset() {
if (binding != null) {
binding.dispose();
binding = null;
}
if (isCollecting) {
final Builder filterBuilder = SourceSectionFilter.newBuilder();
if (mimeTypes != null) {
filterBuilder.mimeTypeIs(mimeTypes);
}
final SourceSectionFilter filter = filterBuilder.tagIs(StandardTags.RootTag.class).sourceIs(notInternal).build();
binding = instrumenter.attachExecutionEventFactory(filter, new ExecutionEventNodeFactory() {
public ExecutionEventNode create(EventContext context) {
return createCountingNode(context);
}
});
}
}
Aggregations