Search in sources :

Example 1 with Counter

use of com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter in project graal by oracle.

the class StatementProfilerExampleTest method testLoopHundreds.

@Test
public void testLoopHundreds() throws IOException {
    Source source = lines(// 1
    "LOOP(100", // 2
    ",STATEMENT(", // 3
    "STATEMENT),", /**/
    "STATEMENT)");
    // 4
    Map<SourceSection, Counter> counters = profiler.getCounters();
    for (int i = 0; i < 10; i++) {
        if (i == 0) {
            Assert.assertTrue(counters.isEmpty());
        } else {
            assertLine(counters, 2, i * 100);
            assertLine(counters, 3, i * 100);
            assertLine(counters, 4, i * 100);
        }
        run(source);
    }
}
Also used : Counter(com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 2 with Counter

use of com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter in project graal by oracle.

the class StatementProfilerExampleTest method testStatements.

@Test
public void testStatements() throws IOException {
    Source source = lines(// 1
    "ROOT(", // 2
    "STATEMENT(EXPRESSION", // 3
    ", STATEMENT),", // 4
    "STATEMENT)");
    Map<SourceSection, Counter> counters = profiler.getCounters();
    for (int i = 0; i < 1000; i++) {
        if (i == 0) {
            Assert.assertTrue(counters.isEmpty());
        } else {
            assertLine(counters, 2, i);
            assertLine(counters, 3, i);
            assertLine(counters, 4, i);
        }
        run(source);
    }
}
Also used : Counter(com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Example 3 with Counter

use of com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter in project graal by oracle.

the class StatementProfilerExampleTest method testLoopZero.

@Test
public void testLoopZero() throws IOException {
    Source source = lines(// 1
    "LOOP(0", // 2
    ",STATEMENT(", // 3
    "STATEMENT),", /**/
    "STATEMENT)");
    // 4
    Map<SourceSection, Counter> counters = profiler.getCounters();
    for (int i = 0; i < 10; i++) {
        run(source);
        // never actually executed
        Assert.assertTrue(counters.isEmpty());
    }
}
Also used : Counter(com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test) AbstractInstrumentationTest(com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)

Aggregations

AbstractInstrumentationTest (com.oracle.truffle.api.instrumentation.test.AbstractInstrumentationTest)3 Counter (com.oracle.truffle.api.instrumentation.test.examples.StatementProfilerExample.Counter)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 Source (org.graalvm.polyglot.Source)3 Test (org.junit.Test)3