Search in sources :

Example 11 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkEndTime.

/**
 * Test that getIteratorOverQuark returns the correct intervals for a range
 * included in the state system range
 */
@Test
public void testIteratorOverQuarkEndTime() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    int quark;
    try {
        quark = ss.getQuarkAbsolute(DUMMY_STRING);
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1199);
        /* There should be one interval ranging from 1000L to 1199L */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1200);
        /* There should be 2 intervals ranging from 1000L to 1199L and 1200L to 1499L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1200L, interval.getStartTime());
        assertEquals(1499L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, 1800, 5000);
        /* There should be one interval ranging from 1500L to 2000L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1500L, interval.getStartTime());
        assertEquals(2000L, interval.getEndTime());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 12 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkResolution.

/**
 * Test that the QuarkIterator returns the correct intervals for a range
 * included in the state system range and a resolution
 */
@Test
public void testIteratorOverQuarkResolution() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, 1L);
    ITmfStateSystemBuilder ss = StateSystemFactory.newStateSystem(backend);
    try {
        // Create a small state system with intervals for a resolution
        int quark = ss.getQuarkAbsoluteAndAdd(DUMMY_STRING);
        /**
         * Here follows the state system, with each dash representing a nanosecond and
         * vertical line a change of state. The time are the times that are expected to
         * be queried
         *
         * <pre>
         *
         * resolution of 4:  2   6      10
         * resolution of 3:  2  5    8   11
         *                  ------|-|-|----
         * </pre>
         */
        ss.modifyAttribute(1L, 1, quark);
        ss.modifyAttribute(7L, 2, quark);
        ss.modifyAttribute(8L, 1, quark);
        ss.modifyAttribute(9L, 2, quark);
        ss.closeHistory(12L);
        // Verify a resolution of 4
        QuarkIterator iterator = new QuarkIterator(ss, quark, 2, 14, 4);
        /*
             * With steps of 4, there should be 2 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
        // Verify a resolution of 3
        iterator = new QuarkIterator(ss, quark, 2, 14, 3);
        /*
             * With steps of 3, there should be 3 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the first interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the second interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    } finally {
        ss.dispose();
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 13 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkReversed.

/**
 * Test that the reverse iterator returns the correct intervals:
 * <ul>
 * <li>intervals for the correct quark</li>
 * <li>ordered intervals</li>
 * <li>intervals covering the correct time range</li>
 * </ul>
 */
@Test
public void testIteratorOverQuarkReversed() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MAX_VALUE);
        ITmfStateInterval prevInterval = null;
        ITmfStateInterval currInterval = null;
        while (iterator.hasPrevious()) {
            currInterval = iterator.previous();
            assertEquals(quark, currInterval.getAttribute());
            if (prevInterval == null) {
                /* This is the first interval for this attribute */
                assertEquals(currInterval.getEndTime(), ss.getCurrentEndTime());
            } else {
                assertEquals(prevInterval.getStartTime() - 1, currInterval.getEndTime());
            }
            prevInterval = currInterval;
        }
        assertNotNull("Iterator should have returned at least one interval", currInterval);
        assertEquals(ss.getStartTime(), currInterval.getStartTime());
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 14 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuark.

/**
 * Test that iterator returns the correct intervals:
 * <ul>
 * <li>intervals for the correct quark</li>
 * <li>ordered intervals</li>
 * <li>intervals covering the correct time range</li>
 * </ul>
 */
@Test
public void testIteratorOverQuark() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    for (int quark = 0; quark < ss.getNbAttributes(); quark++) {
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE);
        ITmfStateInterval prevInterval = null;
        ITmfStateInterval currInterval = null;
        while (iterator.hasNext()) {
            currInterval = iterator.next();
            assertEquals(quark, currInterval.getAttribute());
            if (prevInterval == null) {
                /* This is the first interval for this attribute */
                assertEquals(currInterval.getStartTime(), ss.getStartTime());
            } else {
                assertEquals(prevInterval.getEndTime() + 1, currInterval.getStartTime());
            }
            prevInterval = currInterval;
        }
        assertNotNull("Iterator should have returned at least one interval", currInterval);
        assertEquals(ss.getCurrentEndTime(), currInterval.getEndTime());
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 15 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class InMemoryBackendTest method testDoQuery.

/**
 * Query the state system
 */
@Test
public void testDoQuery() {
    List<@Nullable ITmfStateInterval> interval = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
    for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
        interval.add(null);
    }
    IStateHistoryBackend backend = fixture;
    assertNotNull(backend);
    try {
        backend.doQuery(interval, 950);
    } catch (TimeRangeException | StateSystemDisposedException e) {
        fail(e.getMessage());
    }
    assertEquals(NUMBER_OF_ATTRIBUTES, interval.size());
    testInterval(interval.get(0), 900, 990, 9);
    testInterval(interval.get(1), 901, 991, 9);
    testInterval(interval.get(2), 902, 992, 9);
    testInterval(interval.get(3), 903, 993, 9);
    testInterval(interval.get(4), 904, 994, 9);
    testInterval(interval.get(5), 905, 995, 9);
    testInterval(interval.get(6), 906, 996, 9);
    testInterval(interval.get(7), 907, 997, 9);
    testInterval(interval.get(8), 908, 998, 9);
    testInterval(interval.get(9), 909, 999, 9);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Aggregations

ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)155 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)78 Test (org.junit.Test)56 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)52 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)41 ArrayList (java.util.ArrayList)37 NonNull (org.eclipse.jdt.annotation.NonNull)27 Nullable (org.eclipse.jdt.annotation.Nullable)20 HashMap (java.util.HashMap)19 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)16 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)15 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)14 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)12 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)12 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)12 ImmutableList (com.google.common.collect.ImmutableList)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)11 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)11