TMF: Add utility method to return trace set, including experiment
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 13 Jun 2014 19:19:25 +0000 (15:19 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 9 Jul 2014 17:23:26 +0000 (13:23 -0400)
And add the experiment state systems in the state system explorer

Change-Id: I0470804d2057b25a778f04c195661d505fdaf7be
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/29394
Tested-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java
org.eclipse.linuxtools.tmf.ctf.core.tests/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/tracemanager/TmfTraceManagerTest.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java

index 4a617a2517ebfb4c2a714109443ee371ec13bcd5..3536a0c66962a419cd7bc2a6b0823a27a4cb5aa0 100644 (file)
 package org.eclipse.linuxtools.tmf.core.trace;
 
 import java.io.File;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 
@@ -25,6 +27,7 @@ import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.internal.tmf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
 import org.eclipse.linuxtools.tmf.core.filter.ITmfFilter;
@@ -205,6 +208,35 @@ public final class TmfTraceManager {
         return new ITmfTrace[] { trace };
     }
 
+    /**
+     * Get the trace set of a given trace or experiment, including the
+     * experiment. For a standard trace, this is simply a set containing only
+     * that trace. For experiments, it is the set of all the traces contained in
+     * this experiment, along with the experiment.
+     *
+     * @param trace
+     *            The trace or experiment
+     * @return The corresponding trace set, including the experiment
+     * @since 3.1
+     */
+    public static @NonNull Set<ITmfTrace> getTraceSetWithExperiment(ITmfTrace trace) {
+        if (trace == null) {
+            @SuppressWarnings("null")
+            @NonNull Set<ITmfTrace> emptySet = Collections.EMPTY_SET;
+            return emptySet;
+        }
+        if (trace instanceof TmfExperiment) {
+            TmfExperiment exp = (TmfExperiment) trace;
+            ITmfTrace[] traces = exp.getTraces();
+            Set<ITmfTrace> alltraces = new LinkedHashSet<>(Arrays.asList(traces));
+            alltraces.add(exp);
+            return alltraces;
+        }
+        @SuppressWarnings("null")
+        @NonNull Set<ITmfTrace> singleton = Collections.singleton(trace);
+        return singleton;
+    }
+
     /**
      * Return the path (as a string) to the directory for supplementary files to
      * use with a given trace. If no supplementary file directory has been
index a17b351b6acd868f265d66748488932ef7aa2c82..8ceaa20122e504e96bf45431656b5c138901485a 100644 (file)
@@ -24,4 +24,5 @@ Export-Package: org.eclipse.linuxtools.tmf.ctf.core.tests,
  org.eclipse.linuxtools.tmf.ctf.core.tests.statistics;x-internal:=true,
  org.eclipse.linuxtools.tmf.ctf.core.tests.stubs,
  org.eclipse.linuxtools.tmf.ctf.core.tests.tracemanager;x-internal:=true
-Import-Package: org.eclipse.test.performance
+Import-Package: com.google.common.collect,
+ org.eclipse.test.performance
index 7345d72e2ec353f883b3ceed6d95ad2b1d98c87c..68c994960cfd01a29d9cf769f749c517d4f936cd 100644 (file)
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertSame;
 import static org.junit.Assume.assumeTrue;
 
 import java.io.File;
+import java.util.Set;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
@@ -41,6 +42,8 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * Test suite for the {@link TmfTraceManager}.
  *
@@ -193,6 +196,25 @@ public class TmfTraceManagerTest {
         assertArrayEquals(expected, actual);
     }
 
+    /**
+     * Test the contents of the complete trace set.
+     */
+    @Test
+    public void testTraceSetWithExperiment() {
+        /* Test with a trace */
+        Set<ITmfTrace> expected = ImmutableSet.of(trace1);
+        Set<ITmfTrace> actual = TmfTraceManager.getTraceSetWithExperiment(trace1);
+        assertEquals(1, actual.size());
+        assertEquals(expected, actual);
+
+        /* Test with an experiment */
+        TmfExperiment exp = createExperiment(trace1, trace2);
+        expected = ImmutableSet.of(trace1, trace2, exp);
+        actual = TmfTraceManager.getTraceSetWithExperiment(exp);
+        assertEquals(3, actual.size());
+        assertEquals(expected, actual);
+    }
+
     /**
      * Test the {@link TmfTraceManager#getSupplementaryFileDir} method.
      */
index 23025d7d39986c7f48f6c148d9dd1a1e4b44c1e4..cfd666a0c7bbe598b5c09dc6c1eec967a81d4875 100644 (file)
@@ -207,7 +207,7 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer {
      * system entries if they do not exist yet.
      */
     private void updateEntriesList(List<ITmfTreeViewerEntry> entries, long timestamp) {
-        for (final ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
+        for (final ITmfTrace trace : TmfTraceManager.getTraceSetWithExperiment(getTrace())) {
             if (trace == null) {
                 continue;
             }
This page took 0.028701 seconds and 5 git commands to generate.