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;
}
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();
}
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());
}
}
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();
}
}
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;
}
Aggregations