Search in sources :

Example 11 with StateSystemDisposedException

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

the class HistoryTreeBackend method doQuery.

@Override
public void doQuery(List<ITmfStateInterval> stateInfo, long t) throws TimeRangeException, StateSystemDisposedException {
    checkValidTime(t);
    /* Queue is a stack of nodes containing nodes intersecting t */
    Deque<Integer> queue = new ArrayDeque<>();
    /* We start by reading the information in the root node */
    queue.add(getSHT().getRootNode().getSequenceNumber());
    /* Then we follow the down in the relevant children */
    try {
        while (!queue.isEmpty()) {
            int sequenceNumber = queue.pop();
            HTNode currentNode = getSHT().readNode(sequenceNumber);
            if (currentNode.getNodeType() == HTNode.NodeType.CORE) {
                /* Here we add the relevant children nodes for BFS */
                queue.addAll(((ParentNode) currentNode).selectNextChildren(t));
            }
            currentNode.writeInfoFromNode(stateInfo, t);
        }
    } catch (ClosedChannelException e) {
        throw new StateSystemDisposedException(e);
    }
/*
         * The stateInfo should now be filled with everything needed, we pass
         * the control back to the State System.
         */
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ClosedChannelException(java.nio.channels.ClosedChannelException) ArrayDeque(java.util.ArrayDeque)

Example 12 with StateSystemDisposedException

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

the class FsmTest method testInitialStateWithCondition.

/**
 * Compare the execution of two state machines doing the same job, the tid
 * condition is ignored with the initial element and used with the
 * initialState element. The result should be different.
 */
@Test
public void testInitialStateWithCondition() {
    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("fsm3");
        interval = stateSystem.querySingleState(END_TIME, quark);
        long count3 = interval.getStateValue().unboxLong();
        assertTrue("Test the count value", count1 > count3);
    } 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)

Example 13 with StateSystemDisposedException

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

the class TmfXmlConditionTest method testConditionsValidation.

/**
 * Test basic conditions on a state provider analysis
 */
@Test
public void testConditionsValidation() {
    ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace2);
    DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.CONDITION_FILE);
    try {
        module.setTrace(trace);
        module.schedule();
        module.waitForCompletion();
        ITmfStateSystem ss = module.getStateSystem();
        assertNotNull(ss);
        List<Integer> quarks = ss.getQuarks("*");
        assertEquals(5, quarks.size());
        for (Integer quark : quarks) {
            String name = ss.getAttributeName(quark);
            switch(name) {
                case "test":
                    {
                        final int[] expectedStarts = { 1, 5, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "test1":
                    {
                        final int[] expectedStarts = { 1, 3, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) };
                        XmlUtilsTest.verifyStateIntervals("test1", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "checkpoint":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("checkpoint", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "and_three_operands":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1) };
                        XmlUtilsTest.verifyStateIntervals("and_three_operands", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "not_operand":
                    {
                        final int[] expectedStarts = { 1, 5, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueLong(0), TmfStateValue.newValueLong(1), TmfStateValue.newValueLong(0) };
                        XmlUtilsTest.verifyStateIntervals("not_operand", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                default:
                    fail("Wrong attribute name " + name);
                    break;
            }
        }
    } catch (TmfAnalysisException | AttributeNotFoundException | StateSystemDisposedException e) {
        fail(e.getMessage());
    } finally {
        module.dispose();
        trace.dispose();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Example 14 with StateSystemDisposedException

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

the class DataDrivenScenarioHistoryBuilder method getStoredFieldValue.

/**
 * Get the value of a special field in the state system
 *
 * @param container
 *            The state system container this class use
 * @param attributeName
 *            The attribute name of the special field
 * @param info
 *            The scenario details
 * @param event
 *            The current event
 *
 * @return The value of a special field saved into the state system
 */
public ITmfStateValue getStoredFieldValue(IAnalysisDataContainer container, String attributeName, DataDrivenScenarioInfo info, ITmfEvent event) {
    ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
    long ts = event.getTimestamp().toNanos();
    ITmfStateInterval state = null;
    try {
        int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STORED_FIELDS, attributeName);
        state = ss.querySingleState(ts, attributeQuark);
    } catch (StateSystemDisposedException e) {
        // $NON-NLS-1$
        Activator.logError("failed to get the value of the stored field " + attributeName, e);
    }
    return (state != null) ? NonNullUtils.checkNotNull(state.getStateValue()) : TmfStateValue.nullValue();
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)

Example 15 with StateSystemDisposedException

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

the class DataDrivenScenarioHistoryBuilder method getSpecificStateStartTime.

/**
 * Get the start time of a specific state of the scenario
 *
 * @param container
 *            The state system container this class use
 * @param stateName
 *            The name of the current state of the scenario
 * @param info
 *            The scenario details
 * @param event
 *            The current event
 *
 * @return The start time for the specified state
 */
public long getSpecificStateStartTime(IXmlStateSystemContainer container, String stateName, DataDrivenScenarioInfo info, ITmfEvent event) {
    long ts = event.getTimestamp().getValue();
    ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
    try {
        int attributeQuark = getQuarkRelativeAndAdd(ss, info.getQuark(), TmfXmlStrings.STATE, stateName, START_TIME);
        ITmfStateInterval state = ss.querySingleState(ts, attributeQuark);
        return state.getStartTime();
    } catch (StateSystemDisposedException e) {
        // $NON-NLS-1$
        Activator.logError("failed the start time of the state " + stateName, e);
    }
    return -1l;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)

Aggregations

StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)96 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)78 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)51 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)40 Test (org.junit.Test)38 NonNull (org.eclipse.jdt.annotation.NonNull)25 ArrayList (java.util.ArrayList)24 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)16 HashMap (java.util.HashMap)15 Nullable (org.eclipse.jdt.annotation.Nullable)15 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)11 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)9 Map (java.util.Map)7