Search in sources :

Example 1 with StateValueTypeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.

the class StateSystemUtilsTest method setupStateSystem.

/**
 * Build a small test state system in memory
 */
@Before
public void setupStateSystem() {
    try {
        IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, START_TIME);
        fStateSystem = StateSystemFactory.newStateSystem(backend);
        int quark = fStateSystem.getQuarkAbsoluteAndAdd(DUMMY_STRING);
        fStateSystem.modifyAttribute(1200L, 10, quark);
        fStateSystem.modifyAttribute(1500L, 20, quark);
        fStateSystem.closeHistory(2000L);
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
}
Also used : StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Before(org.junit.Before)

Example 2 with StateValueTypeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException 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 3 with StateValueTypeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.

the class StateSystem method pushAttribute.

@Override
public void pushAttribute(long t, Object value, int attributeQuark) throws TimeRangeException, StateValueTypeException {
    int stackDepth;
    int subAttributeQuark;
    Object previousSV = transState.getOngoingStateValue(attributeQuark);
    if (previousSV == null) {
        /*
             * If the StateValue was null, this means this is the first time we
             * use this attribute. Leave stackDepth at 0.
             */
        stackDepth = 0;
    } else if (previousSV instanceof Integer) {
        /* Previous value was an integer, all is good, use it */
        stackDepth = (int) previousSV;
    } else {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getClass() + ", Expected:" + Type.INTEGER);
    }
    if (stackDepth >= MAX_STACK_DEPTH) {
        /*
             * Limit stackDepth to 100000, to avoid having Attribute Trees grow
             * out of control due to buggy insertions
             */
        // $NON-NLS-1$
        String message = " Stack limit reached, not pushing";
        // $NON-NLS-1$
        throw new IllegalStateException(getSSID() + " Quark:" + attributeQuark + message);
    }
    stackDepth++;
    subAttributeQuark = getQuarkRelativeAndAdd(attributeQuark, String.valueOf(stackDepth));
    modifyAttribute(t, stackDepth, attributeQuark);
    modifyAttribute(t, value, subAttributeQuark);
}
Also used : StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)

Example 4 with StateValueTypeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.

the class TransientState method processStateChange.

/**
 * Process a state change to be inserted in the history.
 *
 * @param eventTime
 *            The timestamp associated with this state change
 * @param value
 *            The new StateValue associated to this attribute
 * @param quark
 *            The quark of the attribute that is being modified
 * @throws TimeRangeException
 *             If 'eventTime' is invalid
 * @throws IndexOutOfBoundsException
 *             If the quark is out of range
 * @throws StateValueTypeException
 *             If the state value to be inserted is of a different type of
 *             what was inserted so far for this attribute.
 */
public void processStateChange(long eventTime, @Nullable Object value, int quark) throws TimeRangeException, StateValueTypeException {
    if (!this.fIsActive) {
        return;
    }
    fRWLock.writeLock().lock();
    try {
        Class<?> expectedSvType = fStateValueTypes.get(quark);
        /*
             * Make sure the state value type we're inserting is the same as the
             * one registered for this attribute.
             */
        if (expectedSvType == null) {
            /*
                 * The value hasn't been used yet, set it to the value we're
                 * currently inserting (which might be null/-1 again).
                 */
            fStateValueTypes.set(quark, value != null ? value.getClass() : null);
        } else if ((value != null) && (value.getClass() != expectedSvType)) {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            throw new StateValueTypeException(fBackend.getSSID() + " Quark:" + quark + ", Type:" + value.getClass() + ", Expected:" + expectedSvType);
        }
        if (Objects.equals(fOngoingStateInfo.get(quark), value) && !fBackend.canInsertBackwards()) {
            /*
                 * This is the case where the new value and the one already
                 * present in the Builder are the same. We do not need to create
                 * an interval, we'll just keep the current one going.
                 */
            return;
        }
        if (fOngoingStateStartTimes.get(quark) < eventTime) {
            /*
                 * These two conditions are necessary to create an interval and
                 * update ongoingStateInfo.
                 */
            fBackend.insertPastState(fOngoingStateStartTimes.get(quark), eventTime - 1, /* End Time */
            quark, /* attribute quark */
            fOngoingStateInfo.get(quark));
            /* StateValue */
            fOngoingStateStartTimes.set(quark, eventTime);
            fOngoingStateInfo.set(quark, value);
        } else if (fOngoingStateStartTimes.get(quark) == eventTime || !fBackend.canInsertBackwards()) {
            fOngoingStateInfo.set(quark, value);
        } else {
            fBackend.insertPastState(fOngoingStateStartTimes.get(quark), eventTime - 1, /* End Time */
            quark, /* attribute quark */
            value);
            /* StateValue */
            fOngoingStateStartTimes.set(quark, eventTime);
        }
        /* Update the Transient State's lastestTime, if needed */
        if (fLatestTime < eventTime) {
            fLatestTime = eventTime;
        }
    } finally {
        fRWLock.writeLock().unlock();
    }
}
Also used : StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)

Example 5 with StateValueTypeException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.

the class DataDrivenScenarioHistoryBuilder method updateScenarioState.

private static void updateScenarioState(@Nullable ITmfEvent event, IAnalysisDataContainer container, DataDrivenScenarioInfo info) {
    ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
    long ts = getTimestamp(event, ss);
    try {
        // save the status
        int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
        ss.modifyAttribute(ts, info.getActiveState().getId(), attributeQuark);
    } catch (StateValueTypeException e) {
        // $NON-NLS-1$
        Activator.logError("failed to update scenario state");
    }
}
Also used : ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)

Aggregations

StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)35 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)17 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)15 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)14 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)12 Test (org.junit.Test)11 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)10 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)7 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)5 Random (java.util.Random)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 KernelEventHandler (org.eclipse.tracecompass.internal.analysis.os.linux.core.kernel.handlers.KernelEventHandler)2 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)2 TmfAttributePool (org.eclipse.tracecompass.tmf.core.statesystem.TmfAttributePool)2 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)2 Before (org.junit.Before)2