Search in sources :

Example 1 with StackTraceEntry

use of com.oracle.truffle.tools.profiler.StackTraceEntry in project graal by oracle.

the class ManualSamplingTest method assertEntry.

private static void assertEntry(Iterator<StackTraceEntry> iterator, String expectedName, int expectedCharIndex) {
    StackTraceEntry entry = iterator.next();
    assertEquals(expectedName, entry.getRootName());
    assertEquals(expectedCharIndex, entry.getSourceSection().getCharIndex());
    assertNotNull(entry.toStackTraceElement());
    assertNotNull(entry.toString());
    assertNotNull(entry.hashCode());
    assertTrue(entry.equals(entry));
}
Also used : StackTraceEntry(com.oracle.truffle.tools.profiler.StackTraceEntry)

Example 2 with StackTraceEntry

use of com.oracle.truffle.tools.profiler.StackTraceEntry in project graal by oracle.

the class NoTagSamplingTest method testNoTagSampling.

@Test
public void testNoTagSampling() throws InterruptedException, ExecutionException {
    ExecutorService singleThread = Executors.newSingleThreadExecutor();
    await = new Semaphore(0);
    try (Context context = Context.create(NoTagLanguage.ID)) {
        CPUSampler sampler = CPUSampler.find(context.getEngine());
        Source source = Source.newBuilder(NoTagLanguage.ID, "", "").buildLiteral();
        Future<?> f = singleThread.submit(() -> {
            return context.eval(source).asInt();
        });
        Map<Thread, List<StackTraceEntry>> sample = null;
        for (int i = 0; i < 10000; i++) {
            // times out after 10s
            sample = sampler.takeSample();
            if (!sample.isEmpty()) {
                break;
            }
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
        }
        // wait for future
        await.release();
        assertEquals(42, f.get());
        assertTrue(!sample.isEmpty());
        List<StackTraceEntry> entries = sample.values().iterator().next();
        assertEquals(1, entries.size());
        assertEquals(TEST_ROOT_NAME, entries.get(0).getRootName());
        singleThread.shutdown();
        singleThread.awaitTermination(10, TimeUnit.SECONDS);
    }
}
Also used : Context(org.graalvm.polyglot.Context) Semaphore(java.util.concurrent.Semaphore) StackTraceEntry(com.oracle.truffle.tools.profiler.StackTraceEntry) Source(org.graalvm.polyglot.Source) TruffleSafepoint(com.oracle.truffle.api.TruffleSafepoint) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) Test(org.junit.Test)

Aggregations

StackTraceEntry (com.oracle.truffle.tools.profiler.StackTraceEntry)2 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)1 CPUSampler (com.oracle.truffle.tools.profiler.CPUSampler)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 Context (org.graalvm.polyglot.Context)1 Source (org.graalvm.polyglot.Source)1 Test (org.junit.Test)1