Search in sources :

Example 96 with ITmfStateInterval

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

the class StateSystem method query2D.

private Iterable<@NonNull ITmfStateInterval> query2D(@NonNull Collection<@NonNull Integer> quarks, TimeRangeCondition timeCondition, boolean reverse) throws TimeRangeException, IndexOutOfBoundsException {
    if (timeCondition.min() < getStartTime()) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TimeRangeException("Time conditions " + timeCondition.min() + " is lower than state system start time: " + getStartTime());
    }
    if (quarks.isEmpty()) {
        return Collections.emptyList();
    }
    IntegerRangeCondition quarkCondition = IntegerRangeCondition.forDiscreteRange(quarks);
    if (quarkCondition.min() < 0 || quarkCondition.max() >= getNbAttributes()) {
        throw new IndexOutOfBoundsException();
    }
    Iterable<@NonNull ITmfStateInterval> transStateIterable = transState.query2D(quarks, timeCondition);
    Iterable<@NonNull ITmfStateInterval> backendIterable = backend.query2D(quarkCondition, timeCondition, reverse);
    return Iterables.concat(transStateIterable, backendIterable);
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) IntegerRangeCondition(org.eclipse.tracecompass.internal.provisional.datastore.core.condition.IntegerRangeCondition)

Example 97 with ITmfStateInterval

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

the class TransientState method query2D.

/**
 * Generalized 2D iterable query method. Iterates over intervals that match
 * the conditions on quarks and times in the Transient State.
 *
 * @param quarks
 *            Collection of quarks for returned intervals.
 * @param timeCondition
 *            Condition on the times for returned intervals
 * @return An iterable over the queried intervals, ordered by quarks.
 * @since 2.1
 */
public Iterable<ITmfStateInterval> query2D(Collection<Integer> quarks, TimeRangeCondition timeCondition) {
    fRWLock.readLock().lock();
    try (TraceCompassLogUtils.ScopeLog log = new // $NON-NLS-1$
    TraceCompassLogUtils.ScopeLog(// $NON-NLS-1$
    LOGGER, // $NON-NLS-1$
    Level.FINEST, // $NON-NLS-1$
    "TransientState:query2D", // $NON-NLS-1$
    "ssid", // $NON-NLS-1$
    fBackend.getSSID(), // $NON-NLS-1$
    "quarks", // $NON-NLS-1$
    quarks, "time", timeCondition)) {
        // $NON-NLS-1$
        if (!fIsActive) {
            return Collections.emptyList();
        }
        long end = timeCondition.max();
        Collection<ITmfStateInterval> iterable = new ArrayList<>();
        for (Integer quark : quarks) {
            ITmfStateInterval interval = getIntervalAt(end, quark);
            if (interval != null) {
                iterable.add(interval);
            }
        }
        return iterable;
    } finally {
        fRWLock.readLock().unlock();
    }
}
Also used : TraceCompassLogUtils(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList)

Example 98 with ITmfStateInterval

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

the class TmfStateSystemAnalysisModule method loadInitialState.

/**
 * Batch-load the initial state, if there is any.
 */
