Search in sources :

Example 16 with ITmfStateInterval

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

the class InMemoryBackendTest method testQueryAttribute.

/**
 * Test single attribute then compare it to a full query
 */
@Test
public void testQueryAttribute() {
    try {
        IStateHistoryBackend backend = fixture;
        assertNotNull(backend);
        ITmfStateInterval[] interval = new TmfStateInterval[10];
        for (int i = 0; i < 10; i++) {
            interval[i] = backend.doSingularQuery(950, i);
        }
        testInterval(interval[0], 900, 990, 9);
        testInterval(interval[1], 901, 991, 9);
        testInterval(interval[2], 902, 992, 9);
        testInterval(interval[3], 903, 993, 9);
        testInterval(interval[4], 904, 994, 9);
        testInterval(interval[5], 905, 995, 9);
        testInterval(interval[6], 906, 996, 9);
        testInterval(interval[7], 907, 997, 9);
        testInterval(interval[8], 908, 998, 9);
        testInterval(interval[9], 909, 999, 9);
        List<@Nullable ITmfStateInterval> intervalQuery = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
        for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
            intervalQuery.add(null);
        }
        backend.doQuery(intervalQuery, 950);
        ITmfStateInterval[] ref = intervalQuery.toArray(new ITmfStateInterval[0]);
        assertArrayEquals(ref, interval);
    } catch (TimeRangeException | StateSystemDisposedException e) {
        fail(e.getMessage());
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) 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)

Example 17 with ITmfStateInterval

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

the class StateHistoryBackendTestBase method testFullIntervals.

/**
 * Test the full query method by filling a small backend with intervals that
 * take the full time range, like this:
 *
 * <pre>
 * |x-------------x|
 * |x-------------x|
 * |x-------------x|
 * |x-------------x|
 * |      ...      |
 * </pre>
 *
 * and then querying at every single timestamp, making sure all, and only,
 * the expected intervals are returned.
 */
@Test
public void testFullIntervals() {
    final int nbAttr = 1000;
    final long startTime = 0;
    final long endTime = 1000;
    List<ITmfStateInterval> intervals = new ArrayList<>();
    for (int attr = 0; attr < nbAttr; attr++) {
        intervals.add(new TmfStateInterval(startTime, endTime, attr, attr));
    }
    buildAndQueryFullRange(startTime, endTime, nbAttr, intervals, false);
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 18 with ITmfStateInterval

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

the class StateHistoryBackendTestBase method testNegativeTimes.

/**
 * Test that negative times are also properly handled.
 *
 * @throws IOException
 *             if an IO exception occurred creating the backend.
 * @throws StateSystemDisposedException
 *             if the state system was disposed
 * @throws TimeRangeException
 *             if the time was incorrect.
 */
@Test
public void testNegativeTimes() throws IOException, TimeRangeException, StateSystemDisposedException {
    long startTime = -1001;
    IStateHistoryBackend backend = getBackendForBuilding(startTime);
    for (long t = startTime; t <= 200; t += 10) {
        backend.insertPastState(t, t + 10, 0, t);
    }
    backend.finishedBuilding(210);
    IStateHistoryBackend backendQuery = getBackendForQuerying(backend);
    ITmfStateInterval poisonInterval = backendQuery.doSingularQuery(-1, 0);
    assertNotNull(poisonInterval);
    assertEquals(-11L, poisonInterval.getValue());
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 19 with ITmfStateInterval

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

the class StateSystem method queryFullState.

// --------------------------------------------------------------------------
// Regular query methods (sent to the back-end)
// --------------------------------------------------------------------------
@Override
public List<ITmfStateInterval> queryFullState(long t) throws TimeRangeException, StateSystemDisposedException {
    if (isDisposed) {
        throw new StateSystemDisposedException();
    }
    try (ScopeLog log = new // $NON-NLS-1$
    ScopeLog(// $NON-NLS-1$
    LOGGER, // $NON-NLS-1$
    Level.FINER, // $NON-NLS-1$
    "StateSystem:FullQuery", "ssid", getSSID(), "ts", t)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        final int nbAttr = getNbAttributes();
        List<@Nullable ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
        /*
             * Bring the size of the array to the current number of attributes
             */
        for (int i = 0; i < nbAttr; i++) {
            stateInfo.add(null);
        }
        /*
             * If we are currently building the history, also query the
             * "ongoing" states for stuff that might not yet be written to the
             * history.
             */
        if (transState.isActive()) {
            transState.doQuery(stateInfo, t);
        }
        /* Query the storage backend */
        backend.doQuery(stateInfo, t);
        /*
             * We should have previously inserted an interval for every
             * attribute.
             */
        for (ITmfStateInterval interval : stateInfo) {
            if (interval == null) {
                // $NON-NLS-1$
                throw new IllegalStateException("Incoherent interval storage");
            }
        }
        return stateInfo;
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog)

Example 20 with ITmfStateInterval

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

the class TransientState method replaceOngoingState.

/**
 * More advanced version of {@link #changeOngoingStateValue}. Replaces the
 * complete ongoingStateInfo in one go, and updates the
 * ongoingStateStartTimes and #stateValuesTypes accordingly. BE VERY CAREFUL
 * WITH THIS!
 *
 * @param newStateIntervals
 *            The List of intervals that will represent the new
 *            "ongoing state". Their end times don't matter, we will only
 *            check their value and start times.
 */
public void replaceOngoingState(List<ITmfStateInterval> newStateIntervals) {
    final int size = newStateIntervals.size();
    fRWLock.writeLock().lock();
    try {
        fOngoingStateInfo = new ArrayList<>(size);
        fOngoingStateStartTimes = new ArrayList<>(size);
        fStateValueTypes = new ArrayList<>(size);
        for (ITmfStateInterval interval : newStateIntervals) {
            Object value = interval.getValue();
            fOngoingStateInfo.add(value);
            fOngoingStateStartTimes.add(interval.getStartTime());
            Class<?> objectClass = value != null ? value.getClass() : null;
            fStateValueTypes.add(objectClass);
        }
    } finally {
        fRWLock.writeLock().unlock();
    }
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

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