Support for upgrading Linux Tools features to Trace Compass
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.ui / src / org / eclipse / tracecompass / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowView.java
index 927a31c16fdebce45df46eff3e5de61cce4131e8..87b8571b848ce40d49d16ab08f6e820236a703a1 100644 (file)
@@ -20,6 +20,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IToolBarManager;
@@ -27,7 +28,8 @@ import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.tracecompass.internal.lttng2.kernel.core.Attributes;
 import org.eclipse.tracecompass.internal.lttng2.kernel.ui.Activator;
 import org.eclipse.tracecompass.internal.lttng2.kernel.ui.Messages;
-import org.eclipse.tracecompass.lttng2.kernel.core.analysis.LttngKernelAnalysisModule;
+import org.eclipse.tracecompass.lttng2.kernel.core.analysis.kernel.LttngKernelAnalysis;
+import org.eclipse.tracecompass.lttng2.kernel.core.analysis.kernel.LttngKernelThreadInformationProvider;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
@@ -39,6 +41,7 @@ import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ui.views.timegraph.AbstractTimeGraphView;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ILinkEvent;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
@@ -223,10 +226,7 @@ public class ControlFlowView extends AbstractTimeGraphView {
 
     @Override
     protected void buildEventList(final ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
-        if (trace == null) {
-            return;
-        }
-        ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysisModule.ID);
+        ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
         if (ssq == null) {
             return;
         }
@@ -290,19 +290,18 @@ public class ControlFlowView extends AbstractTimeGraphView {
                         String execName = execNameInterval.getStateValue().unboxStr();
                         long startTime = execNameInterval.getStartTime();
                         long endTime = execNameInterval.getEndTime() + 1;
+
                         if (entry == null) {
                             ITmfStateInterval ppidInterval = null;
                             try {
                                 int ppidQuark = ssq.getQuarkRelative(threadQuark, Attributes.PPID);
-                                ppidInterval = ssq.querySingleState(startTime, ppidQuark);
+                                ppidInterval = StateSystemUtils.queryUntilNonNullValue(ssq, ppidQuark, startTime, endTime);
                             } catch (AttributeNotFoundException e) {
                                 /* No info, keep PPID at -1 */
-                            } catch (StateSystemDisposedException e) {
-                                /* SS is closing down, time to bail */
-                                break;
                             }
+
                             int ppid = -1;
-                            if (!(ppidInterval == null) && !ppidInterval.getStateValue().isNull()) {
+                            if (ppidInterval != null) {
                                 ppid = ppidInterval.getStateValue().unboxInt();
                             }
                             entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
@@ -346,9 +345,17 @@ public class ControlFlowView extends AbstractTimeGraphView {
             boolean root = (entry.getParent() == null);
             if (root && entry.getParentThreadId() > 0) {
                 for (ControlFlowEntry parent : entryList) {
+                    /*
+                     * 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.getThreadId() == entry.getParentThreadId() &&
-                            entry.getStartTime() >= parent.getStartTime() &&
-                            entry.getStartTime() <= parent.getEndTime()) {
+                            !(entry.getStartTime() > parent.getEndTime() ||
+                            entry.getEndTime() < parent.getStartTime())) {
                         parent.addChild(entry);
                         root = false;
                         if (rootList != null && rootList.contains(entry)) {
@@ -367,9 +374,9 @@ public class ControlFlowView extends AbstractTimeGraphView {
         removeFromEntryList(parentTrace, rootListToRemove);
     }
 
-    private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, IProgressMonitor monitor, long start, long end) {
+    private void buildStatusEvents(ITmfTrace trace, ControlFlowEntry entry, @NonNull IProgressMonitor monitor, long start, long end) {
         if (start < entry.getEndTime() && end > entry.getStartTime()) {
-            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysisModule.ID);
+            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysis.ID);
             if (ssq == null) {
                 return;
             }
@@ -408,13 +415,12 @@ public class ControlFlowView extends AbstractTimeGraphView {
         if (realEnd <= realStart) {
             return null;
         }
-        ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(entry.getTrace(), LttngKernelAnalysisModule.ID);
-        if (ssq == null) {
+        LttngKernelAnalysis kernelAnalysis = TmfTraceUtils.getAnalysisModuleOfClass(entry.getTrace(), LttngKernelAnalysis.class, LttngKernelAnalysis.ID);
+        if (kernelAnalysis == null) {
             return null;
         }
         try {
-            int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);
-            List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ssq, statusQuark, realStart, realEnd - 1, resolution, monitor);
+            List<ITmfStateInterval> statusIntervals = LttngKernelThreadInformationProvider.getStatusIntervalsForThread(kernelAnalysis, entry.getThreadId(), realStart, realEnd, resolution, monitor);
             eventList = new ArrayList<>(statusIntervals.size());
             long lastEndTime = -1;
             for (ITmfStateInterval statusInterval : statusIntervals) {
@@ -435,10 +441,8 @@ public class ControlFlowView extends AbstractTimeGraphView {
                 eventList.add(new TimeEvent(entry, time, duration, status));
                 lastEndTime = time + duration;
             }
-        } catch (AttributeNotFoundException | TimeRangeException e) {
-            e.printStackTrace();
-        } catch (StateSystemDisposedException e) {
-            /* Ignored */
+        } catch (TimeRangeException e) {
+            Activator.getDefault().logError(e.getMessage());
         }
         return eventList;
     }
@@ -466,7 +470,7 @@ public class ControlFlowView extends AbstractTimeGraphView {
             if (trace == null) {
                 continue;
             }
-            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysisModule.ID);
+            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
             if (ssq == null) {
                 continue;
             }
@@ -523,7 +527,7 @@ public class ControlFlowView extends AbstractTimeGraphView {
             if (trace == null) {
                 continue;
             }
-            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysisModule.ID);
+            ITmfStateSystem ssq = TmfStateSystemAnalysisModule.getStateSystem(trace, LttngKernelAnalysis.ID);
             if (ssq == null) {
                 continue;
             }
This page took 0.029389 seconds and 5 git commands to generate.