tmf: Split the state system in a separate plugin
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.ui / src / org / eclipse / linuxtools / internal / lttng2 / kernel / ui / views / controlflow / ControlFlowView.java
index ce25ecf4c3fc1f633adc277282065284b76f94b3..3bbd30ca991056ff451469aa084464ad561daa1b 100644 (file)
@@ -20,20 +20,21 @@ import java.util.List;
 import java.util.Map;
 
 import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.dialogs.IDialogSettings;
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Attributes;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.kernel.ui.Messages;
-import org.eclipse.linuxtools.lttng2.kernel.ui.analysis.LttngKernelAnalysisModule;
-import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException;
-import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException;
-import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
-import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
-import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
-import org.eclipse.linuxtools.tmf.core.statevalue.ITmfStateValue;
+import org.eclipse.linuxtools.lttng2.kernel.core.analysis.LttngKernelAnalysisModule;
+import org.eclipse.linuxtools.statesystem.core.ITmfStateSystem;
+import org.eclipse.linuxtools.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.linuxtools.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.linuxtools.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.linuxtools.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
 import org.eclipse.linuxtools.tmf.ui.views.timegraph.AbstractTimeGraphView;
@@ -266,42 +267,57 @@ public class ControlFlowView extends AbstractTimeGraphView {
                 if (threadId <= 0) { // ignore the 'unknown' (-1) and swapper (0) threads
                     continue;
                 }
+
+                int execNameQuark;
+                List<ITmfStateInterval> execNameIntervals;
                 try {
-                    int execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);
-                    List<ITmfStateInterval> execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end);
-                    for (ITmfStateInterval execNameInterval : execNameIntervals) {
-                        if (monitor.isCanceled()) {
-                            return;
-                        }
-                        ControlFlowEntry entry = entryMap.get(threadId);
-                        if (!execNameInterval.getStateValue().isNull() &&
-                                execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
-                            String execName = execNameInterval.getStateValue().unboxStr();
-                            long startTime = execNameInterval.getStartTime();
-                            long endTime = execNameInterval.getEndTime() + 1;
-                            if (entry == null) {
-                                int ppid = -1;
+                    execNameQuark = ssq.getQuarkRelative(threadQuark, Attributes.EXEC_NAME);
+                    execNameIntervals = ssq.queryHistoryRange(execNameQuark, start, end);
+                } catch (AttributeNotFoundException e) {
+                    /* No information on this thread (yet?), skip it for now */
+                    continue;
+                } catch (StateSystemDisposedException e) {
+                    /* State system is closing down, no point continuing */
+                    break;
+                }
+
+                for (ITmfStateInterval execNameInterval : execNameIntervals) {
+                    if (monitor.isCanceled()) {
+                        return;
+                    }
+                    ControlFlowEntry entry = entryMap.get(threadId);
+                    if (!execNameInterval.getStateValue().isNull() &&
+                            execNameInterval.getStateValue().getType() == ITmfStateValue.Type.STRING) {
+                        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);
-                                ITmfStateInterval ppidInterval = ssq.querySingleState(startTime, ppidQuark);
-                                if (!ppidInterval.getStateValue().isNull()) {
-                                    ppid = ppidInterval.getStateValue().unboxInt();
-                                }
-                                entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
-                                entryList.add(entry);
-                                entryMap.put(threadId, entry);
-                            } else {
-                                // update the name of the entry to the latest execName
-                                entry.setName(execName);
-                                entry.updateEndTime(endTime);
+                                ppidInterval = ssq.querySingleState(startTime, ppidQuark);
+                            } 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()) {
+                                ppid = ppidInterval.getStateValue().unboxInt();
                             }
+                            entry = new ControlFlowEntry(threadQuark, trace, execName, threadId, ppid, startTime, endTime);
+                            entryList.add(entry);
+                            entryMap.put(threadId, entry);
                         } else {
-                            entryMap.remove(threadId);
+                            // update the name of the entry to the latest
+                            // execName
+                            entry.setName(execName);
+                            entry.updateEndTime(endTime);
                         }
+                    } else {
+                        entryMap.remove(threadId);
                     }
-                } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
-                    e.printStackTrace();
-                } catch (StateSystemDisposedException e) {
-                    /* Ignored */
                 }
             }
 
@@ -367,7 +383,7 @@ public class ControlFlowView extends AbstractTimeGraphView {
             long endTime = Math.min(end + 1, entry.getEndTime());
             long resolution = Math.max(1, (end - ssq.getStartTime()) / getDisplayWidth());
             List<ITimeEvent> eventList = getEventList(entry, startTime, endTime, resolution, monitor);
-            if (monitor.isCanceled()) {
+            if (eventList == null) {
                 return;
             }
             for (ITimeEvent event : eventList) {
@@ -386,7 +402,7 @@ public class ControlFlowView extends AbstractTimeGraphView {
     }
 
     @Override
-    protected List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
+    protected @Nullable List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
         List<ITimeEvent> eventList = null;
         if (!(tgentry instanceof ControlFlowEntry)) {
             return eventList;
This page took 0.026707 seconds and 5 git commands to generate.