use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class InMemoryBackendTest method testQueryAttribute.
/**
* Test single attribute then compare it to a full query
*/
@Test
public void testQueryAttribute() {
try {
IStateHistoryBackend backend = fixture;
assertNotNull(backend);
ITmfStateInterval[] interval = new TmfStateInterval[10];
for (int i = 0; i < 10; i++) {
interval[i] = backend.doSingularQuery(950, i);
}
testInterval(interval[0], 900, 990, 9);
testInterval(interval[1], 901, 991, 9);
testInterval(interval[2], 902, 992, 9);
testInterval(interval[3], 903, 993, 9);
testInterval(interval[4], 904, 994, 9);
testInterval(interval[5], 905, 995, 9);
testInterval(interval[6], 906, 996, 9);
testInterval(interval[7], 907, 997, 9);
testInterval(interval[8], 908, 998, 9);
testInterval(interval[9], 909, 999, 9);
List<@Nullable ITmfStateInterval> intervalQuery = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
intervalQuery.add(null);
}
backend.doQuery(intervalQuery, 950);
ITmfStateInterval[] ref = intervalQuery.toArray(new ITmfStateInterval[0]);
assertArrayEquals(ref, interval);
} catch (TimeRangeException | StateSystemDisposedException e) {
fail(e.getMessage());
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateHistoryBackendTestBase method testFullIntervals.
/**
* Test the full query method by filling a small backend with intervals that
* take the full time range, like this:
*
* <pre>
* |x-------------x|
* |x-------------x|
* |x-------------x|
* |x-------------x|
* | ... |
* </pre>
*
* and then querying at every single timestamp, making sure all, and only,
* the expected intervals are returned.
*/
@Test
public void testFullIntervals() {
final int nbAttr = 1000;
final long startTime = 0;
final long endTime = 1000;
List<ITmfStateInterval> intervals = new ArrayList<>();
for (int attr = 0; attr < nbAttr; attr++) {
intervals.add(new TmfStateInterval(startTime, endTime, attr, attr));
}
buildAndQueryFullRange(startTime, endTime, nbAttr, intervals, false);
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateHistoryBackendTestBase method testNegativeTimes.
/**
* Test that negative times are also properly handled.
*
* @throws IOException
* if an IO exception occurred creating the backend.
* @throws StateSystemDisposedException
* if the state system was disposed
* @throws TimeRangeException
* if the time was incorrect.
*/
@Test
public void testNegativeTimes() throws IOException, TimeRangeException, StateSystemDisposedException {
long startTime = -1001;
IStateHistoryBackend backend = getBackendForBuilding(startTime);
for (long t = startTime; t <= 200; t += 10) {
backend.insertPastState(t, t + 10, 0, t);
}
backend.finishedBuilding(210);
IStateHistoryBackend backendQuery = getBackendForQuerying(backend);
ITmfStateInterval poisonInterval = backendQuery.doSingularQuery(-1, 0);
assertNotNull(poisonInterval);
assertEquals(-11L, poisonInterval.getValue());
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystem method queryFullState.
// --------------------------------------------------------------------------
// Regular query methods (sent to the back-end)
// --------------------------------------------------------------------------
@Override
public List<ITmfStateInterval> queryFullState(long t) throws TimeRangeException, StateSystemDisposedException {
if (isDisposed) {
throw new StateSystemDisposedException();
}
try (ScopeLog log = new // $NON-NLS-1$
ScopeLog(// $NON-NLS-1$
LOGGER, // $NON-NLS-1$
Level.FINER, // $NON-NLS-1$
"StateSystem:FullQuery", "ssid", getSSID(), "ts", t)) {
// $NON-NLS-1$ //$NON-NLS-2$
final int nbAttr = getNbAttributes();
List<@Nullable ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
/*
* Bring the size of the array to the current number of attributes
*/
for (int i = 0; i < nbAttr; i++) {
stateInfo.add(null);
}
/*
* If we are currently building the history, also query the
* "ongoing" states for stuff that might not yet be written to the
* history.
*/
if (transState.isActive()) {
transState.doQuery(stateInfo, t);
}
/* Query the storage backend */
backend.doQuery(stateInfo, t);
/*
* We should have previously inserted an interval for every
* attribute.
*/
for (ITmfStateInterval interval : stateInfo) {
if (interval == null) {
// $NON-NLS-1$
throw new IllegalStateException("Incoherent interval storage");
}
}
return stateInfo;
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class TransientState method replaceOngoingState.
/**
* More advanced version of {@link #changeOngoingStateValue}. Replaces the
* complete ongoingStateInfo in one go, and updates the
* ongoingStateStartTimes and #stateValuesTypes accordingly. BE VERY CAREFUL
* WITH THIS!
*
* @param newStateIntervals
* The List of intervals that will represent the new
* "ongoing state". Their end times don't matter, we will only
* check their value and start times.
*/
public void replaceOngoingState(List<ITmfStateInterval> newStateIntervals) {
final int size = newStateIntervals.size();
fRWLock.writeLock().lock();
try {
fOngoingStateInfo = new ArrayList<>(size);
fOngoingStateStartTimes = new ArrayList<>(size);
fStateValueTypes = new ArrayList<>(size);
for (ITmfStateInterval interval : newStateIntervals) {
Object value = interval.getValue();
fOngoingStateInfo.add(value);
fOngoingStateStartTimes.add(interval.getStartTime());
Class<?> objectClass = value != null ? value.getClass() : null;
fStateValueTypes.add(objectClass);
}
} finally {
fRWLock.writeLock().unlock();
}
}
Aggregations