private void loadInitialState(ITmfStateProvider provider) {
    final ITmfTrace trace = provider.getTrace();
    File path = new File(trace.getPath());
    path = path.isDirectory() ? path : path.getParentFile();
    if (path == null) {
        return;
    }
    for (ITmfStateSystem ss : getStateSystems()) {
        if (ss instanceof ITmfStateSystemBuilder) {
            StateSnapshot snapshot = StateSnapshot.read(path.toPath(), ss.getSSID());
            if (snapshot == null || provider.getVersion() != snapshot.getVersion()) {
                continue;
            }
            List<List<String>> paths = new ArrayList<>();
            /* create quark list */
            for (Entry<List<String>, ITmfStateInterval> attributeSnapshot : snapshot.getStates().entrySet()) {
                List<String> attributePath = Objects.requireNonNull(attributeSnapshot.getKey());
                ITmfStateInterval state = Objects.requireNonNull(attributeSnapshot.getValue());
                while (paths.size() <= state.getAttribute()) {
                    // $NON-NLS-1$
                    paths.add(Collections.singletonList("Dummy" + paths.size()));
                }
                paths.set(state.getAttribute(), attributePath);
            }
            /*
                 * Populate quarks in order
                 */
            int i = 0;
            for (List<String> attributePath : paths) {
                int quark = ((ITmfStateSystemBuilder) ss).getQuarkAbsoluteAndAdd(attributePath.toArray(new String[attributePath.size()]));
                if (i != quark) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    Activator.logWarning("Quark for analysis " + getClass().getCanonicalName() + " not the same ( " + quark + " != " + i + ")");
                }
                i++;
            }
            /* Load the statedump into the statesystem */
            for (ITmfStateInterval interval : snapshot.getStates().values()) {
                Object initialState = interval.getValue();
                int attribute = interval.getAttribute();
                provider.addFutureEvent(interval.getStartTime(), initialState, attribute, FutureEventType.MODIFICATION);
                if (interval.getEndTime() != Long.MIN_VALUE) {
                    provider.addFutureEvent(interval.getEndTime() + 1, (Object) null, attribute, FutureEventType.MODIFICATION);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateSnapshot(org.eclipse.tracecompass.statesystem.core.snapshot.StateSnapshot) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 99 with ITmfStateInterval

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

the class FsmTest method testTwoInitialStates.

/**
 * Execute one pattern, with the two types of initial state initialization,
 * then test that the new behavior is prioritized and that preconditions are
 * ignored with initialState element
 *
 * @throws AttributeNotFoundException
 *             Exceptions thrown querying the state system
 * @throws StateSystemDisposedException
 *             Exceptions thrown querying the state system
 */
@Test
public void testTwoInitialStates() throws AttributeNotFoundException, StateSystemDisposedException {
    // Test segment store
    ISegmentStore<@NonNull ISegment> ss = fModule2.getSegmentStore();
    assertNotNull("segment store exist", ss);
    assertTrue("Segment store not empty", ss.size() == 1);
    Object item = ss.iterator().next();
    assertTrue(item instanceof TmfXmlPatternSegment);
    assertTrue(((TmfXmlPatternSegment) item).getName().equals(TEST_SEGMENT_NEW));
    // Test state system
    ITmfStateSystem stateSystem = fModule2.getStateSystem(fModule2.getId());
    assertNotNull("state system exist", stateSystem);
    int quark = stateSystem.getQuarkAbsolute("count_new");
    ITmfStateInterval interval = stateSystem.querySingleState(END_TIME, quark);
    int count = interval.getStateValue().unboxInt();
    assertTrue("Test the count value", count > 0);
    quark = stateSystem.optQuarkAbsolute("precond");
    assertEquals(ITmfStateSystem.INVALID_ATTRIBUTE, quark);
}
Also used : TmfXmlPatternSegment(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Example 100 with ITmfStateInterval

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

the class FsmTest method testInitialStateDeclaration.

/**
 * Compare the execution of two state machines that do the same job, one
 * using the initial element, the second one using the initialState element.
 * The result should be the same for both state machines
 */
@Test
public void testInitialStateDeclaration() {
    ITmfStateSystem stateSystem = fModule.getStateSystem(fModule.getId());
    assertNotNull("state system exist", stateSystem);
    try {
        int quark = stateSystem.getQuarkAbsolute("fsm1");
        @NonNull ITmfStateInterval interval = stateSystem.querySingleState(END_TIME, quark);
        long count1 = interval.getStateValue().unboxLong();
        quark = stateSystem.getQuarkAbsolute("fsm2");
        interval = stateSystem.querySingleState(END_TIME, quark);
        long count2 = interval.getStateValue().unboxLong();
        assertEquals("Test the count value", count1, count2);
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail("Failed to query the state system");
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

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