Search in sources :

Example 21 with Annotation

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

the class CustomAnnotationProvider method getMarkers.

private Map<@NonNull String, @NonNull Collection<@NonNull Annotation>> getMarkers(Map<@NonNull String, @NonNull Object> fetchParams, @Nullable IProgressMonitor monitor) {
    List<@NonNull Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParams);
    if (timeRequested == null || timeRequested.size() < 2) {
        return Collections.emptyMap();
    }
    Long[] times = timeRequested.toArray(new Long[0]);
    long starttime = timeRequested.get(0);
    long endtime = timeRequested.get(timeRequested.size() - 1);
    int resolution = (int) Math.min(Integer.MAX_VALUE, timeRequested.get(1) - timeRequested.get(0));
    Map<@NonNull String, @NonNull Collection<@NonNull Annotation>> markerMap = new LinkedHashMap<>();
    for (CustomPeriodicAnnotationProvider periodicAnnotationProvider : fAnnotationProviders) {
        long minDuration = resolution * MIN_PERIOD;
        long maxDuration = (long) periodicAnnotationProvider.getPeriod();
        if (maxDuration > minDuration) {
            AnnotationModel model = periodicAnnotationProvider.fetchAnnotations(fetchParams, monitor).getModel();
            if (model != null) {
                Map<@NonNull String, @NonNull Collection<@NonNull Annotation>> annotations = model.getAnnotations();
                List<Annotation> markerList = new ArrayList<>();
                for (Entry<@NonNull String, @NonNull Collection<@NonNull Annotation>> entryAnnotation : annotations.entrySet()) {
                    String category = Objects.requireNonNull(entryAnnotation.getKey());
                    for (Annotation annotation : Objects.requireNonNull(entryAnnotation.getValue())) {
                        markerList.add(annotation);
                        for (SubMarker subMarker : periodicAnnotationProvider.getSubMarkers()) {
                            getSubMarkerList(Objects.requireNonNull(subMarker), annotation, markerMap, starttime, endtime, minDuration, times);
                        }
                    }
                    markerMap.put(category, markerList);
                }
            }
        }
    }
    @Nullable Set<@NonNull String> categoriesRequested = DataProviderParameterUtils.extractSelectedCategories(fetchParams);
    markerMap.keySet().removeIf(cat -> categoriesRequested != null && !categoriesRequested.contains(cat));
    return markerMap;
}
Also used : ArrayList(java.util.ArrayList) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) LinkedHashMap(java.util.LinkedHashMap) NonNull(org.eclipse.jdt.annotation.NonNull) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 22 with Annotation

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

the class BaseDataProviderTimeGraphView method getViewMarkerList.

@Override
@NonNull
protected List<IMarkerEvent> getViewMarkerList(Iterable<@NonNull TimeGraphEntry> entries, long startTime, long endTime, long resolution, @NonNull IProgressMonitor monitor) {
    List<IMarkerEvent> viewMarkerList = super.getViewMarkerList(startTime, endTime, resolution, monitor);
    List<@NonNull TimeGraphEntry> traceEntries = getEntryList(getTrace());
    if (traceEntries == null) {
        return viewMarkerList;
    }
    List<@NonNull Long> times = StateSystemUtils.getTimes(startTime, endTime, resolution);
    Multimap<ITimeGraphDataProvider<? extends TimeGraphEntryModel>, Long> providersToModelIds = filterGroupEntries(entries, startTime, endTime);
    for (ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider : providersToModelIds.keySet()) {
        if (provider instanceof IOutputAnnotationProvider) {
            List<String> categories = new ArrayList<>(fMarkerCategories.get(provider));
            categories.removeIf(category -> !getTimeGraphViewer().isMarkerCategoryVisible(category));
            if (categories.isEmpty()) {
                continue;
            }
            Map<@NonNull String, @NonNull Object> parameters = getFetchAnnotationsParameters(times, providersToModelIds.get(provider));
            parameters.put(DataProviderParameterUtils.REQUESTED_MARKER_CATEGORIES_KEY, categories);
            TmfModelResponse<@NonNull AnnotationModel> response = ((IOutputAnnotationProvider) provider).fetchAnnotations(parameters, new NullProgressMonitor());
            AnnotationModel model = response.getModel();
            if (model != null) {
                for (Entry<String, Collection<Annotation>> entry : model.getAnnotations().entrySet()) {
                    String category = entry.getKey();
                    for (Annotation annotation : entry.getValue()) {
                        if (annotation.getType() == AnnotationType.CHART) {
                            // If the annotation entry ID is -1 we want the
                            // marker to span across all entries
                            ITimeGraphEntry markerEntry = null;
                            if (annotation.getEntryId() != -1) {
                                synchronized (fEntries) {
                                    markerEntry = fEntries.get(provider, annotation.getEntryId());
                                }
                            }
                            MarkerEvent markerEvent = new MarkerEvent(annotation, markerEntry, category, true);
                            viewMarkerList.add(markerEvent);
                        }
                    }
                }
            }
        }
    }
    return viewMarkerList;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITimeGraphDataProvider(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphDataProvider) IOutputAnnotationProvider(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider) ArrayList(java.util.ArrayList) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) IMarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.IMarkerEvent) MarkerEvent(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.MarkerEvent) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) Collection(java.util.Collection) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)22 ArrayList (java.util.ArrayList)17 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)17 Test (org.junit.Test)15 List (java.util.List)10 IOutputAnnotationProvider (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IOutputAnnotationProvider)10 PeriodicAnnotationProvider (org.eclipse.tracecompass.internal.tmf.core.annotations.PeriodicAnnotationProvider)9 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)8 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)7 AnnotationModel (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel)6 Marker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker)5 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)5 MarkerSet (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet)5 SplitMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker)5 WeightedMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker)5 NonNull (org.eclipse.jdt.annotation.NonNull)4 Collection (java.util.Collection)3 OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)3 HashMap (java.util.HashMap)2 Nullable (org.eclipse.jdt.annotation.Nullable)2