Search in sources :

Example 1 with TmfXmlPatternSegment

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment in project tracecompass by tracecompass.

the class XmlSegmentTest method doTestSegmentContent.

private static void doTestSegmentContent(XmlPatternAnalysis module) {
    @Nullable ISegmentStore<@NonNull ISegment> ss = module.getSegmentStore();
    assertNotNull(ss);
    assertEquals("Segment store size", 4, ss.size());
    Iterator<@NonNull ISegment> iterator = ss.iterator();
    // first segment
    assertTrue(iterator.hasNext());
    ISegment segment1 = iterator.next();
    assertTrue(segment1 instanceof TmfXmlPatternSegment);
    XmlUtilsTest.testPatternSegmentData(SEGMENT_1, (TmfXmlPatternSegment) segment1);
    // second segment
    assertTrue(iterator.hasNext());
    ISegment segment2 = iterator.next();
    assertTrue(segment2 instanceof TmfXmlPatternSegment);
    XmlUtilsTest.testPatternSegmentData(SEGMENT_2, (TmfXmlPatternSegment) segment2);
    // third segment
    assertTrue(iterator.hasNext());
    ISegment segment3 = iterator.next();
    assertTrue(segment3 instanceof TmfXmlPatternSegment);
    XmlUtilsTest.testPatternSegmentData(SEGMENT_3, (TmfXmlPatternSegment) segment3);
    // fourth segment
    assertTrue(iterator.hasNext());
    ISegment segment4 = iterator.next();
    assertTrue(segment4 instanceof TmfXmlPatternSegment);
    XmlUtilsTest.testPatternSegmentData(SEGMENT_4, (TmfXmlPatternSegment) segment4);
    assertFalse(iterator.hasNext());
    // Compare segments
    // segment1 < segment3, comparison by string (end time)
    assertEquals(-1, segment1.compareTo(segment3));
    assertEquals(1, segment3.compareTo(segment1));
    // segment1 < segment2, comparison by name
    assertEquals(-1, segment1.compareTo(segment2));
    assertEquals(1, segment2.compareTo(segment1));
    assertEquals(0, segment2.compareTo(segment2));
    // segment2 < segment4, comparison by content
    assertEquals(-1, segment2.compareTo(segment4));
    assertEquals(1, segment4.compareTo(segment2));
}
Also used : TmfXmlPatternSegment(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with TmfXmlPatternSegment

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment in project tracecompass by tracecompass.

the class DataDrivenActionSegment method eventHandle.

@Override
public void eventHandle(ITmfEvent event, DataDrivenScenarioInfo scenarioInfo, IAnalysisDataContainer container) {
    if (!(container instanceof DataDrivenPattern)) {
        // This action should only be run with pattern state provider
        return;
    }
    DataDrivenPattern provider = (DataDrivenPattern) container;
    // Get the default timestamp
    long start = provider.getExecutionData().getHistoryBuilder().getStartTime(container, scenarioInfo, event);
    long end = event.getTimestamp().toNanos();
    Object segmentName = fType.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
    Map<String, Object> fields = new HashMap<>();
    for (Entry<String, DataDrivenValue> field : fFields.entrySet()) {
        Object value = field.getValue().getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        // Segment content does not support null values
        if (value != null) {
            if (value instanceof ITmfStateValue) {
                if (!((ITmfStateValue) value).isNull()) {
                    fields.put(field.getKey(), Objects.requireNonNull(((ITmfStateValue) value).unboxValue()));
                }
            } else {
                fields.put(field.getKey(), value);
            }
        }
    }
    // Set the start time
    if (fStart != null) {
        Object startVal = fStart.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (startVal instanceof Number) {
            start = ((Number) startVal).longValue();
        }
    }
    // Set the end time
    if (fEnd != null) {
        Object endVal = fEnd.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (endVal instanceof Number) {
            long endL = ((Number) endVal).longValue();
            end = endL >= start ? endL : end;
        }
    } else if (fDuration != null) {
        Object durationVal = fDuration.getValue(event, ITmfStateSystem.ROOT_ATTRIBUTE, scenarioInfo, container);
        if (durationVal instanceof Number) {
            long durationL = ((Number) durationVal).longValue();
            long endL = start + durationL;
            end = endL >= start ? endL : end;
        }
    }
    TmfXmlPatternSegment segment = new TmfXmlPatternSegment(start, end, String.valueOf(segmentName), fields);
    provider.getListener().onNewSegment(segment);
}
Also used : TmfXmlPatternSegment(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment) HashMap(java.util.HashMap) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) DataDrivenPattern(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.pattern.DataDrivenPattern)

Example 3 with TmfXmlPatternSegment

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment in project tracecompass by tracecompass.

the class FsmTest method testTwoInitialStates.

/**
 * Execute one pattern, with the two types of initial state initialization,
 * then test that the new behavior is prioritized and that preconditions are
 * ignored with initialState element
 *
 * @throws AttributeNotFoundException
 *             Exceptions thrown querying the state system
 * @throws StateSystemDisposedException
 *             Exceptions thrown querying the state system
 */
@Test
public void testTwoInitialStates() throws AttributeNotFoundException, StateSystemDisposedException {
    // Test segment store
    ISegmentStore<@NonNull ISegment> ss = fModule2.getSegmentStore();
    assertNotNull("segment store exist", ss);
    assertTrue("Segment store not empty", ss.size() == 1);
    Object item = ss.iterator().next();
    assertTrue(item instanceof TmfXmlPatternSegment);
    assertTrue(((TmfXmlPatternSegment) item).getName().equals(TEST_SEGMENT_NEW));
    // Test state system
    ITmfStateSystem stateSystem = fModule2.getStateSystem(fModule2.getId());
    assertNotNull("state system exist", stateSystem);
    int quark = stateSystem.getQuarkAbsolute("count_new");
    ITmfStateInterval interval = stateSystem.querySingleState(END_TIME, quark);
    int count = interval.getStateValue().unboxInt();
    assertTrue("Test the count value", count > 0);
    quark = stateSystem.optQuarkAbsolute("precond");
    assertEquals(ITmfStateSystem.INVALID_ATTRIBUTE, quark);
}
Also used : TmfXmlPatternSegment(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Aggregations

TmfXmlPatternSegment (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.segment.TmfXmlPatternSegment)3 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)2 HashMap (java.util.HashMap)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 DataDrivenValue (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue)1 DataDrivenPattern (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.pattern.DataDrivenPattern)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)1 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)1 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)1 Test (org.junit.Test)1