Search in sources :

Example 11 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class HistogramDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    if (fCached != null) {
        return fCached;
    }
    fModule.waitForInitialization();
    Builder<TmfTreeDataModel> builder = ImmutableList.builder();
    builder.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(getTrace().getName())));
    builder.add(new TmfTreeDataModel(fTotalId, fTraceId, Collections.singletonList(Objects.requireNonNull(Messages.HistogramDataProvider_Total))));
    ITmfStateSystem eventsSs = Objects.requireNonNull(fModule.getStateSystem(TmfStatisticsEventTypesModule.ID));
    if (eventsSs.optQuarkAbsolute(Attributes.LOST_EVENTS) != ITmfStateSystem.INVALID_ATTRIBUTE) {
        builder.add(new TmfTreeDataModel(fLostId, fTraceId, Collections.singletonList(Objects.requireNonNull(Messages.HistogramDataProvider_Lost))));
    }
    if (eventsSs.waitUntilBuilt(0)) {
        TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> response = new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), builder.build()), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
        fCached = response;
        return response;
    }
    return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), builder.build()), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 12 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class TmfXyResponseFactory method create.

/**
 * Create a {@link TmfModelResponse} for values with a common X axis values,
 * with a either RUNNING or COMPLETED status. Model is not null, it's either
 * partial or full.
 *
 * @param title
 *            Chart title
 * @param xValues
 *            The x values requested by the viewer
 * @param yModels
 *            Collection of IYModel
 * @param isComplete
 *            Tells whether the computed model is complete or partial
 * @return A {@link TmfModelResponse} with either a running status or a
 *         completed status
 */
public static TmfModelResponse<ITmfXyModel> create(String title, long[] xValues, Collection<IYModel> yModels, boolean isComplete) {
    List<ISeriesModel> series = Lists.transform(new ArrayList<>(yModels), model -> {
        SeriesModelBuilder builder = new SeriesModelBuilder(model.getId(), model.getName(), xValues, model.getData());
        TmfXYAxisDescription yAxis = model.getYAxisDescription();
        if (yAxis != null) {
            builder.yAxisDescription(yAxis);
        }
        return builder.build();
    });
    ITmfXyModel model = new TmfXyModel(title, series);
    if (isComplete) {
        return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, Objects.requireNonNull(CommonStatusMessage.COMPLETED));
    }
    return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, Objects.requireNonNull(CommonStatusMessage.RUNNING));
}
Also used : ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) TmfXYAxisDescription(org.eclipse.tracecompass.tmf.core.model.xy.TmfXYAxisDescription) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SeriesModelBuilder(org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel) TmfXyModel(org.eclipse.tracecompass.tmf.core.model.TmfXyModel) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Example 13 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class TmfTimeGraphCompositeDataProvider method fetchRowModel.

