From: Matthew Khouzam Date: Thu, 1 Oct 2015 00:59:02 +0000 (-0400) Subject: TMF: Fix behavior of XML time graph views with experiments X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=836d7c77cd2daccf7107d52e6e4bb78891a6ecb3;p=deliverable%2Ftracecompass.git TMF: Fix behavior of XML time graph views with experiments Expected behavior: * Show the content of analyses when the trace contains those analyses. * If experiment, show the content of analyses if any of the trace or the experiment itself contains those analyses. * Empty if no trace contains the required analyses. Change-Id: Id04c2f9d4f1ecd9c8c466a9a0536e1b07277ea1f Signed-off-by: Geneviève Bastien Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/35490 Reviewed-by: Hudson CI --- diff --git a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java index febc1a0ee0..868a456983 100644 --- a/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java +++ b/tmf/org.eclipse.tracecompass.tmf.analysis.xml.ui/src/org/eclipse/tracecompass/tmf/analysis/xml/ui/views/timegraph/XmlTimeGraphView.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -31,6 +32,7 @@ import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.widgets.Display; +import org.eclipse.tracecompass.common.core.NonNullUtils; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.Activator; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.TmfXmlUiStrings; import org.eclipse.tracecompass.internal.tmf.analysis.xml.ui.views.XmlViewInfo; @@ -63,6 +65,8 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent; import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry; import org.w3c.dom.Element; +import com.google.common.collect.Iterables; + /** * This view displays state system data in a time graph view. It uses an XML * {@link TmfXmlUiStrings#TIME_GRAPH_VIEW} element from an XML file. This @@ -167,7 +171,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView { * Default label provider, it shows name, id and parent columns * * TODO: There should be a way to define columns in the XML - * */ + */ private static class XmlTreeLabelProvider extends TreeLabelProvider { @Override @@ -246,58 +250,54 @@ public class XmlTimeGraphView extends AbstractTimeGraphView { List entries = XmlUtils.getChildElements(viewElement, TmfXmlUiStrings.ENTRY_ELEMENT); Set entryList = new TreeSet<>(getEntryComparator()); - for (ITmfTrace aTrace : TmfTraceManager.getTraceSet(trace)) { - aTrace = checkNotNull(aTrace); - if (monitor.isCanceled()) { - return; - } + if (monitor.isCanceled()) { + return; + } - List stateSystemModules = new LinkedList<>(); - if (analysisIds.isEmpty()) { - /* - * No analysis specified, take all state system analysis modules - */ - for (ITmfAnalysisModuleWithStateSystems module : TmfTraceUtils.getAnalysisModulesOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class)) { + Set stateSystemModules = new HashSet<>(); + if (analysisIds.isEmpty()) { + /* + * No analysis specified, take all state system analysis modules + */ + Iterables.addAll(stateSystemModules, TmfTraceUtils.getAnalysisModulesOfClass(trace, ITmfAnalysisModuleWithStateSystems.class)); + } else { + for (String moduleId : analysisIds) { + moduleId = checkNotNull(moduleId); + ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(trace, ITmfAnalysisModuleWithStateSystems.class, moduleId); + if (module != null) { stateSystemModules.add(module); } - } else { - for (String moduleId : analysisIds) { - moduleId = checkNotNull(moduleId); - ITmfAnalysisModuleWithStateSystems module = TmfTraceUtils.getAnalysisModuleOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class, moduleId); - if (module != null) { - stateSystemModules.add(module); - } - } } + } - for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) { - IStatus status = module.schedule(); - if (!status.isOK()) { - return; - } - if (module instanceof TmfStateSystemAnalysisModule) { - ((TmfStateSystemAnalysisModule) module).waitForInitialization(); - } - for (ITmfStateSystem ssq : module.getStateSystems()) { - ssq.waitUntilBuilt(); - - long startTime = ssq.getStartTime(); - long endTime = ssq.getCurrentEndTime(); - XmlEntry groupEntry = new XmlEntry(-1, aTrace, aTrace.getName(), ssq); - entryList.add(groupEntry); - setStartTime(Math.min(getStartTime(), startTime)); - setEndTime(Math.max(getEndTime(), endTime)); - - /* Add children entry of this entry for each line */ - for (Element entry : entries) { - buildEntry(entry, groupEntry, -1); - } + for (ITmfAnalysisModuleWithStateSystems module : stateSystemModules) { + IStatus status = module.schedule(); + if (!status.isOK()) { + return; + } + if (module instanceof TmfStateSystemAnalysisModule) { + ((TmfStateSystemAnalysisModule) module).waitForInitialization(); + } + for (ITmfStateSystem ssq : module.getStateSystems()) { + ssq.waitUntilBuilt(); + + long startTime = ssq.getStartTime(); + long endTime = ssq.getCurrentEndTime(); + XmlEntry groupEntry = new XmlEntry(-1, trace, trace.getName(), ssq); + entryList.add(groupEntry); + setStartTime(Math.min(getStartTime(), startTime)); + setEndTime(Math.max(getEndTime(), endTime)); + + /* Add children entry of this entry for each line */ + for (Element entry : entries) { + buildEntry(entry, groupEntry, -1); } } } + putEntryList(trace, new ArrayList(entryList)); - if (trace.equals(getTrace())) { + if (parentTrace.equals(getTrace())) { refresh(); } for (XmlEntry traceEntry : entryList) { @@ -461,7 +461,7 @@ public class XmlTimeGraphView extends AbstractTimeGraphView { */ if (parent != null && !(entry.getStartTime() > parent.getEndTime() || - entry.getEndTime() < parent.getStartTime())) { + entry.getEndTime() < parent.getStartTime())) { parent.addChild(entry); root = false; } @@ -524,4 +524,46 @@ public class XmlTimeGraphView extends AbstractTimeGraphView { return Collections.EMPTY_LIST; } + /** + * This method will pre-filter the traces that contain analysis modules + * supported by this view, whether they are from a trace or an experiment. + */ + @Override + protected Iterable getTracesToBuild(ITmfTrace trace) { + /* + * Get the view element from the XML file. If the element can't be + * found, return. + */ + Element viewElement = fViewInfo.getViewElement(TmfXmlUiStrings.TIME_GRAPH_VIEW); + if (viewElement == null) { + return super.getTracesToBuild(trace); + } + + Set analysisIds = fViewInfo.getViewAnalysisIds(viewElement); + Set traces = new HashSet<>(); + + for (ITmfTrace aTrace : TmfTraceManager.getTraceSetWithExperiment(trace)) { + if (aTrace == null) { + continue; + } + if ((analysisIds.isEmpty() && TmfTraceUtils.getAnalysisModulesOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class).iterator().hasNext())) { + /* + * No analysis ID specified, so this trace will be built only if + * it has state system modules + */ + traces.add(aTrace); + } else { + /* Build this trace only if it has one the requested modules */ + for (String moduleId : analysisIds) { + if (TmfTraceUtils.getAnalysisModuleOfClass(aTrace, ITmfAnalysisModuleWithStateSystems.class, NonNullUtils.checkNotNull(moduleId)) != null) { + traces.add(aTrace); + } + } + } + } + if (traces.isEmpty()) { + return super.getTracesToBuild(trace); + } + return traces; + } }