use of org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment in project tracecompass by tracecompass.
the class MarkerConfigXmlParserTest method testParse.
/**
* Test the parse method
*
* @throws IOException if an exception occurs
*/
@Test
public void testParse() throws IOException {
File file = File.createTempFile("markers", "xml");
try (FileWriter fw = new FileWriter(file)) {
fw.write(XML_CONTENT);
fw.flush();
List<MarkerSet> markerSets = MarkerConfigXmlParser.parse(file.getAbsolutePath());
assertEquals(2, markerSets.size());
MarkerSet setA = markerSets.get(0);
assertEquals("Set A", setA.getName());
assertEquals("set.a", setA.getId());
assertEquals(3, setA.getMarkers().size());
PeriodicMarker markerA1 = (PeriodicMarker) setA.getMarkers().get(0);
assertEquals("Marker A-1", markerA1.getName());
assertEquals("A-1 %d", markerA1.getLabel());
assertEquals("marker.a.1", markerA1.getId());
assertEquals("ref.a.1", markerA1.getReferenceId());
assertEquals("#0000ff", markerA1.getColor());
assertEquals(10.0, markerA1.getPeriod(), 0);
assertEquals("ms", markerA1.getUnit());
assertEquals(Range.closed(0L, 4095L), markerA1.getRange());
assertEquals(0, markerA1.getOffset());
assertEquals(1, markerA1.getSubMarkers().size());
SplitMarker submarkerA11 = (SplitMarker) markerA1.getSubMarkers().get(0);
assertEquals("Submarker A-1-1", submarkerA11.getName());
assertEquals("A-1-1 %d", submarkerA11.getLabel());
assertEquals("submarker.a.1.1", submarkerA11.getId());
assertEquals("#000000", submarkerA11.getColor());
assertEquals(Range.closed(0L, 99L), submarkerA11.getRange());
assertEquals(1, submarkerA11.getSubMarkers().size());
SplitMarker submarkerA111 = (SplitMarker) submarkerA11.getSubMarkers().get(0);
assertEquals("Submarker A-1-1-1", submarkerA111.getName());
assertEquals("A-1-1-1 %d", submarkerA111.getLabel());
assertEquals("submarker.a.1.1.1", submarkerA111.getId());
assertEquals("#000000", submarkerA111.getColor());
assertEquals(Range.closed(0L, 9L), submarkerA111.getRange());
assertEquals(0, submarkerA111.getSubMarkers().size());
PeriodicMarker markerA2 = (PeriodicMarker) setA.getMarkers().get(1);
assertEquals("Marker A-2", markerA2.getName());
assertEquals("A-2 %d", markerA2.getLabel());
assertEquals("marker.a.2", markerA2.getId());
assertEquals("ref.a.2", markerA2.getReferenceId());
assertEquals("#ff0000", markerA2.getColor());
assertEquals(20.0, markerA2.getPeriod(), 0);
assertEquals("us", markerA2.getUnit());
assertEquals(Range.atLeast(0L), markerA2.getRange());
assertEquals(0, markerA2.getOffset());
assertEquals(0, markerA2.getSubMarkers().size());
PeriodicMarker markerA3 = (PeriodicMarker) setA.getMarkers().get(2);
assertEquals("Marker A-3", markerA3.getName());
assertEquals("A-3 %d", markerA3.getLabel());
assertEquals("marker.a.3", markerA3.getId());
assertEquals("ref.a.3", markerA3.getReferenceId());
assertEquals("#00ff00", markerA3.getColor());
assertEquals(2.5, markerA3.getPeriod(), 0);
assertEquals("ns", markerA3.getUnit());
assertEquals(Range.atLeast(0L), markerA3.getRange());
assertEquals(0, markerA3.getOffset());
assertEquals(1, markerA3.getSubMarkers().size());
WeightedMarker submarkerA31 = (WeightedMarker) markerA3.getSubMarkers().get(0);
assertEquals("Submarker A-3-1", submarkerA31.getName());
assertEquals(0, submarkerA31.getSubMarkers().size());
assertEquals(2, submarkerA31.getSegments().size());
MarkerSegment submarkerA31a = submarkerA31.getSegments().get(0);
assertEquals(null, submarkerA31a.getName());
assertEquals("A-3-1-a %d", submarkerA31a.getLabel());
assertEquals("marker.a.3.1.a", submarkerA31a.getId());
assertEquals("#aaaaaa", submarkerA31a.getColor());
assertEquals(1, submarkerA31a.getLength());
assertEquals(0, submarkerA31a.getSubMarkers().size());
MarkerSegment submarkerA31b = submarkerA31.getSegments().get(1);
assertEquals(null, submarkerA31b.getName());
assertEquals("A-3-1-b %d", submarkerA31b.getLabel());
assertEquals("marker.a.3.1.b", submarkerA31b.getId());
assertEquals("#bbbbbb", submarkerA31b.getColor());
assertEquals(2, submarkerA31b.getLength());
assertEquals(0, submarkerA31b.getSubMarkers().size());
MarkerSet setB = markerSets.get(1);
assertEquals("Set B", setB.getName());
assertEquals("set.b", setB.getId());
assertEquals(1, setB.getMarkers().size());
PeriodicMarker markerB1 = (PeriodicMarker) setB.getMarkers().get(0);
assertEquals("Marker B-1", markerB1.getName());
assertEquals("B-1 %d", markerB1.getLabel());
assertEquals("marker.b.1", markerB1.getId());
assertEquals("ref.b.1", markerB1.getReferenceId());
assertEquals("#010203", markerB1.getColor());
assertEquals(1000.0, markerB1.getPeriod(), 0);
assertEquals("cycles", markerB1.getUnit());
assertEquals(Range.atLeast(1L), markerB1.getRange());
assertEquals(5, markerB1.getOffset());
assertEquals(2, markerB1.getSubMarkers().size());
SplitMarker submarkerB11 = (SplitMarker) markerB1.getSubMarkers().get(0);
assertEquals("Submarker B-1-1", submarkerB11.getName());
assertEquals("submarker.b.1.1", submarkerB11.getId());
assertEquals("#010203", submarkerB11.getColor());
assertEquals(Range.closed(1L, 10L), submarkerB11.getRange());
assertEquals(0, submarkerB11.getSubMarkers().size());
SplitMarker submarkerB12 = (SplitMarker) markerB1.getSubMarkers().get(1);
assertEquals("Submarker B-1-2", submarkerB12.getName());
assertEquals("submarker.b.1.2", submarkerB12.getId());
assertEquals("#010203", submarkerB12.getColor());
assertEquals(Range.closed(1L, 100L), submarkerB12.getRange());
assertEquals(0, submarkerB12.getSubMarkers().size());
} finally {
file.delete();
}
}
use of org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment in project tracecompass by tracecompass.
the class MarkerTest method testAddSegment.
/**
* Test the MarkerSegment constructor and method addSegment
*/
@Test
public void testAddSegment() {
WeightedMarker subMarker = new WeightedMarker("name");
MarkerSegment segmentA = new MarkerSegment("A", "a", "color1", 1);
subMarker.addSegment(segmentA);
MarkerSegment segmentB = new MarkerSegment("B", "b", "color2", 2);
subMarker.addSegment(segmentB);
assertEquals(Arrays.asList(segmentA, segmentB), subMarker.getSegments());
}
use of org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment in project tracecompass by tracecompass.
the class CustomAnnotationProvider method getSubMarkerCategories.
private void getSubMarkerCategories(Set<String> categories, List<SubMarker> subMarkers) {
for (SubMarker subMarker : subMarkers) {
categories.add(subMarker.getName());
getSubMarkerCategories(categories, subMarker.getSubMarkers());
if (subMarker instanceof WeightedMarker) {
for (MarkerSegment segment : ((WeightedMarker) subMarker).getSegments()) {
getSubMarkerCategories(categories, segment.getSubMarkers());
}
}
}
}
use of org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment 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.tmf.core.markers.MarkerSegment 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