Search in sources :

Example 6 with TmfModelResponse

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

the class TmfEventTableDataProvider method fetchIndex.

/**
 * Find the index in the table of an event using the rank in the trace or
 * the timestamp value. It will take any filter into consideration.
 *
 * @param fetchParameters
 *            Map of parameters that contain the filter applied to the
 *            table, if any. Everything else is ignored.
 * @param traceRank
 *            Rank of the event in the trace
 * @param timeBegin
 *            Timestamp of the event
 * @param monitor
 *            Progress monitor
 * @return Index in the table
 */
public TmfModelResponse<List<Long>> fetchIndex(Map<String, Object> fetchParameters, long traceRank, long timeBegin, @Nullable IProgressMonitor monitor) {
    @Nullable ITmfFilter filter = extractFilter(fetchParameters);
    long rank;
    if (traceRank == -1) {
        ITmfContext context = getTrace().seekEvent(TmfTimestamp.fromNanos(timeBegin));
        rank = context.getRank();
    } else {
        rank = traceRank;
    }
    if (filter == null) {
        return new TmfModelResponse<>(Collections.singletonList(rank), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    applyFilter(filter);
    Entry<Long, Long> nearestEntry = fRankToIndexMap.floorEntry(rank);
    long startingIndex = nearestEntry != null ? nearestEntry.getValue() : 0L;
    long startingRank = nearestEntry != null ? nearestEntry.getKey() : 0L;
    List<Long> foundIndex = new ArrayList<>();
    TmfEventRequest request = new TmfEventRequest(ITmfEvent.class, TmfTimeRange.ETERNITY, startingRank, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND) {

        private long currentIndex = startingIndex;

        private long fRank = startingRank;

        @Override
        public void handleData(ITmfEvent event) {
            super.handleData(event);
            if (monitor != null && monitor.isCanceled()) {
                cancel();
                return;
            }
            if (fRank >= rank) {
                foundIndex.add(currentIndex);
                done();
                return;
            }
            if (filter.matches(event)) {
                currentIndex++;
            }
            fRank++;
        }
    };
    getTrace().sendRequest(request);
    try {
        request.waitForCompletion();
    } catch (InterruptedException e) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, NonNullUtils.nullToEmptyString(e.getMessage()));
    }
    return new TmfModelResponse<>(foundIndex, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : ArrayList(java.util.ArrayList) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfContext(org.eclipse.tracecompass.tmf.core.trace.ITmfContext) ITmfFilter(org.eclipse.tracecompass.tmf.core.filter.ITmfFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ITmfEventRequest(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 7 with TmfModelResponse

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

the class CustomOutputAnnotationProvider method fetchAnnotationCategories.

@Override
public TmfModelResponse<AnnotationCategoriesModel> fetchAnnotationCategories(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Object markerID = fetchParameters.get(DataProviderParameterUtils.REQUESTED_MARKER_SET_KEY);
    /* Ignore if trace is not the first element of its trace set. */
    if (!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(null, ms).fetchAnnotationCategories(fetchParameters, monitor);
}
Also used : MarkerSet(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 8 with TmfModelResponse

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

the class LostEventsOutputAnnotationProvider method fetchAnnotationCategories.

@Override
public TmfModelResponse<AnnotationCategoriesModel> fetchAnnotationCategories(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    AnnotationCategoriesModel model = new AnnotationCategoriesModel(Collections.emptyList());
    ITmfStateSystem ss = getStateSystem();
    if (ss != null && getLostEventsQuark(ss) != -1) {
        model = new AnnotationCategoriesModel(Arrays.asList(LOST_EVENTS));
    }
    // $NON-NLS-1$
    return new TmfModelResponse<>(model, Status.COMPLETED, "");
}
Also used : AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 9 with TmfModelResponse

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

the class LostEventsOutputAnnotationProvider method fetchAnnotations.

@SuppressWarnings("null")
@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    IProgressMonitor progressMonitor = monitor;
    if (progressMonitor == null) {
        progressMonitor = new NullProgressMonitor();
    }
    ITmfStateSystem ss = getStateSystem();
    if (ss == null) {
        return NO_DATA;
    }
    int lostEventsQuark = getLostEventsQuark(ss);
    if (lostEventsQuark == -1) {
        return NO_DATA;
    }
    List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    @Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
    if (timeRequested == null || timeRequested.size() < 2 || (categories != null && !categories.contains(LOST_EVENTS))) {
        return NO_DATA;
    }
    if (timeRequested.equals(fLastRequest)) {
        // $NON-NLS-1$
        return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
    }
    fLastRequest = new ArrayList<>(timeRequested);
    TreeMultimap<String, Annotation> markers = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(Annotation::getStartTime));
    try {
        long start = Math.max(timeRequested.get(0), ss.getStartTime());
        long end = Math.min(timeRequested.get(timeRequested.size() - 1), ss.getCurrentEndTime());
        if (start <= end) {
            List<Long> times = new ArrayList<>(getTimes(ss, timeRequested));
            /* Update start to ensure that the previous marker is included. */
            start = Math.max(start - 1, ss.getStartTime());
            /* Update end to ensure that the next marker is included. */
            long nextStartTime = ss.querySingleState(end, lostEventsQuark).getEndTime() + 1;
            end = Math.min(nextStartTime, ss.getCurrentEndTime());
            times.set(0, start);
            times.set(times.size() - 1, end);
            for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(lostEventsQuark), times)) {
                if (progressMonitor.isCanceled()) {
                    fLastRequest = Collections.emptyList();
                    fLastAnnotationModel = new AnnotationModel(Collections.emptyMap());
                    // $NON-NLS-1$
                    return new TmfModelResponse<>(fLastAnnotationModel, Status.CANCELLED, "");
                }
                if (interval.getStateValue().isNull()) {
                    continue;
                }
                long lostEventsStartTime = interval.getStartTime();
                /*
                     * The end time of the lost events range is the value of the
                     * attribute, not the end time of the interval.
                     */
                long lostEventsEndTime = interval.getStateValue().unboxLong();
                long duration = lostEventsEndTime - lostEventsStartTime;
                Map<String, Object> style = new HashMap<>();
                style.put(StyleProperties.COLOR, COLOR);
                style.put(StyleProperties.OPACITY, OPACITY);
                markers.put(LOST_EVENTS, new Annotation(lostEventsStartTime, duration, -1, AnnotationType.CHART, null, new OutputElementStyle(LOST_EVENTS, style)));
            }
        }
    } catch (StateSystemDisposedException e) {
    /* ignored */
    }
    fLastAnnotationModel = new AnnotationModel(markers.asMap());
    // $NON-NLS-1$
    return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 10 with TmfModelResponse

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

the class PeriodicAnnotationProvider method fetchAnnotations.

@Override
@NonNull
public TmfModelResponse<@NonNull AnnotationModel> fetchAnnotations(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
    if (times == null) {
        return EMPTY_MODEL_RESPONSE;
    }
    int size = times.size() - 1;
    long startTime = times.get(0);
    long endTime = times.get(size);
    long resolution = (endTime - startTime) / (size);
    if (startTime > endTime) {
        return EMPTY_MODEL_RESPONSE;
    }
    long step = Math.max(Math.round(fPeriod), resolution);
    OutputElementStyle[] styles = new OutputElementStyle[2];
    styles[0] = generateOutputElementStyle(fColor1);
    RGBAColor color2 = fColor2;
    styles[1] = color2 == null ? styles[0] : generateOutputElementStyle(color2);
    Collection<Annotation> annotations = new ArrayList<>();
    /* Subtract 1.5 periods to ensure previous marker is included */
    long time = startTime - Math.max(Math.round(1.5 * fPeriod), resolution);
    ITimeReference reference = adjustReference(fReference, time);
    Annotation annotation = null;
    while (true) {
        long index = Math.round((time - reference.getTime()) / fPeriod) + reference.getIndex();
        long markerTime = Math.round((index - reference.getIndex()) * fPeriod) + reference.getTime();
        long duration = (fColor2 == null) ? 0 : Math.round((index + 1 - reference.getIndex()) * fPeriod) + reference.getTime() - markerTime;
        long labelIndex = index;
        if (fRollover != 0) {
            labelIndex %= fRollover;
            if (labelIndex < 0) {
                labelIndex += fRollover;
            }
        }
        /* Add previous marker if current is visible */
        if ((markerTime >= startTime || markerTime + duration > startTime) && annotation != null) {
            annotations.add(annotation);
        }
        if (isApplicable(labelIndex)) {
            OutputElementStyle style = Objects.requireNonNull((index % 2) == 0 ? styles[0] : styles[1]);
            annotation = new Annotation(markerTime, duration, -1, getAnnotationLabel(labelIndex), style);
        } else {
            annotation = null;
        }
        if (markerTime > endTime || (monitor != null && monitor.isCanceled())) {
            if (annotation != null && isApplicable(labelIndex)) {
                /* The next marker out of range is included */
                annotations.add(annotation);
            }
            break;
        }
        time += step;
    }
    Map<String, Collection<Annotation>> model = new HashMap<>();
    model.put(fCategory, annotations);
    // $NON-NLS-1$
    return new TmfModelResponse<>(new AnnotationModel(model), Status.COMPLETED, "");
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) HashMap(java.util.HashMap) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) ITimeReference(org.eclipse.tracecompass.tmf.core.markers.ITimeReference) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) NonNull(org.eclipse.jdt.annotation.NonNull)

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