Search in sources :

Example 1 with Builder

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<@NonNull XmlTimeGraphEntryModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    @NonNull List<@NonNull XmlTimeGraphEntryModel> entryList = new ArrayList<>();
    boolean isComplete = true;
    String traceName = String.valueOf(getTrace().getName());
    for (ITmfStateSystem ss : fSs) {
        isComplete &= ss.waitUntilBuilt(0);
        /* Don't query empty state system */
        if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
            long start = ss.getStartTime();
            long end = ss.getCurrentEndTime();
            long id = fBaseQuarkToId.row(ss).computeIfAbsent(ITmfStateSystem.ROOT_ATTRIBUTE, s -> sfAtomicId.getAndIncrement());
            Builder ssEntry = new Builder(id, -1, Collections.singletonList(traceName), start, end, null, ss, ITmfStateSystem.ROOT_ATTRIBUTE, fCompilationData);
            entryList.add(ssEntry.build());
            for (Element entry : fEntries) {
                buildEntry(ss, entry, ssEntry, -1, StringUtils.EMPTY, end, entryList);
            }
        }
    }
    Status status = isComplete ? Status.COMPLETED : Status.RUNNING;
    String msg = isComplete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING;
    return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), entryList), status, msg);
}
Also used : Status(org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status) Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) NonNull(org.eclipse.jdt.annotation.NonNull) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 2 with Builder

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method processEntry.

private Builder processEntry(@NonNull Element entryElement, DataDrivenStateSystemPath displayPath, @NonNull Builder parentEntry, int quark, ITmfStateSystem ss, long currentEnd) {
    /*
         * Get the start time and end time of this entry from the display attribute
         */
    int displayQuark = displayPath.getQuark(quark, parentEntry);
    long id = fBaseQuarkToId.row(ss).computeIfAbsent(quark, s -> sfAtomicId.getAndIncrement());
    if (displayQuark < 0) {
        return new Builder(id, parentEntry.getId(), Collections.singletonList(String.format("Unknown display quark for %s", ss.getAttributeName(quark))), ss.getStartTime(), ss.getCurrentEndTime(), null, ss, quark, // $NON-NLS-1$
        fCompilationData);
    }
    fIDToDisplayQuark.put(id, new Pair<>(ss, displayQuark));
    long entryStart = ss.getStartTime();
    long entryEnd = currentEnd;
    try {
        ITmfStateInterval oneInterval = ss.querySingleState(entryStart, displayQuark);
        /* The entry start is the first non-null interval */
        while (oneInterval.getStateValue().isNull()) {
            long ts = oneInterval.getEndTime() + 1;
            if (ts > currentEnd) {
                break;
            }
            oneInterval = ss.querySingleState(ts, displayQuark);
        }
        entryStart = oneInterval.getStartTime();
        /* The entry end is the last non-null interval */
        oneInterval = ss.querySingleState(entryEnd - 1, displayQuark);
        while (oneInterval.getStateValue().isNull()) {
            long ts = oneInterval.getStartTime() - 1;
            if (ts < ss.getStartTime()) {
                break;
            }
            oneInterval = ss.querySingleState(ts, displayQuark);
        }
        entryEnd = Math.min(oneInterval.getEndTime() + 1, currentEnd);
    } catch (StateSystemDisposedException e) {
    }
    return new Builder(id, parentEntry.getId(), Collections.singletonList(ss.getAttributeName(quark)), entryStart, entryEnd, entryElement, ss, quark, fCompilationData);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 3 with Builder

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder in project tracecompass by tracecompass.

the class XmlTimeGraphDataProvider method buildTree.

/**
 * Build a tree using getParentId() and getId()
 */
private static void buildTree(Map<String, Builder> entryMap, long parentId) {
    for (Builder entry : entryMap.values()) {
        boolean root = true;
        if (!entry.getXmlParentId().isEmpty()) {
            Builder parent = entryMap.get(entry.getXmlParentId());
            /*
                 * Associate the parent entry only if their time overlap. A child entry may
                 * start before its parent, for example at the beginning of the trace if a
                 * parent has not yet appeared in the state system. We just want to make sure
                 * that the entry didn't start after the parent ended or ended before the parent
                 * started.
                 */
            if (parent != null && !(entry.getStartTime() > parent.getEndTime() || entry.getEndTime() < parent.getStartTime())) {
                entry.setParentId(parent.getId());
                root = false;
            }
        }
        if (root) {
            entry.setParentId(parentId);
        }
    }
}
Also used : Builder(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder)

Example 4 with Builder

use of org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder 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

Builder (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.module.XmlTimeGraphEntryModel.Builder)4 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)2 Element (org.w3c.dom.Element)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 TmfXmlStateSystemPathCu (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.compile.TmfXmlStateSystemPathCu)1 DataDrivenStateSystemPath (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.model.DataDrivenStateSystemPath)1 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)1 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)1 Status (org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1