Search in sources :

Example 6 with AnnotationModel

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

the class PeriodicAnnotationProviderTest method assertAnnotationModelResponse.

private static void assertAnnotationModelResponse(Map<String, List<Annotation>> expectedMap, TmfModelResponse<AnnotationModel> response) {
    assertEquals(Status.COMPLETED, response.getStatus());
    AnnotationModel model = response.getModel();
    assertNotNull(model);
    for (Entry<String, List<Annotation>> entry : expectedMap.entrySet()) {
        String category = entry.getKey();
        List<Annotation> expectedList = entry.getValue();
        Collection<@NonNull Annotation> actualCollection = model.getAnnotations().get(category);
        assertNotNull(actualCollection);
        assertEquals(expectedList.size(), actualCollection.size());
        List<Annotation> actualList = new ArrayList<>(actualCollection);
        for (int i = 0; i < expectedList.size(); i++) {
            Annotation expected = expectedList.get(i);
            Annotation actual = actualList.get(i);
            assertEquals("Time comparison for index " + i + " " + actual.toString(), expected.getTime(), actual.getTime());
            assertEquals("Duration comparison for index " + i + " " + actual.toString(), expected.getDuration(), actual.getDuration());
            assertEquals("EntryId comparison for index " + i + " " + actual.toString(), expected.getEntryId(), actual.getEntryId());
            assertEquals("Label comparison for index " + i + " " + actual.toString(), expected.getLabel(), actual.getLabel());
            assertEquals("Style comparison for index " + i + " " + actual.toString(), expected.getStyle(), actual.getStyle());
        }
    }
}
Also used : AnnotationModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.AnnotationModel) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)

Example 7 with AnnotationModel

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

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

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