Search in sources :

Example 1 with TmfXmlStateSystemPathCu

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu 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 2 with TmfXmlStateSystemPathCu

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method buildEntry.

private void buildEntry(ITmfStateSystem ssq, Element entryElement, @NonNull Builder parentEntry, int prevBaseQuark, @NonNull String prevRegex, long currentEnd, List<XmlTimeGraphEntryModel> entryList) {
    /* Get the attribute string to display */
    String path = entryElement.getAttribute(TmfXmlStrings.PATH);
    if (path.isEmpty()) {
        path = TmfXmlStrings.WILDCARD;
    }
    /*
         * Make sure the XML element has either a display attribute or entries,
         * otherwise issue a warning
         */
    List<Element> displayElements = TmfXmlUtils.getChildElements(entryElement, TmfXmlStrings.DISPLAY_ELEMENT);
    List<Element> entryElements = TmfXmlUtils.getChildElements(entryElement, TmfXmlStrings.ENTRY_ELEMENT);
    if (displayElements.isEmpty() && entryElements.isEmpty()) {
        // $NON-NLS-1$
        Activator.logWarning(String.format("XML view: entry for %s should have either a display element or entry elements", path));
        return;
    }
    // Get the state system to use to populate those entries, by default, it
    // is the same as the parent
    String analysisId = entryElement.getAttribute(TmfXmlStrings.ANALYSIS_ID);
    ITmfStateSystem parentSs = ssq;
    ITmfStateSystem ss = parentSs;
    int baseQuark = prevBaseQuark;
    if (!analysisId.isEmpty()) {
        ss = TmfStateSystemAnalysisModule.getStateSystem(getTrace(), analysisId);
        baseQuark = ITmfStateSystem.ROOT_ATTRIBUTE;
        if (ss == null) {
            return;
        }
    }
    // Replace any place holders in the path
    Pattern pattern = Pattern.compile(prevRegex);
    String attributePath = prevBaseQuark > 0 ? parentSs.getFullAttributePath(prevBaseQuark) : StringUtils.EMPTY;
    Matcher matcher = pattern.matcher(attributePath);
    if (matcher.find()) {
        path = matcher.replaceFirst(path);
    }
    // $NON-NLS-1$//$NON-NLS-2$
    String regexName = path.replaceAll("\\*", "(.*)");
    /* Get the list of quarks to process with this path */
    String[] paths = regexName.split(SPLIT_STRING);
    int i = 0;
    List<Integer> quarks = Collections.singletonList(baseQuark);
    while (i < paths.length) {
        List<Integer> subQuarks = new LinkedList<>();
        /* Replace * by .* to have a regex string */
        String name = paths[i];
        for (int relativeQuark : quarks) {
            subQuarks.addAll(ss.getSubAttributes(relativeQuark, false, name));
        }
        quarks = subQuarks;
        i++;
    }
    /* Process each quark */
    DataDrivenStateSystemPath displayPath = null;
    Map<String, Builder> entryMap = new HashMap<>();
    if (!displayElements.isEmpty()) {
        Element displayElement = displayElements.get(0);
        TmfXmlStateSystemPathCu displayCu = TmfXmlStateSystemPathCu.compile(parentEntry.getAnalysisCompilationData(), Collections.singletonList(displayElement));
        if (displayCu != null) {
            displayPath = displayCu.generate();
        }
    }
    for (int quark : quarks) {
        Builder currentEntry = parentEntry;
        /* Process the current entry, if specified */
        if (displayPath != null) {
            currentEntry = processEntry(entryElement, displayPath, parentEntry, quark, ss, currentEnd);
            entryMap.put(currentEntry.getXmlId(), currentEntry);
        } else {
            long id = fBaseQuarkToId.row(ss).computeIfAbsent(quark, s -> sfAtomicId.getAndIncrement());
            currentEntry = new Builder(id, parentEntry.getId(), Collections.singletonList(ss.getAttributeName(quark)), ss.getStartTime(), ss.getCurrentEndTime(), null, ss, quark, fCompilationData);
            entryMap.put(currentEntry.getXmlId(), currentEntry);
        }
        /* Process the children entry of this entry */
        for (Element subEntryEl : entryElements) {
            String regex = prevRegex.isEmpty() ? regexName : prevRegex + '/' + regexName;
            buildEntry(ss, subEntryEl, currentEntry, quark, regex, currentEnd, entryList);
        }
    }
    // At this point, the parent has been set, so we can build the entries
    buildTree(entryMap, parentEntry.getId());
    for (Builder b : entryMap.values()) {
        entryList.add(b.build());
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Element(org.w3c.dom.Element) Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder) TmfXmlStateSystemPathCu(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu) LinkedList(java.util.LinkedList) DataDrivenStateSystemPath(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Aggregations

TmfXmlStateSystemPathCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu)2 DataDrivenStateSystemPath (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath)2 Element (org.w3c.dom.Element)2 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Nullable (org.eclipse.jdt.annotation.Nullable)1 AnalysisCompilationData (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.AnalysisCompilationData)1 Builder (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder)1 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)1 ITmfAnalysisModuleWithStateSystems (org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems)1