lttng: Fix thread ordering in virtual machine view
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 13 Jan 2016 03:42:57 +0000 (22:42 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Thu, 21 Jan 2016 14:55:31 +0000 (09:55 -0500)
Threads in the virtual machine view are now ordered by their numeric thread IDs
instead of the corresponding string which makes it more intuitive.

Change-Id: I681e3423dcea9e946b74bebe4e2d0416680ccfa9
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/64205
Reviewed-by: Hudson CI
lttng/org.eclipse.tracecompass.lttng2.kernel.ui/src/org/eclipse/tracecompass/internal/lttng2/kernel/ui/views/vm/vcpuview/VirtualMachineView.java
lttng/org.eclipse.tracecompass.lttng2.kernel.ui/src/org/eclipse/tracecompass/internal/lttng2/kernel/ui/views/vm/vcpuview/VirtualMachineViewEntry.java

index 21b6cc4f3aba5ad1fa7b9f68a911ca47070a2eb2..d496efc681ca25704c45d26ac64e25bd82d47fc9 100644 (file)
@@ -70,22 +70,7 @@ public class VirtualMachineView extends AbstractTimeGraphView {
     private static final long BUILD_UPDATE_TIMEOUT = 500;
     private static final int[] DEFAULT_WEIGHT = { 1, 3 };
 
-    private Comparator<ITimeGraphEntry> fComparator = new Comparator<ITimeGraphEntry>() {
-        @Override
-        public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
-            if (!((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry))) {
-                return 0;
-            }
-            VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
-            VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
-            int cmp = entry1.getType().compareTo(entry2.getType());
-            /* FIXME: Threads should be ordered by their thread IDs instead */
-            if (cmp == 0) {
-                cmp = entry1.getName().compareTo(entry2.getName());
-            }
-            return cmp;
-        }
-    };
+    private Comparator<ITimeGraphEntry> fComparator = VirtualMachineViewEntry.getComparator();
 
     // ------------------------------------------------------------------------
     // Constructors
index 913ba5269a239459e2c4530b538704345e413233..26e4eb86f22ba8336fae4ada254be664cc95330c 100644 (file)
@@ -35,14 +35,17 @@ public final class VirtualMachineViewEntry extends TimeGraphEntry {
 
         @Override
         public int compare(@Nullable ITimeGraphEntry o1, @Nullable ITimeGraphEntry o2) {
-
-            int result = 0;
-
-            if ((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry)) {
-                VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
-                VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
-                result = entry1.getType().compareTo(entry2.getType());
-                if (result == 0) {
+            if (!((o1 instanceof VirtualMachineViewEntry) && (o2 instanceof VirtualMachineViewEntry))) {
+                return 0;
+            }
+            VirtualMachineViewEntry entry1 = (VirtualMachineViewEntry) o1;
+            VirtualMachineViewEntry entry2 = (VirtualMachineViewEntry) o2;
+            int result = entry1.getType().compareTo(entry2.getType());
+            if (result == 0) {
+                /* If there is a numeric ID, use it instead */
+                if (entry1.getNumericId() != -1) {
+                    result = entry1.getNumericId().compareTo(entry2.getNumericId());
+                } else {
                     result = entry1.getId().compareTo(entry2.getId());
                 }
             }
@@ -196,7 +199,7 @@ public final class VirtualMachineViewEntry extends TimeGraphEntry {
          * @return A new {@link VirtualMachineViewEntry} object
          */
         public VirtualMachineViewEntry build() {
-            switch(fbType) {
+            switch (fbType) {
             case VCPU:
                 fbEntryName = Messages.VmView_VCpu + ' ' + fbEntryName;
                 break;
@@ -296,7 +299,8 @@ public final class VirtualMachineViewEntry extends TimeGraphEntry {
 
     /**
      * Set the intervals for the threads of the corresponding virtual machine.
-     * This should be called only if the type of this entry is {@link Type#VM}.
+     * This should be called only if the type of this entry is
+     * {@link Type#VM}.
      *
      * @param threadIntervals
      *            The map of intervals for each thread ID
@@ -305,4 +309,12 @@ public final class VirtualMachineViewEntry extends TimeGraphEntry {
         fThreadIntervals = threadIntervals;
     }
 
+    /**
+     * Get the default implementation of virtual machine entry comparator
+     *
+     * @return A virtual machine entry comparator
+     */
+    public static Comparator<ITimeGraphEntry> getComparator() {
+        return COMPARATOR;
+    }
 }
This page took 0.028652 seconds and 5 git commands to generate.