Search in sources :

Example 11 with SourceSectionFilter

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();
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) Test(org.junit.Test)

Example 12 with SourceSectionFilter

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");
    });
}
Also used : ConstantTag(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ConstantTag) ExpressionTag(com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Test(org.junit.Test)

Example 13 with SourceSectionFilter

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);
    });
}
Also used : MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) ExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode) MaterializeChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) MaterializedChildExpressionNode(com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(org.graalvm.polyglot.Source) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) Test(org.junit.Test)

Example 14 with SourceSectionFilter

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));
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter)

Example 15 with SourceSectionFilter

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);
            }
        });
    }
}
Also used : EventContext(com.oracle.truffle.api.instrumentation.EventContext) ExecutionEventNodeFactory(com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory) Builder(com.oracle.truffle.api.instrumentation.SourceSectionFilter.Builder) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags)

Aggregations

SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)32 Test (org.junit.Test)21 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)7 Source (com.oracle.truffle.api.source.Source)7 ExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode)5 MaterializeChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode)5 MaterializedChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode)5 ExpressionTag (com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag)4 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)3 Node (com.oracle.truffle.api.nodes.Node)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 EventContext (com.oracle.truffle.api.instrumentation.EventContext)2 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)2 Instrumenter (com.oracle.truffle.api.instrumentation.Instrumenter)2 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)2 Builder (com.oracle.truffle.api.instrumentation.SourceSectionFilter.Builder)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 Source (org.graalvm.polyglot.Source)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 AllocationListener (com.oracle.truffle.api.instrumentation.AllocationListener)1