Search in sources :

Example 1 with SplitMarker

use of org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker 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();
    }
}
Also used : MarkerSet(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet) WeightedMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) FileWriter(java.io.FileWriter) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) MarkerSegment(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment) File(java.io.File) Test(org.junit.Test)

Example 2 with SplitMarker

use of org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker in project tracecompass by tracecompass.

the class CustomAnnotationProviderTest method testSubmarkers.

/**
 * Test submarkers
 */
@Test
public void testSubmarkers() {
    List<Annotation> annotationList;
    MarkerSet set = new MarkerSet("name", "id");
    fProvider.configure(set);
    assertAnnotationCategoriesModelResponse(Collections.emptyList(), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
    /*
         * period: 10 ms, offset: 20 ms, range: 0..4
         *
         * requested range: 100 ms-200 ms
         *
         * expected annotations: 90 ms[2] 100 ms[3] 110 ms[4] 120 ms[0] ... 200
         * ms[3] 210 ms[4]
         */
    Marker markerA = new PeriodicMarker("A", "A %d", "a", "ref.a", COLOR_STR, 10.0, "ms", Range.closed(0L, 4L), 20L, ImmutableRangeSet.of(Range.all()));
    set.addMarker(markerA);
    fProvider.configure(set);
    /*
         * period: 10 us, offset: 20 ms, range: 1..1000
         *
         * requested range: 100 ms-200 ms
         *
         * expected annotations: 99.99 ms[1000] 100.00 ms[1] 100.01 ms[2] 100.02
         * ms[2] ... 200.00 ms[1]
         */
    SubMarker markerB = new SplitMarker("B", "B %d", "b", COLOR_STR, Range.closed(1L, 1000L), ImmutableRangeSet.of(Range.all()));
    markerA.addSubMarker(markerB);
    fProvider.configure(set);
    assertAnnotationCategoriesModelResponse(Arrays.asList("A", "B"), fProvider.fetchAnnotationCategories(Collections.emptyMap(), new NullProgressMonitor()));
    annotationList = getAnnotationList("B", 100000000L, 200000000L, 10000L, new NullProgressMonitor());
    assertEquals(0, annotationList.size());
    annotationList = getAnnotationList("B", 100000000L, 200000000L, 1000L, new NullProgressMonitor());
    assertEquals(10002, annotationList.size());
    for (int i = 0; i < annotationList.size(); i++) {
        long t = (i + 9999) * 10000L;
        int index = (i + 9999) - 2000;
        int labelIndex = 1 + index % 1000;
        RGBAColor color = labelIndex % 2 == 0 ? COLOR : ODD_COLOR;
        validateAnnotation(annotationList.get(i), t, 10000L, "B", String.format("B %d", labelIndex), color);
    }
}
Also used : MarkerSet(org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) RGBAColor(org.eclipse.tracecompass.tmf.core.presentation.RGBAColor) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) Marker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) WeightedMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) Annotation(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation) Test(org.junit.Test)

Example 3 with SplitMarker

use of org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker in project tracecompass by tracecompass.

the class MarkerConfigXmlParser method parseSubMarkers.

private static void parseSubMarkers(Element marker, Marker parent) {
    NodeList nodeList = marker.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getNodeName().equals(IMarkerConstants.SUBMARKER)) {
                Element subMarkerElem = (Element) node;
                String name = subMarkerElem.getAttribute(IMarkerConstants.NAME);
                String label = parseLabel(subMarkerElem.getAttribute(IMarkerConstants.LABEL));
                String id = subMarkerElem.getAttribute(IMarkerConstants.ID);
                String color = subMarkerElem.getAttribute(IMarkerConstants.COLOR);
                if (color.isEmpty()) {
                    color = parent.getColor();
                }
                String rangeAttr = subMarkerElem.getAttribute(IMarkerConstants.RANGE);
                Range<Long> range = parseRange(rangeAttr);
                if (!range.hasLowerBound() || !range.hasUpperBound()) {
                    // $NON-NLS-1$
                    throw new IllegalArgumentException("Unsupported unbound range: " + range);
                }
                RangeSet<Long> indexRange = parseRangeSet(subMarkerElem.getAttribute(IMarkerConstants.INDEX));
                SplitMarker subMarker = new SplitMarker(name, label, id, color, range, indexRange);
                parent.addSubMarker(subMarker);
                parseSubMarkers(subMarkerElem, subMarker);
            } else if (node.getNodeName().equals(IMarkerConstants.SEGMENTS)) {
                Element segmentsElem = (Element) node;
                String name = segmentsElem.getAttribute(IMarkerConstants.NAME);
                WeightedMarker subMarker = new WeightedMarker(name);
                parent.addSubMarker(subMarker);
                parseSegments(segmentsElem, subMarker);
                parseSubMarkers(segmentsElem, subMarker);
            }
        }
    }
}
Also used : WeightedMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Element(org.w3c.dom.Element)

Example 4 with SplitMarker

use of org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker in project tracecompass by tracecompass.

the class MarkerTest method testAddSubMarker.

/**
 * Test the SplitMarker and WeightedMarker constructors and method addMarker
 */
@Test
public void testAddSubMarker() {
    PeriodicMarker marker = new PeriodicMarker("name", "label", "id", "referenceid", "color", 1.0, "ms", Range.atLeast(0L), 0L, ImmutableRangeSet.of(Range.all()));
    SubMarker subMarkerA = new SplitMarker("A", "a", "a", "color", Range.atLeast(0L), ImmutableRangeSet.of(Range.all()));
    marker.addSubMarker(subMarkerA);
    SubMarker subMarkerB = new WeightedMarker("B");
    marker.addSubMarker(subMarkerB);
    assertEquals(Arrays.asList(subMarkerA, subMarkerB), marker.getSubMarkers());
}
Also used : WeightedMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker) SplitMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker) PeriodicMarker(org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker) SubMarker(org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker) Test(org.junit.Test)

Aggregations

SplitMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.SplitMarker)4 WeightedMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker.WeightedMarker)4 PeriodicMarker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker.PeriodicMarker)3 Test (org.junit.Test)3 MarkerSet (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSet)2 SubMarker (org.eclipse.tracecompass.internal.tmf.core.markers.SubMarker)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)1 Marker (org.eclipse.tracecompass.internal.tmf.core.markers.Marker)1 MarkerSegment (org.eclipse.tracecompass.internal.tmf.core.markers.MarkerSegment)1 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1