Search in sources :

Example 1 with IStateHistoryBackend

use of org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend in project tracecompass by tracecompass.

the class CounterStateProviderTest method setup.

/**
 * Setup the trace and the state provider for the tests.
 *
 * @throws TmfTraceException
 *             Exception thrown when initiating the trace
 */
@Before
public void setup() throws TmfTraceException {
    // Create the trace
    TmfXmlTraceStubNs trace = new TmfXmlTraceStubNs();
    trace.initTrace(null, COUNTER_FILE, ITmfEvent.class);
    // Add different varieties of aspects
    trace.addEventAspect(new TmfContentFieldAspect("aspect"));
    trace.addEventAspect(new CounterAspect("counter", "counter"));
    trace.addEventAspect(new CounterAspect("counter", "counter", TmfCpuAspect.class));
    trace.addEventAspect(new CounterAspect("counter", "counter", TmfCpuAspect.class) {

        @Override
        public boolean isCumulative() {
            return true;
        }
    });
    assertEquals(8, Iterables.size(trace.getEventAspects()));
    // Create the state provider
    fStateProvider = CounterStateProvider.create(trace);
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend("CounterStateSystem", 0);
    fSsb = StateSystemFactory.newStateSystem(backend);
    fStateProvider.assignTargetStateSystem(fSsb);
    fTrace = trace;
}
Also used : TmfXmlTraceStubNs(org.eclipse.tracecompass.tmf.tests.stubs.trace.xml.TmfXmlTraceStubNs) TmfCpuAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect) TmfContentFieldAspect(org.eclipse.tracecompass.tmf.core.event.aspect.TmfContentFieldAspect) CounterAspect(org.eclipse.tracecompass.analysis.counters.core.aspects.CounterAspect) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Before(org.junit.Before)

Example 2 with IStateHistoryBackend

use of org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testQueryOngoingStackTop.

/**
 * Test the queryOngoingStackTop() method.
 */
@Test
public void testQueryOngoingStackTop() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, START_TIME);
    ITmfStateSystemBuilder ss = StateSystemFactory.newStateSystem(backend);
    int quark = ss.getQuarkAbsoluteAndAdd(DUMMY_STRING);
    assertEquals(null, StateSystemUtils.queryOngoingStackTop(ss, quark));
    ss.pushAttribute(1100L, "A", quark);
    assertEquals("A", StateSystemUtils.queryOngoingStackTop(ss, quark));
    ss.pushAttribute(1200L, "B", quark);
    assertEquals("B", StateSystemUtils.queryOngoingStackTop(ss, quark));
    ss.popAttribute(1300L, quark);
    assertEquals("A", StateSystemUtils.queryOngoingStackTop(ss, quark));
    ss.popAttribute(1400L, quark);
    assertEquals(null, StateSystemUtils.queryOngoingStackTop(ss, quark));
    ss.closeHistory(1500L);
    ss.dispose();
}
Also used : ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 3 with IStateHistoryBackend

use of org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend in project tracecompass by tracecompass.

the class StateSystemUtilsTest method setupStateSystem.

/**
 * Build a small test state system in memory
 */
@Before
public void setupStateSystem() {
    try {
        IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, START_TIME);
        fStateSystem = StateSystemFactory.newStateSystem(backend);
        int quark = fStateSystem.getQuarkAbsoluteAndAdd(DUMMY_STRING);
        fStateSystem.modifyAttribute(1200L, 10, quark);
        fStateSystem.modifyAttribute(1500L, 20, quark);
        fStateSystem.closeHistory(2000L);
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    }
}
Also used : StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Before(org.junit.Before)

Example 4 with IStateHistoryBackend

use of org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkResolution.

/**
 * Test that the QuarkIterator returns the correct intervals for a range
 * included in the state system range and a resolution
 */
@Test
public void testIteratorOverQuarkResolution() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(DUMMY_STRING, 1L);
    ITmfStateSystemBuilder ss = StateSystemFactory.newStateSystem(backend);
    try {
        // Create a small state system with intervals for a resolution
        int quark = ss.getQuarkAbsoluteAndAdd(DUMMY_STRING);
        /**
         * Here follows the state system, with each dash representing a nanosecond and
         * vertical line a change of state. The time are the times that are expected to
         * be queried
         *
         * <pre>
         *
         * resolution of 4:  2   6      10
         * resolution of 3:  2  5    8   11
         *                  ------|-|-|----
         * </pre>
         */
        ss.modifyAttribute(1L, 1, quark);
        ss.modifyAttribute(7L, 2, quark);
        ss.modifyAttribute(8L, 1, quark);
        ss.modifyAttribute(9L, 2, quark);
        ss.closeHistory(12L);
        // Verify a resolution of 4
        QuarkIterator iterator = new QuarkIterator(ss, quark, 2, 14, 4);
        /*
             * With steps of 4, there should be 2 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
        // Verify a resolution of 3
        iterator = new QuarkIterator(ss, quark, 2, 14, 3);
        /*
             * With steps of 3, there should be 3 intervals and they should be the same
             * forward and backward
             */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        // Check second interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the interval forward
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(9L, interval.getStartTime());
        assertEquals(12L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        // Check the first interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(8L, interval.getStartTime());
        assertEquals(8L, interval.getEndTime());
        // Check the second interval backward
        assertTrue(iterator.hasPrevious());
        interval = iterator.previous();
        assertNotNull(interval);
        assertEquals(1L, interval.getStartTime());
        assertEquals(6L, interval.getEndTime());
        assertFalse(iterator.hasPrevious());
    } catch (StateValueTypeException e) {
        fail(e.getMessage());
    } finally {
        ss.dispose();
    }
}
Also used : QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 5 with IStateHistoryBackend

use of org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend in project tracecompass by tracecompass.

the class InMemoryBackendTest method init.

/**
 * Test setup. make a state system that is moderately large
 */
@BeforeClass
public static void init() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(SSID, 0);
    for (int attribute = 0; attribute < NUMBER_OF_ATTRIBUTES; attribute++) {
        for (int timeStart = 0; timeStart < 1000; timeStart++) {
            try {
                final int stateEndTime = (timeStart * 100) + 90 + attribute;
                final int stateStartTime = timeStart * 100 + attribute;
                backend.insertPastState(stateStartTime, stateEndTime, attribute, timeStart % 100);
                if (timeStart != 999) {
                    backend.insertPastState(stateEndTime + 1, stateEndTime + 9, attribute, (Object) null);
                }
            } catch (TimeRangeException e) {
                /* Should not happen here */
                throw new IllegalStateException();
            }
        }
    }
    fixture = backend;
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) BeforeClass(org.junit.BeforeClass)

Aggregations

IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)36 Test (org.junit.Test)21 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)16 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)12 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)10 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)8 IOException (java.io.IOException)7 Before (org.junit.Before)6 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)5 ArrayList (java.util.ArrayList)3 StateSystem (org.eclipse.tracecompass.internal.statesystem.core.StateSystem)3 BeforeClass (org.junit.BeforeClass)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)2 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)2 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)2 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)2 CustomStateValueStub (org.eclipse.tracecompass.statesystem.core.tests.stubs.statevalues.CustomStateValueStub)2 TmfTraceException (org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException)2 File (java.io.File)1