use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class StateSystem method query2D.
private Iterable<@NonNull ITmfStateInterval> query2D(@NonNull Collection<@NonNull Integer> quarks, TimeRangeCondition timeCondition, boolean reverse) throws TimeRangeException, IndexOutOfBoundsException {
if (timeCondition.min() < getStartTime()) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new TimeRangeException("Time conditions " + timeCondition.min() + " is lower than state system start time: " + getStartTime());
}
if (quarks.isEmpty()) {
return Collections.emptyList();
}
IntegerRangeCondition quarkCondition = IntegerRangeCondition.forDiscreteRange(quarks);
if (quarkCondition.min() < 0 || quarkCondition.max() >= getNbAttributes()) {
throw new IndexOutOfBoundsException();
}
Iterable<@NonNull ITmfStateInterval> transStateIterable = transState.query2D(quarks, timeCondition);
Iterable<@NonNull ITmfStateInterval> backendIterable = backend.query2D(quarkCondition, timeCondition, reverse);
return Iterables.concat(transStateIterable, backendIterable);
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class TransientState method query2D.
/**
* Generalized 2D iterable query method. Iterates over intervals that match
* the conditions on quarks and times in the Transient State.
*
* @param quarks
* Collection of quarks for returned intervals.
* @param timeCondition
* Condition on the times for returned intervals
* @return An iterable over the queried intervals, ordered by quarks.
* @since 2.1
*/
public Iterable<ITmfStateInterval> query2D(Collection<Integer> quarks, TimeRangeCondition timeCondition) {
fRWLock.readLock().lock();
try (TraceCompassLogUtils.ScopeLog log = new // $NON-NLS-1$
TraceCompassLogUtils.ScopeLog(// $NON-NLS-1$
LOGGER, // $NON-NLS-1$
Level.FINEST, // $NON-NLS-1$
"TransientState:query2D", // $NON-NLS-1$
"ssid", // $NON-NLS-1$
fBackend.getSSID(), // $NON-NLS-1$
"quarks", // $NON-NLS-1$
quarks, "time", timeCondition)) {
// $NON-NLS-1$
if (!fIsActive) {
return Collections.emptyList();
}
long end = timeCondition.max();
Collection<ITmfStateInterval> iterable = new ArrayList<>();
for (Integer quark : quarks) {
ITmfStateInterval interval = getIntervalAt(end, quark);
if (interval != null) {
iterable.add(interval);
}
}
return iterable;
} finally {
fRWLock.readLock().unlock();
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class TmfStateSystemAnalysisModule method loadInitialState.
/**
* Batch-load the initial state, if there is any.
*/
private void loadInitialState(ITmfStateProvider provider) {
final ITmfTrace trace = provider.getTrace();
File path = new File(trace.getPath());
path = path.isDirectory() ? path : path.getParentFile();
if (path == null) {
return;
}
for (ITmfStateSystem ss : getStateSystems()) {
if (ss instanceof ITmfStateSystemBuilder) {
StateSnapshot snapshot = StateSnapshot.read(path.toPath(), ss.getSSID());
if (snapshot == null || provider.getVersion() != snapshot.getVersion()) {
continue;
}
List<List<String>> paths = new ArrayList<>();
/* create quark list */
for (Entry<List<String>, ITmfStateInterval> attributeSnapshot : snapshot.getStates().entrySet()) {
List<String> attributePath = Objects.requireNonNull(attributeSnapshot.getKey());
ITmfStateInterval state = Objects.requireNonNull(attributeSnapshot.getValue());
while (paths.size() <= state.getAttribute()) {
// $NON-NLS-1$
paths.add(Collections.singletonList("Dummy" + paths.size()));
}
paths.set(state.getAttribute(), attributePath);
}
/*
* Populate quarks in order
*/
int i = 0;
for (List<String> attributePath : paths) {
int quark = ((ITmfStateSystemBuilder) ss).getQuarkAbsoluteAndAdd(attributePath.toArray(new String[attributePath.size()]));
if (i != quark) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Activator.logWarning("Quark for analysis " + getClass().getCanonicalName() + " not the same ( " + quark + " != " + i + ")");
}
i++;
}
/* Load the statedump into the statesystem */
for (ITmfStateInterval interval : snapshot.getStates().values()) {
Object initialState = interval.getValue();
int attribute = interval.getAttribute();
provider.addFutureEvent(interval.getStartTime(), initialState, attribute, FutureEventType.MODIFICATION);
if (interval.getEndTime() != Long.MIN_VALUE) {
provider.addFutureEvent(interval.getEndTime() + 1, (Object) null, attribute, FutureEventType.MODIFICATION);
}
}
}
}
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class FsmTest method testTwoInitialStates.
/**
* Execute one pattern, with the two types of initial state initialization,
* then test that the new behavior is prioritized and that preconditions are
* ignored with initialState element
*
* @throws AttributeNotFoundException
* Exceptions thrown querying the state system
* @throws StateSystemDisposedException
* Exceptions thrown querying the state system
*/
@Test
public void testTwoInitialStates() throws AttributeNotFoundException, StateSystemDisposedException {
// Test segment store
ISegmentStore<@NonNull ISegment> ss = fModule2.getSegmentStore();
assertNotNull("segment store exist", ss);
assertTrue("Segment store not empty", ss.size() == 1);
Object item = ss.iterator().next();
assertTrue(item instanceof TmfXmlPatternSegment);
assertTrue(((TmfXmlPatternSegment) item).getName().equals(TEST_SEGMENT_NEW));
// Test state system
ITmfStateSystem stateSystem = fModule2.getStateSystem(fModule2.getId());
assertNotNull("state system exist", stateSystem);
int quark = stateSystem.getQuarkAbsolute("count_new");
ITmfStateInterval interval = stateSystem.querySingleState(END_TIME, quark);
int count = interval.getStateValue().unboxInt();
assertTrue("Test the count value", count > 0);
quark = stateSystem.optQuarkAbsolute("precond");
assertEquals(ITmfStateSystem.INVALID_ATTRIBUTE, quark);
}
use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.
the class FsmTest method testInitialStateDeclaration.
/**
* Compare the execution of two state machines that do the same job, one
* using the initial element, the second one using the initialState element.
* The result should be the same for both state machines
*/
@Test
public void testInitialStateDeclaration() {
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("fsm2");
interval = stateSystem.querySingleState(END_TIME, quark);
long count2 = interval.getStateValue().unboxLong();
assertEquals("Test the count value", count1, count2);
} catch (AttributeNotFoundException | StateSystemDisposedException e) {
fail("Failed to query the state system");
}
}
Aggregations