From 0f8687b43585770db3687eea96b5bdf021749fa3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Fri, 13 Jun 2014 15:19:25 -0400 Subject: [PATCH] TMF: Add utility method to return trace set, including experiment MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit And add the experiment state systems in the state system explorer Change-Id: I0470804d2057b25a778f04c195661d505fdaf7be Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/29394 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir --- .../tmf/core/trace/TmfTraceManager.java | 32 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 3 +- .../tracemanager/TmfTraceManagerTest.java | 22 +++++++++++++ .../statesystem/TmfStateSystemViewer.java | 2 +- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java index 4a617a2517..3536a0c669 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTraceManager.java @@ -15,8 +15,10 @@ 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 getTraceSetWithExperiment(ITmfTrace trace) { + if (trace == null) { + @SuppressWarnings("null") + @NonNull Set emptySet = Collections.EMPTY_SET; + return emptySet; + } + if (trace instanceof TmfExperiment) { + TmfExperiment exp = (TmfExperiment) trace; + ITmfTrace[] traces = exp.getTraces(); + Set alltraces = new LinkedHashSet<>(Arrays.asList(traces)); + alltraces.add(exp); + return alltraces; + } + @SuppressWarnings("null") + @NonNull Set 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 diff --git a/org.eclipse.linuxtools.tmf.ctf.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ctf.core.tests/META-INF/MANIFEST.MF index a17b351b6a..8ceaa20122 100644 --- a/org.eclipse.linuxtools.tmf.ctf.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ctf.core.tests/META-INF/MANIFEST.MF @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/tracemanager/TmfTraceManagerTest.java b/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/tracemanager/TmfTraceManagerTest.java index 7345d72e2e..68c994960c 100644 --- a/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/tracemanager/TmfTraceManagerTest.java +++ b/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/tracemanager/TmfTraceManagerTest.java @@ -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 expected = ImmutableSet.of(trace1); + Set 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. */ diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java index 23025d7d39..cfd666a0c7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statesystem/TmfStateSystemViewer.java @@ -207,7 +207,7 @@ public class TmfStateSystemViewer extends AbstractTmfTreeViewer { * system entries if they do not exist yet. */ private void updateEntriesList(List entries, long timestamp) { - for (final ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) { + for (final ITmfTrace trace : TmfTraceManager.getTraceSetWithExperiment(getTrace())) { if (trace == null) { continue; } -- 2.34.1