Search in sources :

Example 1 with AnnotationModel

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel in project tracecompass by tracecompass.

the class TmfTreeDataModelTest method testCompositeTree.

/**
 * Test {@link TmfTreeCompositeDataProvider}
 */
@Test
public void testCompositeTree() {
    List<DummyDataProvider> ddps = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ddps.add(new DummyDataProvider(i));
    }
    TmfTreeCompositeDataProvider<@NonNull TmfTreeDataModel, @NonNull DummyDataProvider> composite = new TmfTreeCompositeDataProvider<>(ddps, "composite-dummy");
    assertNotNull(composite);
    NullProgressMonitor monitor = new NullProgressMonitor();
    TmfModelResponse<@NonNull TmfTreeModel<@NonNull TmfTreeDataModel>> tree = composite.fetchTree(Collections.emptyMap(), monitor);
    TmfTreeModel<@NonNull TmfTreeDataModel> model = tree.getModel();
    assertNotNull(model);
    assertEquals(Arrays.asList("header"), model.getHeaders());
    assertEquals(3, model.getEntries().size());
    // AnnotationCategories
    TmfModelResponse<@NonNull AnnotationCategoriesModel> returnVal = composite.fetchAnnotationCategories(Collections.emptyMap(), monitor);
    AnnotationCategoriesModel categoryModel = returnVal.getModel();
    assertNotNull(categoryModel);
    assertEquals(Arrays.asList("common", "0", "1", "2"), categoryModel.getAnnotationCategories());
    // Annotations
    TmfModelResponse<@NonNull AnnotationModel> annotations = composite.fetchAnnotations(Collections.emptyMap(), monitor);
    AnnotationModel annotationsModel = annotations.getModel();
    assertNotNull(annotationsModel);
    Collection<@NonNull Annotation> collection = annotationsModel.getAnnotations().get("test");
    assertNotNull(collection);
    assertEquals(6, collection.size());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AnnotationCategoriesModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel) ArrayList(java.util.ArrayList) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) NonNull(org.eclipse.jdt.annotation.NonNull) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TmfTreeCompositeDataProvider(org.eclipse.tracecompass.internal.tmf.core.model.tree.TmfTreeCompositeDataProvider) Test(org.junit.Test)

Example 2 with AnnotationModel

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel 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 3 with AnnotationModel

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel 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)

Example 4 with AnnotationModel

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel in project tracecompass by tracecompass.

the class TmfTreeCompositeDataProvider method fetchAnnotations.

@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    boolean isComplete = true;
    AnnotationModel model = new AnnotationModel(Collections.emptyMap());
    for (P dataProvider : getProviders()) {
        if (dataProvider instanceof IOutputAnnotationProvider) {
            TmfModelResponse<AnnotationModel> response = ((IOutputAnnotationProvider) dataProvider).fetchAnnotations(fetchParameters, monitor);
            isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
            model = AnnotationModel.of(model, response.getModel());
            if (monitor != null && monitor.isCanceled()) {
                return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
        }
    }
    if (isComplete) {
        return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
    }
    return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Also used : AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)

Example 5 with AnnotationModel

use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel in project tracecompass by tracecompass.

the class CustomAnnotationProviderTest method getAnnotationList.

private List<@NonNull Annotation> getAnnotationList(String category, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
    Map<String, Object> fetchParameters = ImmutableMap.of(DataProviderParameterUtils.REQUESTED_MARKER_CATEGORIES_KEY, Collections.singleton(category), DataProviderParameterUtils.REQUESTED_TIME_KEY, StateSystemUtils.getTimes(startTime, endTime, resolution));
    TmfModelResponse<@NonNull AnnotationModel> response = fProvider.fetchAnnotations(fetchParameters, monitor);
    assertEquals(Status.COMPLETED, response.getStatus());
    AnnotationModel model = response.getModel();
    assertNotNull(model);
    assertEquals(Collections.singleton(category), model.getAnnotations().keySet());
    return new ArrayList<>(model.getAnnotations().get(category));
}
Also used : AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) ArrayList(java.util.ArrayList)

Aggregations

AnnotationModel (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel)8 ArrayList (java.util.ArrayList)7 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)6 NonNull (org.eclipse.jdt.annotation.NonNull)4 Collection (java.util.Collection)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)3 HashMap (java.util.HashMap)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 IOutputAnnotationProvider (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider)2 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 AnnotationCategoriesModel (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationCategoriesModel)1 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)1 TmfTreeCompositeDataProvider (org.eclipse.tracecompass.internal.tmf.core.model.tree.TmfTreeCompositeDataProvider)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)1 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)1