Search in sources :

Example 21 with TmfTreeDataModel

use of org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel in project tracecompass by tracecompass.

the class XmlXYDataProvider method fetchTree.

/**
 * @since 2.4
 */
@Override
public TmfModelResponse<TmfTreeModel<ITmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fLock.readLock().lock();
    try {
        if (fCached != null) {
            return fCached;
        }
    } finally {
        fLock.readLock().unlock();
    }
    ITmfStateSystem ss = fXmlEntry.getStateSystem();
    DataDrivenStateSystemPath seriesNameAttrib = fSeriesNameAttrib;
    boolean isComplete = ss.waitUntilBuilt(0);
    // Get the quarks before the full states to ensure that the attributes will be present in the full state
    List<Integer> quarks = fXmlEntry.getQuarks();
    fLock.writeLock().lock();
    try {
        List<ITmfStateInterval> fullState = ss.queryFullState(ss.getCurrentEndTime());
        ImmutableList.Builder<ITmfTreeDataModel> builder = ImmutableList.builder();
        builder.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(getTrace().getName())));
        for (int quark : quarks) {
            String seriesName = ss.getAttributeName(quark);
            if (seriesNameAttrib != null) {
                // Use the value of the series name attribute
                int seriesNameQuark = seriesNameAttrib.getQuark(quark, fXmlEntry);
                Object value = fullState.get(seriesNameQuark).getValue();
                if (value != null) {
                    seriesName = String.valueOf(value);
                }
            }
            if (!seriesName.isEmpty()) {
                String tempSeriesName = seriesName;
                String uniqueName = fQuarkToString.computeIfAbsent(quark, q -> getUniqueNameFor(tempSeriesName));
                // Check if an ID has already been created for this quark.
                Long id = fIdToQuark.inverse().computeIfAbsent(quark, q -> ENTRY_IDS.getAndIncrement());
                builder.add(new TmfTreeDataModel(id, fTraceId, Collections.singletonList(uniqueName)));
            }
        }
        ImmutableList<ITmfTreeDataModel> list = builder.build();
        if (isComplete) {
            TmfModelResponse<TmfTreeModel<ITmfTreeDataModel>> tmfModelResponse = new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
            fCached = tmfModelResponse;
            return tmfModelResponse;
        }
        return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
    } catch (StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    } finally {
        fLock.writeLock().unlock();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)21 Test (org.junit.Test)9 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)8 ArrayList (java.util.ArrayList)5 NonNull (org.eclipse.jdt.annotation.NonNull)4 ITmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel)4 HashMap (java.util.HashMap)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)3 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)3 Map (java.util.Map)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)2 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)2 ITmfTreeXYDataProvider (org.eclipse.tracecompass.tmf.core.model.xy.ITmfTreeXYDataProvider)2 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)2 ITmfTreeViewerEntry (org.eclipse.tracecompass.tmf.ui.viewers.tree.ITmfTreeViewerEntry)2 TmfGenericTreeEntry (org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfGenericTreeEntry)2