tmf: Bug 494197: Empty event list for CallStackEntry when no process
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / tmf / ui / views / callstack / CallStackView.java
index 7256c1c38cddaff2d66b96f3016908a9d821e052..8e915d84a86f8926d582a220450181bafe6e18e7 100644 (file)
@@ -577,40 +577,49 @@ public class CallStackView extends AbstractTimeGraphView {
                 traceEntry.updateEndTime(end);
             }
 
-            List<Integer> processQuarks = ss.getQuarks(module.getProcessesPattern());
-            for (int processQuark : processQuarks) {
-
-                /*
-                 * Default to trace entry, overwrite if a process entry exists.
-                 */
-                TimeGraphEntry threadParent = traceEntry;
-                int processId = -1;
-                if (processQuark != ITmfStateSystem.ROOT_ATTRIBUTE) {
-                    /* Create the entry for the process */
-                    ProcessEntry processEntry = processEntryMap.get(processQuark);
-                    if (processEntry == null) {
-                        String name = ss.getAttributeName(processQuark);
-                        /* The attribute name should already be parseable to integer */
-                        processId = Integer.parseInt(name);
-                        processEntry = new ProcessEntry(name, processId, start, end);
-                        processEntryMap.put(processQuark, processEntry);
-                        traceEntry.addChild(processEntry);
-                    } else {
-                        processEntry.updateEndTime(end);
+            try {
+                List<ITmfStateInterval> endStates = ss.queryFullState(ss.getCurrentEndTime());
+
+                List<Integer> processQuarks = ss.getQuarks(module.getProcessesPattern());
+                for (int processQuark : processQuarks) {
+
+                    /*
+                     * Default to trace entry, overwrite if a process entry exists.
+                     */
+                    TimeGraphEntry threadParent = traceEntry;
+                    int processId = -1;
+                    if (processQuark != ITmfStateSystem.ROOT_ATTRIBUTE) {
+                        /* Create the entry for the process */
+                        ProcessEntry processEntry = processEntryMap.get(processQuark);
+                        if (processEntry == null) {
+                            String processName = ss.getAttributeName(processQuark);
+                            ITmfStateValue processStateValue = endStates.get(processQuark).getStateValue();
+                            if (processStateValue.getType() == Type.INTEGER) {
+                                processId = processStateValue.unboxInt();
+                            } else {
+                                try {
+                                    processId = Integer.parseInt(processName);
+                                } catch (NumberFormatException e) {
+                                    /* use default processId */
+                                }
+                            }
+                            processEntry = new ProcessEntry(processName, processId, start, end);
+                            processEntryMap.put(processQuark, processEntry);
+                            traceEntry.addChild(processEntry);
+                        } else {
+                            processEntry.updateEndTime(end);
+                        }
+                        /* The parent of the thread entries will be a process */
+                        threadParent = processEntry;
                     }
-                    /* The parent of the thread entries will be a process */
-                    threadParent = processEntry;
-                }
 
-                /* Create the threads under the process */
-                try {
+                    /* Create the threads under the process */
                     List<Integer> threadQuarks = ss.getQuarks(processQuark, module.getThreadsPattern());
 
                     /*
                      * Only query startStates if necessary (threadEntry == null)
                      */
                     List<ITmfStateInterval> startStates = null;
-                    List<ITmfStateInterval> endStates = ss.queryFullState(ss.getCurrentEndTime());
                     for (int threadQuark : threadQuarks) {
                         if (monitor.isCanceled()) {
                             return;
@@ -634,7 +643,17 @@ public class CallStackView extends AbstractTimeGraphView {
                                 if (startStates == null) {
                                     startStates = ss.queryFullState(ss.getStartTime());
                                 }
-                                long threadId = endStates.get(threadQuark).getStateValue().unboxLong();
+                                long threadId = -1;
+                                ITmfStateValue threadStateValue = endStates.get(threadQuark).getStateValue();
+                                if (threadStateValue.getType() == Type.LONG || threadStateValue.getType() == Type.INTEGER) {
+                                    threadId = threadStateValue.unboxLong();
+                                } else {
+                                    try {
+                                        threadId = Long.parseLong(threadName);
+                                    } catch (NumberFormatException e) {
+                                        /* use default threadId */
+                                    }
+                                }
                                 long threadStart = start;
                                 ITmfStateInterval startInterval = startStates.get(callStackQuark);
                                 if (startInterval.getStateValue().isNull()) {
@@ -658,11 +677,11 @@ public class CallStackView extends AbstractTimeGraphView {
                             level++;
                         }
                     }
-                } catch (AttributeNotFoundException e) {
-                    Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
-                } catch (StateSystemDisposedException e) {
-                    /* Ignored */
                 }
+            } catch (AttributeNotFoundException e) {
+                Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
+            } catch (StateSystemDisposedException e) {
+                /* Ignored */
             }
 
             if (parentTrace == getTrace()) {
@@ -674,16 +693,21 @@ public class CallStackView extends AbstractTimeGraphView {
                 refresh();
             }
 
-            for (ITimeGraphEntry processEntry : traceEntry.getChildren()) {
-                for (ITimeGraphEntry threadEntry : processEntry.getChildren()) {
-                    for (ITimeGraphEntry callStackEntry : threadEntry.getChildren()) {
-                        if (monitor.isCanceled()) {
-                            return;
-                        }
-                        buildStatusEvents(parentTrace, (CallStackEntry) callStackEntry, monitor, ss.getStartTime(), end);
+            Consumer<TimeGraphEntry> consumer = new Consumer<TimeGraphEntry>() {
+                @Override
+                public void accept(TimeGraphEntry entry) {
+                    if (monitor.isCanceled()) {
+                        return;
+                    }
+                    if (entry instanceof CallStackEntry) {
+                        buildStatusEvents(parentTrace, (CallStackEntry) entry, monitor, ss.getStartTime(), end);
+                        return;
                     }
+                    entry.getChildren().forEach(this);
                 }
-            }
+            };
+            traceEntry.getChildren().forEach(consumer);
+
             start = end;
         }
     }
@@ -710,7 +734,7 @@ public class CallStackView extends AbstractTimeGraphView {
     }
 
     /**
-     * @since 2.0
+     * @since 1.2
      */
     @Override
     protected final List<ITimeEvent> getEventList(TimeGraphEntry tgentry, long startTime, long endTime, long resolution, IProgressMonitor monitor) {
@@ -771,7 +795,7 @@ public class CallStackView extends AbstractTimeGraphView {
     }
 
     /**
-     * @since 2.0
+     * @since 1.2
      */
     @Override
     protected void synchingToTime(final long time) {
@@ -901,7 +925,7 @@ public class CallStackView extends AbstractTimeGraphView {
     }
 
     /**
-     * @since 2.0
+     * @since 1.2
      */
     @Override
     protected void fillLocalToolBar(IToolBarManager manager) {
@@ -968,7 +992,7 @@ public class CallStackView extends AbstractTimeGraphView {
                             viewer.getTimeGraphControl().fireSelectionChanged();
                             startZoomThread(viewer.getTime0(), viewer.getTime1());
 
-                        } catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
+                        } catch (TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
                             Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
                         }
                     }
@@ -1013,7 +1037,7 @@ public class CallStackView extends AbstractTimeGraphView {
                             viewer.getTimeGraphControl().fireSelectionChanged();
                             startZoomThread(viewer.getTime0(), viewer.getTime1());
 
-                        } catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
+                        } catch (TimeRangeException | StateSystemDisposedException | StateValueTypeException e) {
                             Activator.getDefault().logError("Error querying state system", e); //$NON-NLS-1$
                         }
                     }
This page took 0.026159 seconds and 5 git commands to generate.