@Override
public TmfModelResponse<TimeGraphModel> fetchRowModel(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    boolean isComplete = true;
    ImmutableList.Builder<ITimeGraphRowModel> series = ImmutableList.builder();
    for (P dataProvider : getProviders()) {
        TmfModelResponse<TimeGraphModel> response = dataProvider.fetchRowModel(fetchParameters, monitor);
        isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
        TimeGraphModel model = response.getModel();
        if (model != null) {
            series.addAll(model.getRows());
        }
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
    }
    if (isComplete) {
        return new TmfModelResponse<>(new TimeGraphModel(series.build()), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(new TimeGraphModel(series.build()), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) ImmutableList(com.google.common.collect.ImmutableList) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 14 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class AbstractTreeDataProvider method fetchTree.

@Override
public final TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    fLock.readLock().lock();
    try {
        if (fCached != null) {
            /*
                 * If the tree depends on the filter, isCacheable should return false (by
                 * contract). If the tree is not cacheable, fCached will always be null, and we
                 * will never enter this block.
                 */
            return fCached;
        }
    } finally {
        fLock.readLock().unlock();
    }
    fLock.writeLock().lock();
    fAnalysisModule.waitForInitialization();
    ITmfStateSystem ss = fAnalysisModule.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    boolean complete = ss.waitUntilBuilt(0);
    try (FlowScopeLog scope = // $NON-NLS-1$
    new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeDataProvider#fetchTree").setCategory(getClass().getSimpleName()).build()) {
        TmfTreeModel<M> tree = null;
        /* Don't query empty state system */
        if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
            tree = getTree(ss, fetchParameters, monitor);
            for (M model : tree.getEntries()) {
                if (model instanceof ICoreElementResolver) {
                    fEntryMetadata.put(model.getId(), ((ICoreElementResolver) model).getMetadata());
                }
            }
        }
        if (complete) {
            TmfModelResponse<TmfTreeModel<M>> response = new TmfModelResponse<>(tree, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
            if (isCacheable()) {
                fCached = response;
            }
            return response;
        }
        return new TmfModelResponse<>(tree, 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 : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) ICoreElementResolver(org.eclipse.tracecompass.tmf.core.model.ICoreElementResolver) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 15 with TmfModelResponse

use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.

the class TmfTreeCompositeDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    boolean isComplete = true;
    List<Entry<M, Object>> entries = new ArrayList<>();
    List<ITableColumnDescriptor> columnDescriptor = null;
    Table<Object, Long, @NonNull M> scopedEntries = HashBasedTable.create();
    for (P dataProvider : fProviders) {
        Map<Long, AtomicInteger> indexMap = new HashMap<>();
        TmfModelResponse<TmfTreeModel<M>> response = dataProvider.fetchTree(fetchParameters, monitor);
        isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
        TmfTreeModel<M> model = response.getModel();
        if (model != null) {
            Object scope = (model.getScope() == null) ? dataProvider : model.getScope();
            Map<Long, @NonNull M> row = scopedEntries.row(scope);
            for (M entry : model.getEntries()) {
                M previous = row.putIfAbsent(entry.getId(), entry);
                // Ignore duplicate entries from different data providers
                if (previous == null) {
                    if (entry.getParentId() == -1) {
                        entries.add(new SimpleEntry(entry, scope));
                    } else {
                        /*
                             * Insert new entries from subsequent data providers
                             * at the correct position in the entries list. New
                             * entries are inserted before sibling entries from
                             * previous data providers.
                             */
                        int index = indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                        int pos = 0;
                        while (pos < entries.size()) {
                            Entry<M, Object> added = entries.get(pos);
                            if (added.getValue().equals(scope) && added.getKey().getParentId() == entry.getParentId()) {
                                if (index == 0) {
                                    break;
                                }
                                index--;
                            }
                            pos++;
                        }
                        if (pos < entries.size()) {
                            entries.add(pos, new SimpleEntry(entry, scope));
                        } else {
                            entries.add(new SimpleEntry(entry, scope));
                        }
                    }
                } else {
                    indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
                }
            }
            // Use the column descriptor of the first model. All descriptors are supposed to be the same
            if (columnDescriptor == null) {
                columnDescriptor = model.getColumnDescriptors();
            }
        }
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
    }
    TmfTreeModel.Builder<M> treeModelBuilder = new TmfTreeModel.Builder<>();
    if (columnDescriptor == null) {
        columnDescriptor = Collections.emptyList();
    }
    treeModelBuilder.setColumnDescriptors(columnDescriptor).setEntries(Lists.transform(entries, e -> e.getKey()));
    if (isComplete) {
        return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : DataProviderManager(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderManager) CommonStatusMessage(org.eclipse.tracecompass.tmf.core.model.CommonStatusMessage) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) HashMap(java.util.HashMap) HashBasedTable(com.google.common.collect.HashBasedTable) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Nullable(org.eclipse.jdt.annotation.Nullable) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) Map(java.util.Map) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SimpleEntry(java.util.AbstractMap.SimpleEntry) ITmfResponse(org.eclipse.tracecompass.tmf.core.response.ITmfResponse) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Entry(java.util.Map.Entry) ITmfTreeDataProvider(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataProvider) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) Table(com.google.common.collect.Table) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) ITableColumnDescriptor(org.eclipse.tracecompass.tmf.core.model.ITableColumnDescriptor) SimpleEntry(java.util.AbstractMap.SimpleEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)

Aggregations

TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)44 ArrayList (java.util.ArrayList)23 NonNull (org.eclipse.jdt.annotation.NonNull)21 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)21 HashMap (java.util.HashMap)16 AtomicLong (java.util.concurrent.atomic.AtomicLong)14 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)14 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)10 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)9 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)9 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)9 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)8 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Nullable (org.eclipse.jdt.annotation.Nullable)6 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)6 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)6