tmf: Make entry comparator apply recursively in AbstractTimeGraphView
authorPatrick Tasse <patrick.tasse@gmail.com>
Tue, 17 Nov 2015 16:02:33 +0000 (11:02 -0500)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 20 Nov 2015 20:40:50 +0000 (15:40 -0500)
Also update ControlFlowView's comparator so that it applies correctly to
non-root child process entries.

Change-Id: If02011789f53c12ef14e128651fdcaf0daedcc8b
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/60665
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/analysis/os/linux/ui/views/controlflow/ControlFlowView.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/timegraph/AbstractTimeGraphView.java

index 38a0b2d1f213049b02307b83dfef61c1cfe309b8..d4b36b38038f07294badc9a92b94d3a19b9c247d 100644 (file)
@@ -165,9 +165,18 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
         @Override
         public int compare(ITimeGraphEntry o1, ITimeGraphEntry o2) {
 
+            if (o1.getParent() != null || o2.getParent() != null) {
+                /* Sort all child processes according to birth time. */
+                return Long.compare(o1.getStartTime(), o2.getStartTime());
+            }
+
             int result = 0;
 
             if ((o1 instanceof ControlFlowEntry) && (o2 instanceof ControlFlowEntry)) {
+                /*
+                 * Sort root processes according to their trace's start time,
+                 * then by trace name, then by the process thread id.
+                 */
                 ControlFlowEntry entry1 = (ControlFlowEntry) o1;
                 ControlFlowEntry entry2 = (ControlFlowEntry) o2;
                 result = entry1.getTrace().getStartTime().compareTo(entry2.getTrace().getStartTime());
@@ -175,12 +184,13 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                     result = entry1.getTrace().getName().compareTo(entry2.getTrace().getName());
                 }
                 if (result == 0) {
-                    result = entry1.getThreadId() < entry2.getThreadId() ? -1 : entry1.getThreadId() > entry2.getThreadId() ? 1 : 0;
+                    result = Integer.compare(entry1.getThreadId(), entry2.getThreadId());
                 }
             }
 
             if (result == 0) {
-                result = o1.getStartTime() < o2.getStartTime() ? -1 : o1.getStartTime() > o2.getStartTime() ? 1 : 0;
+                /* Sort root processes with reused thread id by birth time. */
+                result = Long.compare(o1.getStartTime(), o2.getStartTime());
             }
 
             return result;
index bbaa50669f81582fbaa5ecc425677f6c4f822bfb..a934df7daadeb3dc12ef41138dc405a5e647109d 100644 (file)
@@ -844,7 +844,10 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
     }
 
     /**
-     * Sets the comparator class for the entries
+     * Sets the comparator class for the entries.
+     * <p>
+     * This comparator will apply recursively to entries that implement
+     * {@link TimeGraphEntry#sortChildren(Comparator)}.
      *
      * @param comparator
      *            A comparator object
@@ -1572,6 +1575,9 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
                     } else if (fEntryComparator != null) {
                         List<TimeGraphEntry> list = new ArrayList<>(fEntryList);
                         Collections.sort(list, fEntryComparator);
+                        for (ITimeGraphEntry entry : list) {
+                            sortChildren(entry, fEntryComparator);
+                        }
                         fEntryList.clear();
                         fEntryList.addAll(list);
                     }
@@ -1650,6 +1656,15 @@ public abstract class AbstractTimeGraphView extends TmfView implements ITmfTimeA
         });
     }
 
+    private static void sortChildren(ITimeGraphEntry entry, Comparator<ITimeGraphEntry> comparator) {
+        if (entry instanceof TimeGraphEntry) {
+            ((TimeGraphEntry) entry).sortChildren(comparator);
+        }
+        for (ITimeGraphEntry child : entry.getChildren()) {
+            sortChildren(child, comparator);
+        }
+    }
+
     /**
      * Start or restart the zoom thread.
      *
This page took 0.029544 seconds and 5 git commands to generate.