import java.util.List;
import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.model.TmfXmlLocation;
*
* @author Florian Wininger
*/
-public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer {
+public class XmlEntry extends TimeGraphEntry implements IXmlStateSystemContainer, Comparable<XmlEntry> {
private static final String EMPTY_STRING = ""; //$NON-NLS-1$
DISPLAY
}
- private final ITmfTrace fTrace;
+ private final @NonNull ITmfTrace fTrace;
private final EntryDisplayType fType;
private final int fBaseQuark;
private final int fDisplayQuark;
private final String fParentId;
private final String fId;
private final @NonNull ITmfStateSystem fSs;
- private final Element fElement;
+ private final @Nullable Element fElement;
/**
* Constructor
* used to determine, if available, the parent, ID, name and
* other display option of this entry
*/
- public XmlEntry(int baseQuark, int displayQuark, ITmfTrace trace, String name, long startTime, long endTime, EntryDisplayType type, @NonNull ITmfStateSystem ss, Element entryElement) {
+ public XmlEntry(int baseQuark, int displayQuark, @NonNull ITmfTrace trace, String name, long startTime, long endTime, EntryDisplayType type, @NonNull ITmfStateSystem ss, Element entryElement) {
super(name, startTime, endTime);
fTrace = trace;
fType = type;
* @param ss
* The state system this entry belongs to
*/
- public XmlEntry(int baseQuark, ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) {
+ public XmlEntry(int baseQuark, @NonNull ITmfTrace trace, String name, @NonNull ITmfStateSystem ss) {
super(name, ss.getStartTime(), ss.getCurrentEndTime());
fTrace = trace;
fType = EntryDisplayType.NULL;
*
* @return the entry's trace
*/
- public ITmfTrace getTrace() {
+ public @NonNull ITmfTrace getTrace() {
return fTrace;
}
return true;
}
- /**
- * Add a child to this entry of type XmlEntry
- *
- * @param entry
- * The entry to add
- */
- public void addChild(@NonNull XmlEntry entry) {
- int index;
- for (index = 0; index < getChildren().size(); index++) {
- XmlEntry other = (XmlEntry) getChildren().get(index);
- if (entry.getType().compareTo(other.getType()) < 0) {
- break;
- } else if (entry.getType().equals(other.getType())) {
- if (entry.getName().compareTo(other.getName()) < 0) {
- break;
- }
- }
- }
-
- addChild(index, entry);
- }
-
/**
* Return the state system this entry is associated to
*
}
return pattern.matcher(fParentId).find();
}
+
+ @Override
+ public int compareTo(XmlEntry other) {
+ // First compare by type
+ int cmp = getType().compareTo(other.getType());
+ if (cmp != 0) {
+ return cmp;
+ }
+ // For equal type, then compare by element's attribute (to not mix
+ // different element's entries)
+ Element element = fElement;
+ String attrib = (element == null) ? StringUtils.EMPTY : element.getAttribute(TmfXmlUiStrings.PATH);
+ element = other.fElement;
+ String otherAttrib = (element == null) ? StringUtils.EMPTY : element.getAttribute(TmfXmlUiStrings.PATH);
+ cmp = attrib.compareTo(otherAttrib);
+ if (cmp != 0) {
+ return cmp;
+ }
+ // Then compare by name
+ return getName().compareTo(other.getName());
+ }
+
}
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.tracecompass.tmf.analysis.xml.core.module.TmfXmlStrings;
import org.eclipse.tracecompass.tmf.analysis.xml.core.module.TmfXmlUtils;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
return Messages.XmlTimeGraphView_PreviousInterval;
}
+ /**
+ * Getter for the presentation provider
+ *
+ * @return The time graph presentation provider
+ */
+ @Override
+ protected XmlPresentationProvider getPresentationProvider() {
+ return (XmlPresentationProvider) super.getPresentationProvider();
+ }
+
/**
* Default label provider, it shows name, id and parent columns
*
if ((o1 instanceof XmlEntry) && (o2 instanceof XmlEntry)) {
XmlEntry entry1 = (XmlEntry) o1;
XmlEntry entry2 = (XmlEntry) o2;
- result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
- if (result == 0) {
- result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
- }
- if (result == 0) {
- result = entry1.getName().compareTo(entry2.getName());
- }
+ result = entry1.compareTo(entry2);
}
if (result == 0) {
/* Add children entry of this entry for each line */
for (Element entry : entries) {
- buildEntry(entry, groupEntry, -1);
+ buildEntry(entry, groupEntry, -1, StringUtils.EMPTY);
}
}
}
}
}
- private void buildEntry(Element entryElement, XmlEntry parentEntry, int baseQuark) {
+ private void buildEntry(Element entryElement, XmlEntry parentEntry, int prevBaseQuark, String prevRegex) {
/* Get the attribute string to display */
String path = entryElement.getAttribute(TmfXmlUiStrings.PATH);
if (path.isEmpty()) {
return;
}
- ITmfStateSystem ss = parentEntry.getStateSystem();
+ // Get the state system to use to populate those entries, by default, it is the same as the parent
+ String analysisId = entryElement.getAttribute(TmfXmlUiStrings.ANALYSIS_ID);
+ ITmfStateSystem parentSs = parentEntry.getStateSystem();
+ ITmfStateSystem ss = parentSs;
+ int baseQuark = prevBaseQuark;
+ if (!analysisId.isEmpty()) {
+ ss = TmfStateSystemAnalysisModule.getStateSystem(parentEntry.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);
+ }
+ String regexName = path.replaceAll("\\*", "(.*)"); //$NON-NLS-1$//$NON-NLS-2$
/* Get the list of quarks to process with this path */
- String[] paths = path.split(SPLIT_STRING);
+ 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].replaceAll("\\*", ".*"); //$NON-NLS-1$ //$NON-NLS-2$
+ String name = paths[i];
for (int relativeQuark : quarks) {
for (int quark : ss.getSubAttributes(relativeQuark, false, name)) {
subQuarks.add(quark);
}
/* Process the children entry of this entry */
for (Element subEntryEl : entryElements) {
- buildEntry(subEntryEl, currentEntry, quark);
+ buildEntry(subEntryEl, currentEntry, quark, prevRegex.isEmpty() ? regexName : prevRegex + '/' + regexName);
}
}
if (!entryMap.isEmpty()) {
return eventList;
}
+ private int getStringIndex(String stateStr) {
+ XmlPresentationProvider pres = getPresentationProvider();
+ Integer statusInt = fStringValueMap.get(stateStr);
+ if (statusInt != null) {
+ return statusInt;
+ }
+
+ // Add this new state to the presentation provider
+ int status = pres.addState(stateStr);
+ fStringValueMap.put(stateStr, status);
+ return status;
+
+ }
+
private int getStatusFromInterval(ITmfStateInterval statusInterval) {
ITmfStateValue stateValue = statusInterval.getStateValue();
+
int status = -1;
switch (stateValue.getType()) {
case INTEGER:
break;
case LONG:
status = (int) stateValue.unboxLong();
+ XmlPresentationProvider pres = this.getPresentationProvider();
+ if (!pres.hasIndex(status)) {
+ status = getStringIndex("0x" + Long.toHexString(stateValue.unboxLong())); //$NON-NLS-1$
+ }
break;
case STRING:
String statusStr = stateValue.unboxStr();
- Integer statusInt = fStringValueMap.get(statusStr);
- if (statusInt != null) {
- status = statusInt;
- break;
- }
- ITimeGraphPresentationProvider2 pres = this.getPresentationProvider();
- if (pres instanceof XmlPresentationProvider) {
- // Add this new state to the presentation provider
- status = ((XmlPresentationProvider) pres).addState(statusStr);
- fStringValueMap.put(statusStr, status);
- }
+ status = getStringIndex(statusStr);
break;
case DOUBLE:
status = (int) stateValue.unboxDouble();