use of org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval in project tracecompass by tracecompass.
the class StateHistoryBackendTestBase method testCascadingIntervals.
/**
* Test the full query method by filling a small backend with intervals
* placed in a "stair-like" fashion, like this:
*
* <pre>
* |x----x----x---x|
* |xx----x----x--x|
* |x-x----x----x-x|
* |x--x----x----xx|
* | ... |
* </pre>
*
* and then querying at every single timestamp, making sure all, and only,
* the expected intervals are returned.
*/
@Test
public void testCascadingIntervals() {
final int nbAttr = 10;
final long duration = 10;
final long startTime = 0;
final long endTime = 1000;
List<ITmfStateInterval> intervals = new ArrayList<>();
for (long t = startTime + 1; t <= endTime + duration; t++) {
intervals.add(new TmfStateInterval(Math.max(startTime, t - duration), Math.min(endTime, t - 1), (int) t % nbAttr, t));
}
buildAndQueryFullRange(startTime, endTime, nbAttr, intervals, false);
}
use of org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval in project tracecompass by tracecompass.
the class StateHistoryBackendTestBase method testBuildNowQueryLaterStateValues.
/**
* Test querying various state value types after the state system has been
* built and finished
*/
@Test
public void testBuildNowQueryLaterStateValues() {
/* Test specific data initialization */
long startTime = 10;
long timeStep = 5;
int intQuark = 0;
int longQuark = 1;
int doubleQuark = 2;
int strQuark = 3;
int customQuark = 4;
int nbAttribs = 5;
/* Register custom factory and create custom state values */
CustomStateValueStub.registerFactory();
ITmfStateValue customVal = new CustomStateValueStub(10, "a string");
ITmfStateValue customVal2 = new CustomStateValueStub(Short.MAX_VALUE, "another string");
try {
IStateHistoryBackend backend = getBackendForBuilding(startTime);
assertNotNull(backend);
long firstEnd = startTime + timeStep;
long nextStart = firstEnd + 1;
long endTime = nextStart + timeStep;
insertIntervals(backend, ImmutableList.of(new TmfStateInterval(startTime, startTime + timeStep, intQuark, INT_VAL1), new TmfStateInterval(startTime, startTime + timeStep, longQuark, LONG_VAL1), new TmfStateInterval(startTime, startTime + timeStep, doubleQuark, DOUBLE_VAL1), new TmfStateInterval(startTime, startTime + timeStep, strQuark, STR_VAL1), new TmfStateInterval(startTime, startTime + timeStep, customQuark, customVal), new TmfStateInterval(nextStart, endTime, intQuark, INT_VAL2), new TmfStateInterval(nextStart, endTime, longQuark, LONG_VAL2), new TmfStateInterval(nextStart, endTime, doubleQuark, DOUBLE_VAL2), new TmfStateInterval(nextStart, endTime, strQuark, STR_VAL2), new TmfStateInterval(nextStart, endTime, customQuark, customVal2)));
backend.finishedBuilding(endTime);
/* Make sure the end time corresponds to the backend end time */
assertEquals(endTime, backend.getEndTime());
IStateHistoryBackend backendQuery = getBackendForQuerying(backend);
/* Verify start and end times */
assertEquals("Backend start time", startTime, backendQuery.getStartTime());
assertEquals("Backend end time", endTime, backendQuery.getEndTime());
List<@Nullable ITmfStateInterval> intervals = prepareIntervalList(nbAttribs);
/* Do a full query at start and verify the values */
backendQuery.doQuery(intervals, startTime);
ITmfStateInterval interval = intervals.get(intQuark);
assertNotNull(interval);
assertEquals("Int value after read", INT_VAL1, interval.getValue());
interval = intervals.get(longQuark);
assertNotNull(interval);
assertEquals("Long value after read", LONG_VAL1, interval.getValue());
interval = intervals.get(doubleQuark);
assertNotNull(interval);
assertEquals("Double value after read", DOUBLE_VAL1, interval.getValue());
interval = intervals.get(strQuark);
assertNotNull(interval);
assertEquals("String value after read", STR_VAL1, interval.getValue());
/* Custom */
interval = intervals.get(customQuark);
assertNotNull(interval);
assertEquals("String value after read", customVal, interval.getStateValue());
/* Do a full query at the end and verify the values */
backendQuery.doQuery(intervals, endTime);
interval = intervals.get(intQuark);
assertNotNull(interval);
assertEquals("Int value after read", INT_VAL2, interval.getValue());
interval = intervals.get(longQuark);
assertNotNull(interval);
assertEquals("Long value after read", LONG_VAL2, interval.getValue());
interval = intervals.get(doubleQuark);
assertNotNull(interval);
assertEquals("Double value after read", DOUBLE_VAL2, interval.getValue());
interval = intervals.get(strQuark);
assertNotNull(interval);
assertEquals("String value after read", STR_VAL2, interval.getValue());
/* Custom */
interval = intervals.get(customQuark);
assertNotNull(interval);
assertEquals("String value after read", customVal2, interval.getStateValue());
} catch (TimeRangeException | IOException | StateSystemDisposedException e) {
fail(e.getMessage());
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval in project tracecompass by tracecompass.
the class TmfMipmapFeature method updateMipmap.
@Override
public void updateMipmap(ITmfStateValue value, long ts) {
/* if the value did not change, ignore it */
if (currentValue.equals(value)) {
return;
}
/* if the ongoing state value is not null, create and store a state interval */
if (!currentValue.isNull()) {
ITmfStateInterval interval = new TmfStateInterval(currentStartTime, ts, getLevelQuark(0), currentValue.unboxValue());
intervals.get(0).add(interval);
}
/* if the new value is not null, update the mipmap levels that are full */
if (!value.isNull()) {
int level = 0;
while (intervals.get(level).size() == getMipmapResolution()) {
updateMipmapLevel(++level, ts);
}
}
/* store the new value as the ongoing state value */
currentValue = value;
currentStartTime = ts;
}
use of org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval in project tracecompass by tracecompass.
the class TmfMipmapFeature method updateMipmapLevel.
/**
* Compute and update the mipmap level attribute from the lower-level
* state interval list
*
* @param level
* The mipmap level to update
* @param endTime
* The end timestamp to use for the mipmap interval
*/
protected void updateMipmapLevel(int level, long endTime) {
try {
/* get the lower-level interval list */
List<ITmfStateInterval> lowerIntervals = intervals.get(level - 1);
if (lowerIntervals.isEmpty()) {
return;
}
/* get the start time from the first interval in the lower-level list */
long startTime = lowerIntervals.get(0).getStartTime();
/* compute the mipmap value */
ITmfStateValue value = computeMipmapValue(lowerIntervals, startTime, endTime);
/* clear the lower-level list */
lowerIntervals.clear();
/* get or create the current-level quark */
int levelQuark = ss.getQuarkRelativeAndAdd(mipmapQuark, String.valueOf(level));
if (!checkLevelExists(level)) {
addLevelQuark(levelQuark);
ss.updateOngoingState(TmfStateValue.newValueInt(level), mipmapQuark);
intervals.add(new ArrayList<ITmfStateInterval>(getMipmapResolution()));
}
/* add new interval to current-level list */
ITmfStateInterval interval = new TmfStateInterval(startTime, endTime, levelQuark, value.unboxValue());
intervals.get(level).add(interval);
/* update the current-level attribute */
ss.modifyAttribute(startTime, value.unboxValue(), levelQuark);
} catch (StateValueTypeException e) {
// $NON-NLS-1$
Activator.logError("TmfMipmapFeature : Bad state value type", e);
} catch (TimeRangeException e) {
// $NON-NLS-1$
Activator.logError("TmfMipmapFeature : Time stamp is out of range", e);
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval in project tracecompass by tracecompass.
the class PartialHistoryBackend method doQuery.
@Override
public void doQuery(List<@Nullable ITmfStateInterval> currentStateInfo, long t) throws TimeRangeException, StateSystemDisposedException {
/* Wait for required steps to be done */
waitForCheckpoints();
fPartialSS.getUpstreamSS().waitUntilBuilt();
if (!checkValidTime(t)) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new TimeRangeException(fSSID + " Time:" + t + ", Start:" + getStartTime() + ", End:" + getEndTime());
}
/* Reload the previous checkpoint */
long checkpointTime = fCheckpoints.floorKey(t);
fInnerHistory.doQuery(currentStateInfo, checkpointTime);
/*
* Set the initial contents of the partial state system (which is the
* contents of the query at the checkpoint).
*/
List<@NonNull ITmfStateInterval> filledStateInfo = checkNotNullContents(currentStateInfo.stream()).collect(Collectors.toList());
fPartialSS.takeQueryLock();
fPartialSS.replaceOngoingState(filledStateInfo);
/* Send an event request to update the state system to the target time. */
TmfTimeRange range = new TmfTimeRange(/*
* The state at the checkpoint already includes any state change
* caused by the event(s) happening exactly at 'checkpointTime',
* if any. We must not include those events in the query.
*/
TmfTimestamp.fromNanos(checkpointTime + 1), TmfTimestamp.fromNanos(t));
ITmfEventRequest request = new PartialStateSystemRequest(fPartialInput, range);
fPartialInput.getTrace().sendRequest(request);
try {
request.waitForCompletion();
} catch (InterruptedException e) {
// Do nothing
}
/*
* Now the partial state system should have the ongoing time we are
* looking for. However, the method expects a List of *state intervals*,
* not state values, so we'll create intervals with a dummy end time.
*/
for (int i = 0; i < currentStateInfo.size(); i++) {
long start = 0;
start = ((ITmfStateSystem) fPartialSS).getOngoingStartTime(i);
@Nullable Object val = ((ITmfStateSystem) fPartialSS).queryOngoing(i);
ITmfStateInterval interval = new TmfStateInterval(start, t, i, val);
currentStateInfo.set(i, interval);
}
fPartialSS.releaseQueryLock();
}
Aggregations