use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class ThreadedHistoryTreeBackend method doQuery.
// ------------------------------------------------------------------------
// Query methods
// ------------------------------------------------------------------------
@Override
public void doQuery(List<ITmfStateInterval> currentStateInfo, long t) throws TimeRangeException, StateSystemDisposedException {
super.doQuery(currentStateInfo, t);
if (isFinishedBuilding()) {
/*
* The history tree is the only place to look for intervals once
* construction is finished.
*/
return;
}
/*
* It is possible we may have missed some intervals due to them being in
* the queue while the query was ongoing. Go over the results to see if
* we missed any.
*/
for (int i = 0; i < currentStateInfo.size(); i++) {
if (currentStateInfo.get(i) == null) {
/* Query the missing interval via "unicast" */
ITmfStateInterval interval = doSingularQuery(t, i);
currentStateInfo.set(i, interval);
}
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class TmfIntervalDeserializer method deserialize.
@Override
public ITmfStateInterval deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
JsonObject object = json.getAsJsonObject();
long start = object.get(TmfIntervalStrings.START).getAsLong();
long end = object.get(TmfIntervalStrings.END).getAsLong();
int quark = object.get(TmfIntervalStrings.QUARK).getAsInt();
String type = object.get(TmfIntervalStrings.TYPE).getAsString();
if (type.equals(TmfIntervalStrings.NULL)) {
return new TmfStateInterval(start, end, quark, (Object) null);
}
JsonElement value = object.get(TmfIntervalStrings.VALUE);
try {
Class<?> typeClass = Class.forName(type);
if (typeClass.isAssignableFrom(CustomStateValue.class)) {
String encoded = value.getAsString();
byte[] serialized = Base64.getDecoder().decode(encoded);
ByteBuffer buffer = ByteBuffer.wrap(serialized);
ISafeByteBufferReader sbbr = SafeByteBufferFactory.wrapReader(buffer, serialized.length);
TmfStateValue sv = CustomStateValue.readSerializedValue(sbbr);
return new TmfStateInterval(start, end, quark, sv.unboxValue());
}
if (typeClass.isAssignableFrom(Integer.class)) {
return new TmfStateInterval(start, end, quark, value.getAsInt());
} else if (typeClass.isAssignableFrom(Long.class)) {
return new TmfStateInterval(start, end, quark, value.getAsLong());
} else if (typeClass.isAssignableFrom(Double.class)) {
return new TmfStateInterval(start, end, quark, value.getAsDouble());
} else if (typeClass.isAssignableFrom(String.class)) {
return new TmfStateInterval(start, end, quark, value.getAsString());
}
} catch (ClassNotFoundException e) {
// Fall through
}
// last ditch attempt
return new TmfStateInterval(start, end, quark, value.toString());
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtils method queryHistoryRange.
/**
* Return the state history of a given attribute, but with at most one
* update per "resolution". This can be useful for populating views (where
* it's useless to have more than one query per pixel, for example). A
* progress monitor can be used to cancel the query before completion.
*
* @param ss
* The state system to query
* @param attributeQuark
* Which attribute this query is interested in
* @param t1
* Start time of the range query
* @param t2
* Target end time of the query. If t2 is greater than the end of
* the trace, we will return what we have up to the end of the
* history.
* @param resolution
* The "step" of this query
* @param monitor
* A progress monitor. If the monitor is canceled during a query,
* we will return what has been found up to that point. You can
* use "null" if you do not want to use one.
* @return The List of states that happened between t1 and t2
* @throws TimeRangeException
* If t1 is invalid, if t2 {@literal <=} t1, or if the
* resolution isn't greater than zero.
* @throws AttributeNotFoundException
* If the attribute doesn't exist
* @throws StateSystemDisposedException
* If the query is sent after the state system has been disposed
*/
public static List<ITmfStateInterval> queryHistoryRange(ITmfStateSystem ss, int attributeQuark, long t1, long t2, long resolution, @Nullable IProgressMonitor monitor) throws AttributeNotFoundException, StateSystemDisposedException {
List<ITmfStateInterval> intervals = new LinkedList<>();
ITmfStateInterval currentInterval = null;
long ts, tEnd;
/* Make sure the time range makes sense */
if (t2 < t1 || resolution <= 0) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
throw new TimeRangeException(ss.getSSID() + " Start:" + t1 + ", End:" + t2 + ", Resolution:" + resolution);
}
/* Set the actual, valid end time of the range query */
if (t2 > ss.getCurrentEndTime()) {
tEnd = ss.getCurrentEndTime();
} else {
tEnd = t2;
}
IProgressMonitor mon = monitor;
if (mon == null) {
mon = new NullProgressMonitor();
}
/*
* Iterate over the "resolution points". We skip unneeded queries in the
* case the current interval is longer than the resolution.
*/
for (ts = t1; ts <= tEnd; ts += ((currentInterval.getEndTime() - ts) / resolution + 1) * resolution) {
if (mon.isCanceled()) {
return intervals;
}
currentInterval = ss.querySingleState(ts, attributeQuark);
intervals.add(currentInterval);
}
/* Add the interval at t2, if it wasn't included already. */
if (currentInterval != null && currentInterval.getEndTime() < tEnd) {
currentInterval = ss.querySingleState(tEnd, attributeQuark);
intervals.add(currentInterval);
}
return intervals;
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystemUtils method queryHistoryRange.
/**
* Return a list of state intervals, containing the "history" of a given
* attribute between timestamps t1 and t2. The list will be ordered by
* ascending time.
* <p>
* Note that contrary to queryFullState(), the returned list here is in the
* "direction" of time (and not in the direction of attributes, as is the
* case with queryFullState()).
* </p>
*
* @param ss
* The state system to query
* @param attributeQuark
* Which attribute this query is interested in
* @param t1
* Start time of the range query
* @param t2
* Target end time of the query. If t2 is greater than the end of
* the trace, we will return what we have up to the end of the
* history.
* @return The List of state intervals that happened between t1 and t2
* @throws TimeRangeException
* If t1 is invalid, or if t2 {@literal <=} t1
* @throws AttributeNotFoundException
* If the requested quark does not exist in the model.
* @throws StateSystemDisposedException
* If the query is sent after the state system has been disposed
*/
public static List<ITmfStateInterval> queryHistoryRange(ITmfStateSystem ss, int attributeQuark, long t1, long t2) throws AttributeNotFoundException, StateSystemDisposedException {
List<ITmfStateInterval> intervals;
ITmfStateInterval currentInterval;
long ts, tEnd;
/* Make sure the time range makes sense */
if (t2 < t1) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TimeRangeException(ss.getSSID() + " Start:" + t1 + ", End:" + t2);
}
/* Set the actual, valid end time of the range query */
if (t2 > ss.getCurrentEndTime()) {
tEnd = ss.getCurrentEndTime();
} else {
tEnd = t2;
}
/* Get the initial state at time T1 */
intervals = new ArrayList<>();
currentInterval = ss.querySingleState(t1, attributeQuark);
intervals.add(currentInterval);
/* Get the following state changes */
ts = currentInterval.getEndTime();
while (ts != -1 && ts < tEnd) {
ts++;
/* To "jump over" to the next state in the history */
currentInterval = ss.querySingleState(ts, attributeQuark);
intervals.add(currentInterval);
ts = currentInterval.getEndTime();
}
return intervals;
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class FsmTest method testInitialStateWithCondition.
/**
* Compare the execution of two state machines doing the same job, the tid
* condition is ignored with the initial element and used with the
* initialState element. The result should be different.
*/
@Test
public void testInitialStateWithCondition() {
ITmfStateSystem stateSystem = fModule.getStateSystem(fModule.getId());
assertNotNull("state system exist", stateSystem);
try {
int quark = stateSystem.getQuarkAbsolute("fsm1");
@NonNull ITmfStateInterval interval = stateSystem.querySingleState(END_TIME, quark);
long count1 = interval.getStateValue().unboxLong();
quark = stateSystem.getQuarkAbsolute("fsm3");
interval = stateSystem.querySingleState(END_TIME, quark);
long count3 = interval.getStateValue().unboxLong();
assertTrue("Test the count value", count1 > count3);
} catch (AttributeNotFoundException | StateSystemDisposedException e) {
fail("Failed to query the state system");
}
}
Aggregations