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());
}
}
}
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;
}
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;
}
Aggregations