Search in sources :

Example 26 with TmfModelResponse

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

the class SegmentStoreScatterDataProvider method fetchTree.

/**
 * @since 4.0
 */
@Override
public TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    ISegmentStoreProvider provider = fProvider;
    if (provider instanceof IAnalysisModule) {
        IAnalysisModule module = (IAnalysisModule) provider;
        IProgressMonitor mon = monitor != null ? monitor : new NullProgressMonitor();
        module.waitForCompletion(mon);
        if (mon.isCanceled()) {
            return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
    }
    ISegmentStore<ISegment> segStore = provider.getSegmentStore();
    if (segStore == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    long start = filter.getStart();
    long end = filter.getEnd();
    final Iterable<ISegment> intersectingElements = Iterables.filter(segStore.getIntersectingElements(start, end), s -> s.getStart() >= start);
    Map<String, INamedSegment> segmentTypes = new HashMap<>();
    IAnalysisModule module = (provider instanceof IAnalysisModule) ? (IAnalysisModule) provider : null;
    boolean complete = module == null ? true : module.isQueryable(filter.getEnd());
    // Create the list of segment types that will each create a series
    for (INamedSegment segment : Iterables.filter(intersectingElements, INamedSegment.class)) {
        if (monitor != null && monitor.isCanceled()) {
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        segmentTypes.put(segment.getName(), segment);
    }
    Builder<TmfTreeDataModel> nodes = new ImmutableList.Builder<>();
    nodes.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(String.valueOf(getTrace().getName()))));
    Map<IGroupingSegmentAspect, Map<String, Long>> names = new HashMap<>();
    for (Entry<String, INamedSegment> series : segmentTypes.entrySet()) {
        long parentId = fTraceId;
        /*
             * Create a tree sorting aspects by "Grouping aspect" much like
             * counter analyses
             */
        for (IGroupingSegmentAspect aspect : fGroupingAspects) {
            names.putIfAbsent(aspect, new HashMap<>());
            Map<String, Long> map = names.get(aspect);
            if (map == null) {
                break;
            }
            String name = String.valueOf(aspect.resolve(series.getValue()));
            String key = GROUP_PREFIX + name;
            Long uniqueId = map.get(key);
            if (uniqueId == null) {
                uniqueId = getUniqueId(key);
                map.put(key, uniqueId);
                nodes.add(new TmfTreeDataModel(uniqueId, parentId, name));
            }
            parentId = uniqueId;
        }
        long seriesId = getUniqueId(series.getKey());
        nodes.add(new TmfTreeDataModel(seriesId, parentId, series.getKey()));
    }
    return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), nodes.build()), complete ? ITmfResponse.Status.COMPLETED : ITmfResponse.Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) SeriesModelBuilder(org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder) Builder(com.google.common.collect.ImmutableList.Builder) 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) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) INamedSegment(org.eclipse.tracecompass.segmentstore.core.segment.interfaces.INamedSegment) IGroupingSegmentAspect(org.eclipse.tracecompass.analysis.timing.core.segmentstore.IGroupingSegmentAspect) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) AtomicLong(java.util.concurrent.atomic.AtomicLong) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) HashBiMap(com.google.common.collect.HashBiMap)

Example 27 with TmfModelResponse

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

the class AbstractTimeGraphDataProvider method fetchRowModel.

@Override
public final TmfModelResponse<TimeGraphModel> fetchRowModel(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
    A module = getAnalysisModule();
    if (!module.waitForInitialization()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    ITmfStateSystem ss = module.getStateSystem();
    if (ss == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    long currentEnd = ss.getCurrentEndTime();
    Object times = parameters.get(DataProviderParameterUtils.REQUESTED_TIME_KEY);
    Object items = parameters.get(DataProviderParameterUtils.REQUESTED_ITEMS_KEY);
    if (!(times instanceof List<?>) || ((List<?>) times).isEmpty() || !(items instanceof Collection<?>)) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Object end = Iterables.getLast(((List<?>) times));
    if (!(end instanceof Number)) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    boolean complete = ss.waitUntilBuilt(0) || ((Number) end).longValue() <= currentEnd;
    try (FlowScopeLog scope = // $NON-NLS-1$
    new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTimeGraphDataProvider#fetchRowModel").setCategory(getClass().getSimpleName()).build()) {
        TimeGraphModel models = getRowModel(ss, parameters, monitor);
        if (models == null) {
            // getRowModel returns null if the query was cancelled.
            return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        return new TmfModelResponse<>(models, complete ? Status.COMPLETED : Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
    } catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
        return new TmfModelResponse<>(null, Status.FAILED, String.valueOf(e.getMessage()));
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) FlowScopeLogBuilder(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLogBuilder) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) List(java.util.List) FlowScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.FlowScopeLog) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 28 with TmfModelResponse

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

the class TmfTimeGraphCompositeDataProvider method fetchStyle.

@Override
public TmfModelResponse<OutputStyleModel> fetchStyle(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Map<String, OutputElementStyle> styles = new HashMap<>();
    for (P dataProvider : getProviders()) {
        if (dataProvider instanceof IOutputStyleProvider) {
            TmfModelResponse<OutputStyleModel> response = ((IOutputStyleProvider) dataProvider).fetchStyle(fetchParameters, monitor);
            OutputStyleModel model = response.getModel();
            if (model != null) {
                styles.putAll(model.getStyles());
            }
        }
    }
    if (styles.isEmpty()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(new OutputStyleModel(styles), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : OutputStyleModel(org.eclipse.tracecompass.tmf.core.model.OutputStyleModel) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOutputStyleProvider(org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 29 with TmfModelResponse

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

the class CustomOutputAnnotationProvider method fetchAnnotations.

@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Object markerID = fetchParameters.get(DataProviderParameterUtils.REQUESTED_MARKER_SET_KEY);
    Object hostID = fetchParameters.get(DataProviderParameterUtils.REQUESTED_TRACE_KEY);
    Optional<ITmfTrace> requestedTrace = getTrace(hostID);
    /*
         * Ignore if trace is not the requested trace, or if no requested trace,
         * if the trace is not the first element of its trace set.
         */
    if ((requestedTrace.isPresent() && !requestedTrace.get().equals(fTrace)) || (!requestedTrace.isPresent() && !isFirstTrace())) {
        // $NON-NLS-1$
        return new TmfModelResponse<>(null, Status.COMPLETED, "");
    }
    if (markerID == null) {
        return new TmfModelResponse<>(null, Status.FAILED, NO_MARKER_ID);
    }
    MarkerSet ms = getMarkerSet(markerID);
    if (ms == null) {
        return new TmfModelResponse<>(null, Status.FAILED, formatError(markerID));
    }
    return getAnnotationProvider(requestedTrace.isPresent() ? requestedTrace.get() : null, ms).fetchAnnotations(fetchParameters, monitor);
}
Also used : MarkerSet(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 30 with TmfModelResponse

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

the class TmfTreeCompositeDataProvider method fetchAnnotationCategories.

@Override
public TmfModelResponse<AnnotationCategoriesModel> fetchAnnotationCategories(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    AnnotationCategoriesModel model = new AnnotationCategoriesModel(Collections.emptyList());
    for (P dataProvider : getProviders()) {
        if (dataProvider instanceof IOutputAnnotationProvider) {
            TmfModelResponse<AnnotationCategoriesModel> response = ((IOutputAnnotationProvider) dataProvider).fetchAnnotationCategories(fetchParameters, monitor);
            model = AnnotationCategoriesModel.of(model, response.getModel());
        }
    }
    if (model.getAnnotationCategories().isEmpty()) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

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