Search in sources :

Example 1 with DataDrivenStateSystemPath

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());
    }
}
Also used : DataDrivenValueQuery(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueQuery) TmfXmlStateValueCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu) DataDrivenValueSelf(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueSelf) DataDrivenValue(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValue) Element(org.w3c.dom.Element) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) DataDrivenValueEventField(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventField) DataDrivenValueConstant(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueConstant) DataDrivenValueEventName(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.values.DataDrivenValueEventName) Test(org.junit.Test)

Example 2 with DataDrivenStateSystemPath

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);
}
Also used : IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 3 with DataDrivenStateSystemPath

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);
}
Also used : Element(org.w3c.dom.Element) TmfXmlStateSystemPathCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu) AnalysisCompilationData(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData) ITmfAnalysisModuleWithStateSystems(org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 4 with DataDrivenStateSystemPath

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);
}
Also used : DataDrivenOutputEntry(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.output.DataDrivenOutputEntry) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath)

Example 5 with DataDrivenStateSystemPath

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();
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) AtomicLong(java.util.concurrent.atomic.AtomicLong) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

DataDrivenStateSystemPath (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath)7 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)4 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)3 Element (org.w3c.dom.Element)3 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 TmfXmlStateSystemPathCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu)2 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 WeakHashMap (java.util.WeakHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 AnalysisCompilationData (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData)1 TmfXmlStateValueCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateValueCu)1