use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.
the class StateProviderModelTest method testEventName.
/**
* Test an increment of one, for an event name attribute
*/
@Test
public void testEventName() {
ITmfTrace trace = XmlUtilsTest.initializeTrace(testTrace1);
DataDrivenAnalysisModule module = XmlUtilsTest.initializeModule(TmfXmlTestFiles.ATTRIBUTE_FILE);
try {
module.setTrace(trace);
module.schedule();
module.waitForCompletion();
ITmfStateSystem ss = module.getStateSystem();
assertNotNull(ss);
List<Integer> quarks = ss.getQuarks("*");
assertEquals(2, quarks.size());
for (Integer quark : quarks) {
String name = ss.getAttributeName(quark);
switch(name) {
case "test":
{
final int[] expectedStarts = { 1, 5, 7 };
ITmfStateValue[] expectedValues = { TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
XmlUtilsTest.verifyStateIntervals("test", ss, quark, expectedStarts, expectedValues);
}
break;
case "test1":
{
final int[] expectedStarts = { 1, 3, 7, 7 };
ITmfStateValue[] expectedValues = { TmfStateValue.nullValue(), TmfStateValue.newValueInt(1), TmfStateValue.newValueInt(2) };
XmlUtilsTest.verifyStateIntervals("test1", ss, quark, expectedStarts, expectedValues);
}
break;
default:
fail("Wrong attribute name " + name);
break;
}
}
} catch (TmfAnalysisException | AttributeNotFoundException | StateSystemDisposedException e) {
fail(e.getMessage());
} finally {
module.dispose();
trace.dispose();
}
}
use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.
the class ExperimentStateSystemModuleTest method testSsModule.
/**
* Test the state system module execution and result
*/
@Test
public void testSsModule() {
ITmfStateSystem ss = fModule.getStateSystem();
assertNull(ss);
fModule.schedule();
if (fModule.waitForCompletion()) {
ss = fModule.getStateSystem();
assertNotNull(ss);
try {
int quark = ss.getQuarkAbsolute(TestExperimentAnalysis.TRACE_QUARK_NAME);
ITmfStateInterval interval = ss.querySingleState(ss.getCurrentEndTime(), quark);
assertEquals(2, interval.getStateValue().unboxInt());
} catch (AttributeNotFoundException e) {
fail("The quark for number of traces does not exist");
} catch (StateSystemDisposedException e) {
fail("Error: state system disposed");
}
} else {
fail("Module did not complete properly");
}
}
use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.
the class StateSystemDataProvider method getSelectedEntries.
private Map<Long, Pair<ITmfStateSystem, Integer>> getSelectedEntries(Map<String, Object> fetchParameters) {
Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
if (selectedItems == null) {
return Collections.emptyMap();
}
Map<Long, Pair<ITmfStateSystem, Integer>> idToQuark = new HashMap<>();
synchronized (fEntryBuilder) {
for (Long id : selectedItems) {
Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
if (pair != null) {
idToQuark.put(id, pair);
}
}
}
return idToQuark;
}
use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem 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();
}
use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.
the class StateSystemDataProvider method addModule.
private boolean addModule(@Nullable IProgressMonitor monitor, ITmfAnalysisModuleWithStateSystems module, Long parentId, Long startTime) {
synchronized (fStartedAnalysis) {
/*
* Ensure that this is the only job running build entry list.
*/
if (monitor != null && monitor.isCanceled()) {
return false;
}
}
waitForInitialization(getTrace(), module);
// look if the module already exist
String moduleName = Objects.requireNonNull(module.getName());
EntryModelBuilder entry = fEntryBuilder.get(parentId, moduleName);
ModuleEntryModel.Builder moduleEntry;
if (entry instanceof ModuleEntryModel.Builder) {
moduleEntry = (ModuleEntryModel.Builder) entry;
} else {
long newId = ENTRY_ID.getAndIncrement();
moduleEntry = new ModuleEntryModel.Builder(newId, parentId, moduleName, startTime, module);
fEntryBuilder.put(parentId, moduleName, moduleEntry);
}
long moduleId = moduleEntry.getId();
// Add child entry
boolean fetchTreeIsComplete = true;
Long moduleEnd = startTime;
boolean hasChildren = false;
for (ITmfStateSystem ss : module.getStateSystems()) {
if (monitor != null && monitor.isCanceled()) {
return false;
}
// Children entry of the modules are state system
fetchTreeIsComplete &= ss.waitUntilBuilt(0);
if (!ss.isCancelled()) {
addStateSystem(monitor, ss, moduleId);
moduleEnd = Long.max(moduleEnd, ss.getCurrentEndTime());
hasChildren = true;
} else {
/*
* Need to delete all the children of this State System because
* it might be incomplete
*/
EntryModelBuilder ssEntry = fEntryBuilder.get(moduleId, ss.getSSID());
if (ssEntry != null) {
deleteElementFromBuildEntryList(ssEntry.getId());
}
}
}
// Update the entry
moduleEntry.setEndTime(moduleEnd);
fEntryBuilder.put(parentId, moduleName, moduleEntry);
ModuleEntryModel finalModuleEntry = moduleEntry.build();
fModuleEntryModelList.add(finalModuleEntry);
if (fetchTreeIsComplete && hasChildren) {
// Analysis is complete
fModulesToStatus.put(module, true);
}
return fetchTreeIsComplete;
}
Aggregations