use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation 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());
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation in project tracecompass by tracecompass.
the class CustomAnnotationProvider method getSubMarkerList.
private void getSubMarkerList(WeightedMarker weightedMarker, Annotation markerEvent, Map<String, Collection<@NonNull Annotation>> annotationMap, long startTime, long endTime, long minDuration, Long[] times) {
if (markerEvent.getTime() > endTime || markerEvent.getTime() + markerEvent.getDuration() < startTime) {
return;
}
long start = markerEvent.getTime();
long length = 0;
List<@NonNull Annotation> annotationsList = new ArrayList<>();
for (int i = 0; i < weightedMarker.getSegments().size(); i++) {
MarkerSegment segment = weightedMarker.getSegments().get(i);
length += segment.getLength();
long end = markerEvent.getTime() + Math.round((length / (double) weightedMarker.getTotalLength()) * markerEvent.getDuration());
long duration = end - start;
if (end >= startTime && duration > minDuration && !segment.getColor().isEmpty()) {
RGBAColor color = getColor(segment);
Annotation subAnnotation = new Annotation(start, end - start, -1, String.format(segment.getLabel(), i), getOutputStyle(color));
for (SubMarker subMarker : segment.getSubMarkers()) {
getSubMarkerList(Objects.requireNonNull(subMarker), subAnnotation, annotationMap, startTime, endTime, minDuration, times);
}
for (SubMarker subMarker : weightedMarker.getSubMarkers()) {
getSubMarkerList(Objects.requireNonNull(subMarker), subAnnotation, annotationMap, startTime, endTime, minDuration, times);
}
annotationsList.add(subAnnotation);
}
if (start >= endTime) {
break;
}
start = end;
}
populateMap(annotationMap, annotationsList, Objects.requireNonNull(weightedMarker.getName()));
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation 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, "");
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation 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, "");
}
use of org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation in project tracecompass by tracecompass.
the class CustomAnnotationProviderTest method testWeightedWithSubmarkers.
/**
* Test weighted with submarkers
*/
@Test
public void testWeightedWithSubmarkers() {
List<Annotation> annotationList;
MarkerSet set = new MarkerSet("name", "id");
fProvider.configure(set);
assertAnnotationCategoriesModelResponse(Collections.emptyList(), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
/*
* period: 40 ns, offset: 0 ns, range: 0..49, indexRange: 30..31,40
*
* requested range: 0 ns-4000 ns
*
* expected annotations: 1200 ns[30] 1240 ns[31] 1600 ns[40] 3200 ns[30]
* 3240 ns[31] 3600 ns[40]
*/
Marker markerD = new PeriodicMarker("D", "D %d", "d", "ref.d", COLOR_STR, 40.0, "ns", Range.closed(0L, 49L), 0L, ImmutableRangeSet.<Long>builder().add(Range.closed(30L, 31L)).add(Range.singleton(40L)).build());
set.addMarker(markerD);
/*
* period: 40 ns with segment weights {2,1,3}, offset: 0 ns,
* range:0..49, indexRange:30..31,40
*
* requested range: 0 ns-2000 ns
*
* expected annotations: 1200 ns[0] 1220[2] 1240 ns[0] 1260[2] 1600 ns[0]
* 1620 ns[2]
*/
WeightedMarker markerE = new WeightedMarker("E");
markerD.addSubMarker(markerE);
MarkerSegment segmentE1 = new MarkerSegment("E1 %d", "e1", RED_STR, 2);
markerE.addSegment(segmentE1);
MarkerSegment segmentE2 = new MarkerSegment("E2 %d", "e2", "", 1);
markerE.addSegment(segmentE2);
MarkerSegment segmentE3 = new MarkerSegment("E3 %d", "e3", INVALID_STR, 3);
markerE.addSegment(segmentE3);
fProvider.configure(set);
assertAnnotationCategoriesModelResponse(Arrays.asList("D", "E"), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
annotationList = getAnnotationList("E", 0L, 2000L, 1L, new NullProgressMonitor());
assertEquals(6, annotationList.size());
int i = 0;
for (long t = 0L; t < 2000L; t += 40L) {
int index = (int) (t / 40L) % 50;
if (index == 30L || index == 31L || index == 40L) {
validateAnnotation(annotationList.get(i), t, 13L, "E", String.format("E1 %d", 0), RED);
i++;
/*
* segment 2 does not have visible annotation due to empty color
* name
*/
validateAnnotation(annotationList.get(i), t + 20L, 20L, "E", String.format("E3 %d", 2), DEFAULT);
i++;
}
}
}
Aggregations