Search in sources :

Example 96 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateProviderModelTest method testEventName.

/**
 * Test an increment of one, for an event name attribute
 */
@Test
public void testEventName() {
    ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace1);
    DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.ATTRIBUTE_FILE);
    try {
        module.setTrace(trace);
        module.schedule();
        module.waitForCompletion();
        ITmfStateSystem ss = module.getStateSystem();
        assertNotNull(ss);
        List<Integer> quarks = ss.getQuarks("*");
        assertEquals(2, quarks.size());
        for (Integer quark : quarks) {
            String name = ss.getAttributeName(quark);
            switch(name) {
                case "test":
                    {
                        final int[] expectedStarts = { 1, 5, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
                        XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
                    }
                    break;
                case "test1":
                    {
                        final int[] expectedStarts = { 1, 3, 7, 7 };
                        ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
                        XmlUtilsTest.verifyStateIntervals("test1", 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 97 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class ExperimentStateSystemModuleTest method testSsModule.

/**
 * Test the state system module execution and result
 */
@Test
public void testSsModule() {
    ITmfStateSystem ss = fModule.getStateSystem();
    assertNull(ss);
    fModule.schedule();
    if (fModule.waitForCompletion()) {
        ss = fModule.getStateSystem();
        assertNotNull(ss);
        try {
            int quark = ss.getQuarkAbsolute(TestExperimentAnalysis.TRACE_QUARK_NAME);
            ITmfStateInterval interval = ss.querySingleState(ss.getCurrentEndTime(), quark);
            assertEquals(2, interval.getStateValue().unboxInt());
        } catch (AttributeNotFoundException e) {
            fail("The quark for number of traces does not exist");
        } catch (StateSystemDisposedException e) {
            fail("Error: state system disposed");
        }
    } else {
        fail("Module did not complete properly");
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 98 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateSystemDataProvider method getSelectedEntries.

private Map<Long, Pair<ITmfStateSystem, Integer>> getSelectedEntries(Map<String, Object> fetchParameters) {
    Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
    if (selectedItems == null) {
        return Collections.emptyMap();
    }
    Map<Long, Pair<ITmfStateSystem, Integer>> idToQuark = new HashMap<>();
    synchronized (fEntryBuilder) {
        for (Long id : selectedItems) {
            Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
            if (pair != null) {
                idToQuark.put(id, pair);
            }
        }
    }
    return idToQuark;
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AtomicLong(java.util.concurrent.atomic.AtomicLong) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 99 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class PartialHistoryBackend method doQuery.

@Override
public void doQuery(List<@Nullable ITmfStateInterval> currentStateInfo, long t) throws TimeRangeException, StateSystemDisposedException {
    /* Wait for required steps to be done */
    waitForCheckpoints();
    fPartialSS.getUpstreamSS().waitUntilBuilt();
    if (!checkValidTime(t)) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        throw new TimeRangeException(fSSID + " Time:" + t + ", Start:" + getStartTime() + ", End:" + getEndTime());
    }
    /* Reload the previous checkpoint */
    long checkpointTime = fCheckpoints.floorKey(t);
    fInnerHistory.doQuery(currentStateInfo, checkpointTime);
    /*
         * Set the initial contents of the partial state system (which is the
         * contents of the query at the checkpoint).
         */
    List<@NonNull ITmfStateInterval> filledStateInfo = checkNotNullContents(currentStateInfo.stream()).collect(Collectors.toList());
    fPartialSS.takeQueryLock();
    fPartialSS.replaceOngoingState(filledStateInfo);
    /* Send an event request to update the state system to the target time. */
    TmfTimeRange range = new TmfTimeRange(/*
                 * The state at the checkpoint already includes any state change
                 * caused by the event(s) happening exactly at 'checkpointTime',
                 * if any. We must not include those events in the query.
                 */
    TmfTimestamp.fromNanos(checkpointTime + 1), TmfTimestamp.fromNanos(t));
    ITmfEventRequest request = new PartialStateSystemRequest(fPartialInput, range);
    fPartialInput.getTrace().sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
    // Do nothing
    }
    /*
         * Now the partial state system should have the ongoing time we are
         * looking for. However, the method expects a List of *state intervals*,
         * not state values, so we'll create intervals with a dummy end time.
         */
    for (int i = 0; i < currentStateInfo.size(); i++) {
        long start = 0;
        start = ((ITmfStateSystem) fPartialSS).getOngoingStartTime(i);
        @Nullable Object val = ((ITmfStateSystem) fPartialSS).queryOngoing(i);
        ITmfStateInterval interval = new TmfStateInterval(start, t, i, val);
        currentStateInfo.set(i, interval);
    }
    fPartialSS.releaseQueryLock();
}
Also used : 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) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 100 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateSystemDataProvider method addModule.

private boolean addModule(@Nullable IProgressMonitor monitor, ITmfAnalysisModuleWithStateSystems module, Long parentId, Long startTime) {
    synchronized (fStartedAnalysis) {
        /*
             * Ensure that this is the only job running build entry list.
             */
        if (monitor != null && monitor.isCanceled()) {
            return false;
        }
    }
    waitForInitialization(getTrace(), module);
    // look if the module already exist
    String moduleName = Objects.requireNonNull(module.getName());
    EntryModelBuilder entry = fEntryBuilder.get(parentId, moduleName);
    ModuleEntryModel.Builder moduleEntry;
    if (entry instanceof ModuleEntryModel.Builder) {
        moduleEntry = (ModuleEntryModel.Builder) entry;
    } else {
        long newId = ENTRY_ID.getAndIncrement();
        moduleEntry = new ModuleEntryModel.Builder(newId, parentId, moduleName, startTime, module);
        fEntryBuilder.put(parentId, moduleName, moduleEntry);
    }
    long moduleId = moduleEntry.getId();
    // Add child entry
    boolean fetchTreeIsComplete = true;
    Long moduleEnd = startTime;
    boolean hasChildren = false;
    for (ITmfStateSystem ss : module.getStateSystems()) {
        if (monitor != null && monitor.isCanceled()) {
            return false;
        }
        // Children entry of the modules are state system
        fetchTreeIsComplete &= ss.waitUntilBuilt(0);
        if (!ss.isCancelled()) {
            addStateSystem(monitor, ss, moduleId);
            moduleEnd = Long.max(moduleEnd, ss.getCurrentEndTime());
            hasChildren = true;
        } else {
            /*
                 * Need to delete all the children of this State System because
                 * it might be incomplete
                 */
            EntryModelBuilder ssEntry = fEntryBuilder.get(moduleId, ss.getSSID());
            if (ssEntry != null) {
                deleteElementFromBuildEntryList(ssEntry.getId());
            }
        }
    }
    // Update the entry
    moduleEntry.setEndTime(moduleEnd);
    fEntryBuilder.put(parentId, moduleName, moduleEntry);
    ModuleEntryModel finalModuleEntry = moduleEntry.build();
    fModuleEntryModelList.add(finalModuleEntry);
    if (fetchTreeIsComplete && hasChildren) {
        // Analysis is complete
        fModulesToStatus.put(module, true);
    }
    return fetchTreeIsComplete;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)137 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)52 Test (org.junit.Test)52 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)51 NonNull (org.eclipse.jdt.annotation.NonNull)32 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)30 Nullable (org.eclipse.jdt.annotation.Nullable)26 ArrayList (java.util.ArrayList)25 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)23 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)22 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)22 HashMap (java.util.HashMap)18 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)16 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)16 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 List (java.util.List)9 QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)9 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)9