use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath in project tracecompass by tracecompass.
the class TmfXmlStateAttributeAndLocationCuTest method testValidStateAttributeCompilation.
/**
* Test the compilation of a valid state attribute strings, except locations
*
* @throws SAXException
* Exception thrown by parser
* @throws IOException
* Exception thrown by parser
* @throws ParserConfigurationException
* Exception thrown by parser
*/
@Test
public void testValidStateAttributeCompilation() throws SAXException, IOException, ParserConfigurationException {
String[] validStrings = { "<stateAttribute type=\"null\" />", "<stateAttribute type=\"constant\" value=\"42\" />", "<stateAttribute type=\"eventField\" value=\"myfield\" />", "<stateAttribute type=\"eventName\" />", "<stateAttribute type=\"eventName\" value=\"ignored\" />", "<stateAttribute type=\"query\" ><stateAttribute type=\"constant\" value=\"queryPath\"/></stateAttribute>", "<stateAttribute type=\"self\" />", "<stateAttribute type=\"pool\" />" };
DataDrivenValue[] generated = { TmfXmlTestUtils.NULL_VALUE, new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "42"), new DataDrivenValueEventField(null, ITmfStateValue.Type.NULL, "myfield"), new DataDrivenValueEventName(null), new DataDrivenValueEventName(null), new DataDrivenValueQuery(null, ITmfStateValue.Type.NULL, new DataDrivenStateSystemPath(ImmutableList.of(new DataDrivenValueConstant(null, ITmfStateValue.Type.NULL, "queryPath")), IBaseQuarkProvider.IDENTITY_BASE_QUARK)), new DataDrivenValueSelf(ITmfStateValue.Type.NULL), DataDrivenValuePool.getInstance() };
for (int i = 0; i < validStrings.length; i++) {
String validString = validStrings[i];
DataDrivenValue runtimeObj = generated[i];
Element xmlElement = TmfXmlTestUtils.getXmlElement(TmfXmlStrings.STATE_ATTRIBUTE, validString);
assertNotNull(xmlElement);
List<@NonNull TmfXmlStateValueCu> compileAttribute = TmfXmlStateValueCu.compileAttribute(ANALYSIS_DATA, xmlElement);
assertNotNull(validString, compileAttribute);
assertEquals("Number of attributes", 1, compileAttribute.size());
TmfXmlStateValueCu value = compileAttribute.get(0);
assertEquals("Expected attribute", runtimeObj, value.generate());
}
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath in project tracecompass by tracecompass.
the class XmlXYDataProvider method fetchXY.
@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
DataDrivenStateSystemPath display = fDisplay;
XmlXYEntry entry = fXmlEntry;
ITmfStateSystem ss = entry.getStateSystem();
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
long[] xValues = filter.getTimesRequested();
Map<Integer, IYModel> map = initSeries(fetchParameters);
if (map.isEmpty()) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
long currentEnd = ss.getCurrentEndTime();
try {
for (int i = 0; i < xValues.length; i++) {
if (monitor != null && monitor.isCanceled()) {
return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
}
long time = xValues[i];
if (time > currentEnd) {
break;
} else if (ss.getStartTime() <= time) {
List<@NonNull ITmfStateInterval> full = ss.queryFullState(time);
for (Entry<Integer, IYModel> series : map.entrySet()) {
int attributeQuark = display.getQuark(series.getKey(), entry);
if (attributeQuark >= 0 && attributeQuark < full.size()) {
Object value = full.get(attributeQuark).getValue();
series.getValue().getData()[i] = extractValue(value);
}
}
}
}
// Update the series value if delta is requested
for (Entry<Integer, IYModel> series : map.entrySet()) {
if (entry.getType().equals(DisplayType.DELTA)) {
getSeriesDelta(series.getValue().getData());
}
}
} catch (StateSystemDisposedException e) {
return TmfXyResponseFactory.createFailedResponse(e.getMessage());
}
boolean complete = ss.waitUntilBuilt(0) || filter.getEnd() <= currentEnd;
return TmfXyResponseFactory.create(TITLE, xValues, map.values(), complete);
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath in project tracecompass by tracecompass.
the class XmlXYDataProvider method create.
/**
* Create an instance of {@link XmlXYDataProvider}. Returns null if statesystem
* is null.
*
* @param trace
* A trace on which we are interested to fetch a model
* @param analysisIds
* A list of analysis ids used for retrieving Analysis objects
* @param entryElement
* An XML entry element
* @return A XmlDataProvider
*/
@Nullable
public static XmlXYDataProvider create(ITmfTrace trace, Set<String> analysisIds, Element entryElement) {
ITmfAnalysisModuleWithStateSystems ss = getStateSystemFromAnalyses(analysisIds, trace);
if (ss == null) {
return null;
}
AnalysisCompilationData compilationData = new AnalysisCompilationData();
/*
* Initialize state attributes. There should be only one entry element for XY
* charts.
*/
String path = entryElement.hasAttribute(TmfXmlStrings.PATH) ? entryElement.getAttribute(TmfXmlStrings.PATH) : TmfXmlStrings.WILDCARD;
XmlXYEntry entry = new XmlXYEntry(ss, path, entryElement, compilationData);
/* Get the display element to use */
List<@NonNull Element> displayElements = TmfXmlUtils.getChildElements(entryElement, TmfXmlStrings.DISPLAY_ELEMENT);
if (displayElements.isEmpty()) {
return null;
}
Element displayElement = displayElements.get(0);
TmfXmlStateSystemPathCu display = TmfXmlStateSystemPathCu.compile(entry.getAnalysisCompilationData(), Collections.singletonList(displayElement));
if (display == null) {
return null;
}
/* Get the series name element to use */
List<Element> seriesNameElements = TmfXmlUtils.getChildElements(entryElement, TmfXmlStrings.NAME_ELEMENT);
DataDrivenStateSystemPath seriesName = null;
if (!seriesNameElements.isEmpty()) {
Element seriesNameElement = seriesNameElements.get(0);
TmfXmlStateSystemPathCu seriesNameCu = TmfXmlStateSystemPathCu.compile(entry.getAnalysisCompilationData(), Collections.singletonList(seriesNameElement));
if (seriesNameCu != null) {
seriesName = seriesNameCu.generate();
}
}
return new XmlXYDataProvider(trace, entry, display.generate(), seriesName);
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath in project tracecompass by tracecompass.
the class TmfXmlOutputEntryCu method generate.
@Override
public DataDrivenOutputEntry generate() {
List<DataDrivenOutputEntry> entries = fChildrenEntries.stream().map(TmfXmlOutputEntryCu::generate).collect(Collectors.toList());
DataDrivenStateSystemPath display = fDisplayCu != null ? fDisplayCu.generate() : null;
DataDrivenStateSystemPath id = fIdCu != null ? fIdCu.generate() : null;
DataDrivenStateSystemPath parent = fParentCu != null ? fParentCu.generate() : null;
DataDrivenStateSystemPath name = fNameCu != null ? fNameCu.generate() : null;
return new DataDrivenOutputEntry(entries, fPath, fAnalysisId, fDisplayText, display, id, parent, name, fDisplayType);
}
use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath in project tracecompass by tracecompass.
the class XmlXYDataProvider method fetchTree.
/**
* @since 2.4
*/
@Override
public TmfModelResponse<TmfTreeModel<ITmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
fLock.readLock().lock();
try {
if (fCached != null) {
return fCached;
}
} finally {
fLock.readLock().unlock();
}
ITmfStateSystem ss = fXmlEntry.getStateSystem();
DataDrivenStateSystemPath seriesNameAttrib = fSeriesNameAttrib;
boolean isComplete = ss.waitUntilBuilt(0);
// Get the quarks before the full states to ensure that the attributes will be present in the full state
List<Integer> quarks = fXmlEntry.getQuarks();
fLock.writeLock().lock();
try {
List<ITmfStateInterval> fullState = ss.queryFullState(ss.getCurrentEndTime());
ImmutableList.Builder<ITmfTreeDataModel> builder = ImmutableList.builder();
builder.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(getTrace().getName())));
for (int quark : quarks) {
String seriesName = ss.getAttributeName(quark);
if (seriesNameAttrib != null) {
// Use the value of the series name attribute
int seriesNameQuark = seriesNameAttrib.getQuark(quark, fXmlEntry);
Object value = fullState.get(seriesNameQuark).getValue();
if (value != null) {
seriesName = String.valueOf(value);
}
}
if (!seriesName.isEmpty()) {
String tempSeriesName = seriesName;
String uniqueName = fQuarkToString.computeIfAbsent(quark, q -> getUniqueNameFor(tempSeriesName));
// Check if an ID has already been created for this quark.
Long id = fIdToQuark.inverse().computeIfAbsent(quark, q -> ENTRY_IDS.getAndIncrement());
builder.add(new TmfTreeDataModel(id, fTraceId, Collections.singletonList(uniqueName)));
}
}
ImmutableList<ITmfTreeDataModel> list = builder.build();
if (isComplete) {
TmfModelResponse<TmfTreeModel<ITmfTreeDataModel>> tmfModelResponse = new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
fCached = tmfModelResponse;
return tmfModelResponse;
}
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
} catch (StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
} finally {
fLock.writeLock().unlock();
}
}
Aggregations