use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException 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.exceptions.StateValueTypeException 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.exceptions.StateValueTypeException in project tracecompass by tracecompass.
the class StateSystem method pushAttribute.
@Override
public void pushAttribute(long t, Object value, int attributeQuark) throws TimeRangeException, StateValueTypeException {
int stackDepth;
int subAttributeQuark;
Object previousSV = transState.getOngoingStateValue(attributeQuark);
if (previousSV == null) {
/*
* If the StateValue was null, this means this is the first time we
* use this attribute. Leave stackDepth at 0.
*/
stackDepth = 0;
} else if (previousSV instanceof Integer) {
/* Previous value was an integer, all is good, use it */
stackDepth = (int) previousSV;
} else {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new StateValueTypeException(getSSID() + " Quark:" + attributeQuark + ", Type:" + previousSV.getClass() + ", Expected:" + Type.INTEGER);
}
if (stackDepth >= MAX_STACK_DEPTH) {
/*
* Limit stackDepth to 100000, to avoid having Attribute Trees grow
* out of control due to buggy insertions
*/
// $NON-NLS-1$
String message = " Stack limit reached, not pushing";
// $NON-NLS-1$
throw new IllegalStateException(getSSID() + " Quark:" + attributeQuark + message);
}
stackDepth++;
subAttributeQuark = getQuarkRelativeAndAdd(attributeQuark, String.valueOf(stackDepth));
modifyAttribute(t, stackDepth, attributeQuark);
modifyAttribute(t, value, subAttributeQuark);
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.
the class TransientState method processStateChange.
/**
* Process a state change to be inserted in the history.
*
* @param eventTime
* The timestamp associated with this state change
* @param value
* The new StateValue associated to this attribute
* @param quark
* The quark of the attribute that is being modified
* @throws TimeRangeException
* If 'eventTime' is invalid
* @throws IndexOutOfBoundsException
* If the quark is out of range
* @throws StateValueTypeException
* If the state value to be inserted is of a different type of
* what was inserted so far for this attribute.
*/
public void processStateChange(long eventTime, @Nullable Object value, int quark) throws TimeRangeException, StateValueTypeException {
if (!this.fIsActive) {
return;
}
fRWLock.writeLock().lock();
try {
Class<?> expectedSvType = fStateValueTypes.get(quark);
/*
* Make sure the state value type we're inserting is the same as the
* one registered for this attribute.
*/
if (expectedSvType == null) {
/*
* The value hasn't been used yet, set it to the value we're
* currently inserting (which might be null/-1 again).
*/
fStateValueTypes.set(quark, value != null ? value.getClass() : null);
} else if ((value != null) && (value.getClass() != expectedSvType)) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new StateValueTypeException(fBackend.getSSID() + " Quark:" + quark + ", Type:" + value.getClass() + ", Expected:" + expectedSvType);
}
if (Objects.equals(fOngoingStateInfo.get(quark), value) && !fBackend.canInsertBackwards()) {
/*
* This is the case where the new value and the one already
* present in the Builder are the same. We do not need to create
* an interval, we'll just keep the current one going.
*/
return;
}
if (fOngoingStateStartTimes.get(quark) < eventTime) {
/*
* These two conditions are necessary to create an interval and
* update ongoingStateInfo.
*/
fBackend.insertPastState(fOngoingStateStartTimes.get(quark), eventTime - 1, /* End Time */
quark, /* attribute quark */
fOngoingStateInfo.get(quark));
/* StateValue */
fOngoingStateStartTimes.set(quark, eventTime);
fOngoingStateInfo.set(quark, value);
} else if (fOngoingStateStartTimes.get(quark) == eventTime || !fBackend.canInsertBackwards()) {
fOngoingStateInfo.set(quark, value);
} else {
fBackend.insertPastState(fOngoingStateStartTimes.get(quark), eventTime - 1, /* End Time */
quark, /* attribute quark */
value);
/* StateValue */
fOngoingStateStartTimes.set(quark, eventTime);
}
/* Update the Transient State's lastestTime, if needed */
if (fLatestTime < eventTime) {
fLatestTime = eventTime;
}
} finally {
fRWLock.writeLock().unlock();
}
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException in project tracecompass by tracecompass.
the class DataDrivenScenarioHistoryBuilder method updateScenarioState.
private static void updateScenarioState(@Nullable ITmfEvent event, IAnalysisDataContainer container, DataDrivenScenarioInfo info) {
ITmfStateSystemBuilder ss = (ITmfStateSystemBuilder) container.getStateSystem();
long ts = getTimestamp(event, ss);
try {
// save the status
int attributeQuark = ss.getQuarkRelativeAndAdd(info.getQuark(), TmfXmlStrings.STATE);
ss.modifyAttribute(ts, info.getActiveState().getId(), attributeQuark);
} catch (StateValueTypeException e) {
// $NON-NLS-1$
Activator.logError("failed to update scenario state");
}
}
Aggregations