Search in sources :

Example 46 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testGetNextAfterSeekingOnLocation_3.

@Test
public void testGetNextAfterSeekingOnLocation_3() {
    final ITmfLocation INITIAL_LOC = fTrace.seekEvent(500L).getLocation();
    final long INITIAL_TS = 501;
    final int NB_READS = 20;
    // On lower bound, returns the first event (ts = 501)
    final ITmfContext context = fTrace.seekEvent(INITIAL_LOC);
    // Read NB_EVENTS
    ITmfEvent event;
    for (int i = 0; i < NB_READS; i++) {
        event = fTrace.getNext(context);
        assertEquals("Event timestamp", INITIAL_TS + i, event.getTimestamp().getValue());
    }
    // Make sure we stay positioned
    event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", INITIAL_TS + NB_READS, event.getTimestamp().getValue());
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfLocation(org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation) Test(org.junit.Test)

Example 47 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceTest method testSeekEventOnRankOutOfScope.

@Test
public void testSeekEventOnRankOutOfScope() {
    // Position trace at beginning
    ITmfContext context = fTrace.seekEvent(-1);
    assertEquals("Event rank", 0, context.getRank());
    ITmfEvent event = fTrace.parseEvent(context);
    assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
    assertEquals("Event rank", 0, context.getRank());
    event = fTrace.getNext(context);
    assertEquals("Event timestamp", 1, event.getTimestamp().getValue());
    assertEquals("Event rank", 1, context.getRank());
    // Position trace at event passed the end
    context = fTrace.seekEvent(NB_EVENTS);
    assertEquals("Event rank", NB_EVENTS, context.getRank());
    event = fTrace.parseEvent(context);
    assertNull("Event", event);
    assertEquals("Event rank", NB_EVENTS, context.getRank());
    event = fTrace.getNext(context);
    assertNull("Event", event);
    assertEquals("Event rank", NB_EVENTS, context.getRank());
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) Test(org.junit.Test)

Example 48 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceUtilsTest method testResolveEventAspectsOfNameForEvent.

/**
 * Test the
 * {@link TmfTraceUtils#resolveAspectOfNameForEvent(ITmfTrace, String, ITmfEvent)}
 * method.
 */
@Test
public void testResolveEventAspectsOfNameForEvent() {
    TmfTrace trace = fTrace;
    assertNotNull(trace);
    ITmfContext context = trace.seekEvent(0L);
    ITmfEvent event = trace.getNext(context);
    assertNotNull(event);
    /* Make sure the CPU aspect returns the expected value */
    Object cpuObj = TmfTraceUtils.resolveAspectOfNameForEvent(trace, "cpu", event);
    assertNotNull(cpuObj);
    assertEquals(1, cpuObj);
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 49 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfTraceUtilsTest method testAdditionalAspects.

/**
 * Test the {@link TmfTraceUtils#registerEventAspect(ITmfEventAspect)} method
 */
@Test
public void testAdditionalAspects() {
    TmfTrace trace = fTrace;
    assertNotNull(trace);
    ITmfContext context = trace.seekEvent(0L);
    ITmfEvent event = trace.getNext(context);
    assertNotNull(event);
    // Make sure the aspect is not resolved
    Object obj = TmfTraceUtils.resolveEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
    assertNull(obj);
    obj = TmfTraceUtils.resolveAspectOfNameForEvent(trace, TestEventAspect.ASPECT_NAME, event);
    assertNull(obj);
    Integer val = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
    assertNull(val);
    // Register the aspect
    TmfTraceUtils.registerEventAspect(TEST_ASPECT);
    // See that the aspect is resolved now
    obj = TmfTraceUtils.resolveEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
    assertNotNull(obj);
    assertEquals(TestEventAspect.RESOLVED_VALUE, obj);
    // See if it is resolved by name as well
    obj = TmfTraceUtils.resolveAspectOfNameForEvent(trace, TestEventAspect.ASPECT_NAME, event);
    assertNotNull(obj);
    assertEquals(TestEventAspect.RESOLVED_VALUE, obj);
    // See if it is resolved by Integer type as well
    val = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(trace, TestEventAspect.class, event);
    assertNotNull(val);
    assertEquals(TestEventAspect.RESOLVED_VALUE, val);
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) TmfTrace(org.eclipse.tracecompass.tmf.core.trace.TmfTrace) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) AnalysisManagerTest(org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest) Test(org.junit.Test)

Example 50 with ITmfEvent

use of org.eclipse.tracecompass.tmf.core.event.ITmfEvent in project tracecompass by tracecompass.

the class TmfCheckpointIndexTest2 method testTmfTraceMultiTimestamps.

// ------------------------------------------------------------------------
// Verify checkpoints
// ------------------------------------------------------------------------
@Test
public void testTmfTraceMultiTimestamps() {
    assertEquals("getCacheSize", BLOCK_SIZE, fTrace.getCacheSize());
    assertEquals("getTraceSize", NB_EVENTS, fTrace.getNbEvents());
    assertEquals("getRange-start", 1, fTrace.getTimeRange().getStartTime().getValue());
    assertEquals("getRange-end", 102, fTrace.getTimeRange().getEndTime().getValue());
    assertEquals("getStartTime", 1, fTrace.getStartTime().getValue());
    assertEquals("getEndTime", 102, fTrace.getEndTime().getValue());
    ITmfCheckpointIndex checkpoints = fTrace.getIndexer().getCheckpoints();
    assertTrue("Checkpoints exist", checkpoints != null);
    assertEquals("Checkpoints size", NB_EVENTS / BLOCK_SIZE + 1, checkpoints.size());
    // Trace has 3 events with same timestamp (ts=101) at rank 99, 100, 101
    // Verify that the event at rank=99 is returned when seeking to ts=101 (first event with this timestamp)
    // and not the event at checkpoint boundary
    ITmfTimestamp seekTs = TmfTimestamp.create(101, -3);
    ITmfContext ctx = fTrace.seekEvent(seekTs);
    ITmfEvent event = fTrace.getNext(ctx);
    assertEquals(99, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    event = fTrace.getNext(ctx);
    assertEquals(100, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    event = fTrace.getNext(ctx);
    assertEquals(101, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    // Trace has events with same timestamp (ts=102) for ranks 102..702 -> 2 checkpoints with same timestamp are created
    // Verify that the event at rank=102 is returned when seeking to ts=102 (first event with this timestamp)
    // and not the event at checkpoint boundary
    seekTs = TmfTimestamp.create(102, -3);
    ctx = fTrace.seekEvent(seekTs);
    event = fTrace.getNext(ctx);
    assertEquals(102, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    // Verify seek to first checkpoint
    seekTs = TmfTimestamp.create(1, -3);
    ctx = fTrace.seekEvent(seekTs);
    event = fTrace.getNext(ctx);
    assertEquals(1, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    // Verify seek to timestamp before first event
    seekTs = TmfTimestamp.create(0, -3);
    ctx = fTrace.seekEvent(seekTs);
    event = fTrace.getNext(ctx);
    assertEquals(1, ctx.getRank());
    assertEquals(0, TmfTimestamp.create(1, -3).compareTo(event.getTimestamp()));
    // Verify seek to timestamp between first and second checkpoint
    seekTs = TmfTimestamp.create(50, -3);
    ctx = fTrace.seekEvent(seekTs);
    event = fTrace.getNext(ctx);
    assertEquals(50, ctx.getRank());
    assertEquals(0, seekTs.compareTo(event.getTimestamp()));
    // Verify seek to timestamp after last event in trace
    seekTs = TmfTimestamp.create(103, -3);
    ctx = fTrace.seekEvent(seekTs);
    event = fTrace.getNext(ctx);
    assertEquals(-1, ctx.getRank());
    assertNull(event);
}
Also used : ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) ITmfCheckpointIndex(org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.ITmfCheckpointIndex) Test(org.junit.Test)

Aggregations

ITmfEvent (org.eclipse.tracecompass.tmf.core.event.ITmfEvent)182 Test (org.junit.Test)127 ITmfContext (org.eclipse.tracecompass.tmf.core.trace.ITmfContext)112 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)40 TmfEventRequest (org.eclipse.tracecompass.tmf.core.request.TmfEventRequest)30 AnalysisManagerTest (org.eclipse.tracecompass.tmf.core.tests.analysis.AnalysisManagerTest)27 ITmfLocation (org.eclipse.tracecompass.tmf.core.trace.location.ITmfLocation)25 TmfTimeRange (org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange)24 NonNull (org.eclipse.jdt.annotation.NonNull)20 TmfEvent (org.eclipse.tracecompass.tmf.core.event.TmfEvent)17 ITmfEventRequest (org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest)16 Vector (java.util.Vector)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 Predicate (java.util.function.Predicate)14 TmfTraceUtils (org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 CtfTestTrace (org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace)13 CtfTmfTestTraceUtils (org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils)13 Assert.assertEquals (org.junit.Assert.assertEquals)13 Assert.assertNotNull (org.junit.Assert.assertNotNull)13