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();
}
}
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());
}
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();
}
}
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));
}
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;
}
Aggregations