lttng: Check the state system query results more rigorously
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Mon, 3 Feb 2014 23:20:34 +0000 (18:20 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 4 Feb 2014 20:04:20 +0000 (15:04 -0500)
Defensive programming dictates we should check for integrity,
correctness, etc. at different layers. And not just once and
assume it's safe at every other levels.

In this case, if we had a trace with a sched_process_free event
arriving first for a new TID, the CFV would assume the Exec_name
attribute would be already set, which was not the case.

Change-Id: I0489937be07282c236978a07e48c4221160bb1d9
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/21490
Tested-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>

org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java

index ce25ecf4c3fc1f633adc277282065284b76f94b3..2e0145d64af877726d6627172d9368781c1899a4 100644 (file)
@@ -266,42 +266,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 */
                 }
             }
 
This page took 0.026167 seconds and 5 git commands to generate.