graph: bug 559133 Worker return aspects of original type

The getWorkerInformation(), which provides formatted information for the
views, was used to get the metadata aspects of the graph worker. A new
method is added to return aspects data, ie data that can be used in
filters and comparisons.

[added] IGraphWorker#getWorkerAspects method to retrieve aspect data.

Change-Id: I040b3295c185fd097c0bb543636ccb8487b39e43
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/155864
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/base/IGraphWorker.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/base/IGraphWorker.java
index f2fbe85..7e33c27 100644
--- a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/base/IGraphWorker.java
+++ b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/analysis/graph/core/base/IGraphWorker.java
@@ -13,8 +13,11 @@
 package org.eclipse.tracecompass.analysis.graph.core.base;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
+import org.eclipse.jdt.annotation.NonNull;
+
 /**
  * Interface that the objects in a graph may implement
  *
@@ -42,6 +45,25 @@
     }
 
     /**
+     * Get additional information on this worker. Unlike
+     * {@link #getWorkerInformation()}, this method returns unformatted data in
+     * their original type. It can be used to filter and compare data with other
+     * model objects.
+     *
+     * @return A key, value map of information this worker provides.
+     * @since 2.1
+     */
+    default Map<@NonNull String, @NonNull Object> getWorkerAspects() {
+        Map<String, String> workerInformation = getWorkerInformation();
+        if (workerInformation.isEmpty()) {
+            return Collections.emptyMap();
+        }
+        Map<String, Object> map = new HashMap<>();
+        map.putAll(workerInformation);
+        return map;
+    }
+
+    /**
      * Get additional information on this worker at time t. This would be
      * textual information, in the form of key, value pairs, that could be
      * displayed for instance as a tooltip in the graph view.
diff --git a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/dataprovider/CriticalPathEntry.java b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/dataprovider/CriticalPathEntry.java
index bf47434..baf54e7 100644
--- a/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/dataprovider/CriticalPathEntry.java
+++ b/analysis/org.eclipse.tracecompass.analysis.graph.core/src/org/eclipse/tracecompass/internal/analysis/graph/core/dataprovider/CriticalPathEntry.java
@@ -28,6 +28,7 @@
  */
 public class CriticalPathEntry extends TimeGraphEntryModel {
 
+    private static final String HOST_ID_STR = "hostId"; //$NON-NLS-1$
     private final Long fSum;
     private final Double fPercent;
     private final @NonNull Multimap<@NonNull String, @NonNull Object> fAspects = HashMultimap.create();
@@ -57,8 +58,8 @@
         super(id, parentId, Collections.singletonList(String.valueOf(worker)), startTime, endTime);
         fSum = sum;
         fPercent = percent;
-        fAspects.put("hostId", worker.getHostId());
-        for (Entry<String, String> entry : worker.getWorkerInformation().entrySet()) {
+        fAspects.put(HOST_ID_STR, worker.getHostId());
+        for (Entry<@NonNull String, @NonNull Object> entry : worker.getWorkerAspects().entrySet()) {
             fAspects.put(entry.getKey(), entry.getValue());
         }
     }
diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java
index 228f7dc..d90d3a2 100644
--- a/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java
+++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.core/src/org/eclipse/tracecompass/analysis/os/linux/core/execution/graph/OsWorker.java
@@ -75,6 +75,15 @@
         return Collections.singletonMap(OsStrings.tid(), String.valueOf(tid));
     }
 
+    @Override
+    public @NonNull Map<@NonNull String, @NonNull Object> getWorkerAspects() {
+        int tid = fHostTid.getTid();
+        if (tid == -1) {
+            return Collections.emptyMap();
+        }
+        return Collections.singletonMap(OsStrings.tid(), tid);
+    }
+
     @SuppressWarnings("null")
     @Override
     public @NonNull Map<@NonNull String, @NonNull String> getWorkerInformation(long t) {
diff --git a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/CriticalPathTest.java b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/CriticalPathTest.java
index 784bfae..8f05b83 100644
--- a/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/CriticalPathTest.java
+++ b/lttng/org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests/src/org/eclipse/tracecompass/lttng2/kernel/ui/swtbot/tests/CriticalPathTest.java
@@ -57,8 +57,9 @@
     private static final String TID2 = String.valueOf(TID_NO2);
     private static final String PROCESS2 = "weston-desktop-";
     private static final @NonNull String CP_ID = "org.eclipse.linuxtools.tmf.analysis.graph.ui.criticalpath.view.criticalpathview";
+    private static final String KWORKER_PROCESS = "kworker/u16:0";
     private static final String CRIT_PATH_MAIN_ENTRY = "[" + PROCESS + "," + TID + "]";
-    private static final String CRIT_PATH_OTHER_ENTRY = "[kworker/u16:0,6]";
+    private static final String CRIT_PATH_OTHER_ENTRY = "[" + KWORKER_PROCESS + ",6]";
     private static final String CRIT_PATH_MAIN_ENTRY2 = "[" + PROCESS2 + "," + TID2 + "]";
 
     private static final String FOLLOW_FORWARD = "Follow critical path forward";
@@ -144,10 +145,14 @@
         fViewBotCp.toolbarButton(FOLLOW_FORWARD).click();
         fBot.waitUntil(timeGraphIsReadyCondition);
         fBot.waitUntil(ConditionHelpers.timeGraphSelectionContains(timeGraphCp, 0, CRIT_PATH_OTHER_ENTRY));
+        // Make sure changing the selection changed the selection in CFV too
+        fBot.waitUntil(ConditionHelpers.timeGraphSelectionContains(timeGraphCfv, 0, KWORKER_PROCESS));
         // Follow it back up
         fViewBotCp.toolbarButton(FOLLOW_BACKWARD).click();
         fBot.waitUntil(timeGraphIsReadyCondition);
         fBot.waitUntil(ConditionHelpers.timeGraphSelectionContains(timeGraphCp, 0, CRIT_PATH_MAIN_ENTRY));
+        // Make sure changing the selection changed the selection in CFV too
+        fBot.waitUntil(ConditionHelpers.timeGraphSelectionContains(timeGraphCfv, 0, PROCESS));
 
         // Follow another process and make sure the critical path changes
         entry = timeGraphCfv.getEntry(trace.getName(), "systemd", "we", PROCESS, PROCESS2);