Search in sources :

Example 51 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class DebugValueTest method testNumValue.

@Test
public void testNumValue() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(inf, infinity), \n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value42 = frame.getScope().getDeclaredValue("a");
            assertEquals("a", value42.getName());
            assertFalse(value42.isArray());
            assertNull(value42.getArray());
            assertNull(value42.getProperties());
            assertEquals("Integer", value42.getMetaObject().as(String.class));
            assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
            SourceSection integerSS = value42.getSourceLocation();
            assertEquals("source integer", integerSS.getCharacters());
            SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
            assertEquals("source infinity", infinitySS.getCharacters());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 52 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class BreakpointTest method testResolveListener.

@Test
public void testResolveListener() {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + // break here
    "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    Breakpoint sessionBreakpoint = null;
    try (DebuggerSession session = startSession()) {
        Breakpoint[] resolvedBp = new Breakpoint[1];
        SourceSection[] resolvedSection = new SourceSection[1];
        Breakpoint.ResolveListener bpResolveListener = (Breakpoint breakpoint, SourceSection section) -> {
            resolvedBp[0] = breakpoint;
            resolvedSection[0] = section;
        };
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).resolveListener(bpResolveListener).build());
        Assert.assertNull(resolvedBp[0]);
        Assert.assertNull(resolvedSection[0]);
        sessionBreakpoint = breakpoint;
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertSame(breakpoint, resolvedBp[0]);
            Assert.assertEquals(event.getSourceSection(), resolvedSection[0]);
            checkState(event, 4, true, "STATEMENT");
            Assert.assertEquals(1, event.getBreakpoints().size());
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
        });
        Assert.assertEquals(1, breakpoint.getHitCount());
        Assert.assertEquals(true, breakpoint.isEnabled());
        Assert.assertEquals(true, breakpoint.isResolved());
        expectDone();
    }
    Assert.assertEquals(false, sessionBreakpoint.isResolved());
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 53 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class BreakpointTest method testBreakSourceSection.

@Test
public void testBreakSourceSection() throws Throwable {
    final Source source = testSource("ROOT(STATEMENT, STATEMENT, STATEMENT)\n");
    try (DebuggerSession session = startSession()) {
        SourceSection sourceSection = getSourceImpl(source).createSection(16, 9);
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(sourceSection).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 1, true, "STATEMENT");
            Assert.assertEquals(sourceSection, event.getSourceSection());
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 54 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class CPUSamplerCLI method printAttributes.

private static void printAttributes(PrintStream out, CPUSampler sampler, String prefix, List<ProfilerNode<CPUSampler.Payload>> nodes, int maxRootLength) {
    long samplePeriod = sampler.getPeriod();
    long samples = sampler.getSampleCount();
    long selfInterpreted = 0;
    long selfCompiled = 0;
    long totalInterpreted = 0;
    long totalCompiled = 0;
    for (ProfilerNode<CPUSampler.Payload> tree : nodes) {
        CPUSampler.Payload payload = tree.getPayload();
        selfInterpreted += payload.getSelfInterpretedHitCount();
        selfCompiled += payload.getSelfCompiledHitCount();
        if (!tree.isRecursive()) {
            totalInterpreted += payload.getInterpretedHitCount();
            totalCompiled += payload.getCompiledHitCount();
        }
    }
    long totalSamples = totalInterpreted + totalCompiled;
    if (totalSamples <= 0L) {
        // hide methods without any cost
        return;
    }
    assert totalSamples < samples;
    ProfilerNode<CPUSampler.Payload> firstNode = nodes.get(0);
    SourceSection sourceSection = firstNode.getSourceSection();
    String rootName = firstNode.getRootName();
    if (!firstNode.getTags().contains(StandardTags.RootTag.class)) {
        rootName += "~" + formatIndices(sourceSection, needsColumnSpecifier(firstNode));
    }
    long selfSamples = selfInterpreted + selfCompiled;
    long selfTime = selfSamples * samplePeriod;
    double selfCost = selfSamples / (double) samples;
    double selfCompiledP = 0.0;
    if (selfSamples > 0) {
        selfCompiledP = selfCompiled / (double) selfSamples;
    }
    String selfTimes = String.format("%10dms %5.1f%% | %5.1f%%", selfTime, selfCost * 100, selfCompiledP * 100);
    long totalTime = totalSamples * samplePeriod;
    double totalCost = totalSamples / (double) samples;
    double totalCompiledP = totalCompiled / (double) totalSamples;
    String totalTimes = String.format("%10dms %5.1f%% | %5.1f%%", totalTime, totalCost * 100, totalCompiledP * 100);
    String location = getShortDescription(sourceSection);
    out.println(// 
    String.format(// 
    " %-" + Math.max(maxRootLength, 10) + "s | %s || %s | %s ", prefix + rootName, totalTimes, selfTimes, location));
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler)

Example 55 with SourceSection

use of com.oracle.truffle.api.source.SourceSection in project graal by oracle.

the class CPUTracerSnippets method getCounter.

private synchronized Payload getCounter(EventContext context) {
    SourceSection sourceSection = context.getInstrumentedSourceSection();
    Payload payload = payloadMap.get(sourceSection);
    if (payload == null) {
        payload = new Payload(new SourceLocation(env.getInstrumenter(), context));
        Payload otherPayload = payloadMap.putIfAbsent(sourceSection, payload);
        if (otherPayload != null) {
            payload = otherPayload;
        }
    }
    return payload;
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection)

Aggregations

SourceSection (com.oracle.truffle.api.source.SourceSection)68 Test (org.junit.Test)23 Source (com.oracle.truffle.api.source.Source)15 Source (org.graalvm.polyglot.Source)12 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)11 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)8 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)8 AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)6 Node (com.oracle.truffle.api.nodes.Node)6 RootNode (com.oracle.truffle.api.nodes.RootNode)6 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)5 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)3 DebugScope (com.oracle.truffle.api.debug.DebugScope)3 Counter (com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 RootCallTarget (com.oracle.truffle.api.RootCallTarget)2 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)2 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)2 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)2