tmf: Add new interface to get pre-defined data types
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 5 Mar 2014 14:59:17 +0000 (09:59 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 13 May 2014 19:00:50 +0000 (15:00 -0400)
This way, other trace classes may implement this interface and be
queried on the events it might contain. This will be useful for analyses
who can query traces to know whether or not they might contain the
events it needs to execute.

This can be used by many traces. The TmfEventTypeCollectionHelper
class should help extract useful information from the set of events.
At least until Java 8 comes out.

Change-Id: I1758c0d99b2b4d4b91f5b7fa3ee14b82c325dede
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/22937
Tested-by: Hudson CI
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpEventMatching.java
org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpLttngEventMatching.java
org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceWithPreDefinedEvents.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfEventTypeCollectionHelper.java [new file with mode: 0644]
org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.ctf.core/META-INF/MANIFEST.MF
org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfTrace.java

index dba8b31f434283504f81f28ea5bfb5f345f813e6..339779b3ade11c10be6f7e103824e5cd39c48363 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.lttng2.kernel.core.event.matching;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.TcpEventStrings;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
@@ -22,8 +23,11 @@ import org.eclipse.linuxtools.tmf.core.event.matching.ITmfNetworkMatchDefinition
 import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching.MatchingType;
 import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfEventTypeCollectionHelper;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * Class to match tcp type events. This matching class applies to traces
  * obtained with the 'addons' lttng module. This module can be obtained with
@@ -38,6 +42,10 @@ import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
  */
 public class TcpEventMatching implements ITmfNetworkMatchDefinition {
 
+    private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of(
+            TcpEventStrings.INET_SOCK_LOCAL_IN,
+            TcpEventStrings.INET_SOCK_LOCAL_OUT);
+
     private static boolean canMatchPacket(final ITmfEvent event) {
         /* Make sure all required fields are present to match with this event */
         ITmfEventField content = event.getContent();
@@ -90,8 +98,10 @@ public class TcpEventMatching implements ITmfNetworkMatchDefinition {
             return false;
         }
         CtfTmfTrace ktrace = (CtfTmfTrace) trace;
-        String[] events = { TcpEventStrings.INET_SOCK_LOCAL_IN, TcpEventStrings.INET_SOCK_LOCAL_OUT };
-        return ktrace.hasAtLeastOneOfEvents(events);
+
+        Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes());
+        traceEvents.retainAll(REQUIRED_EVENTS);
+        return !traceEvents.isEmpty();
     }
 
     @Override
index 0d6fe3573c24a2211f76af69a8d155e77945a7b6..9c35b41a0067716173e2dd1c26de576402d28ceb 100644 (file)
@@ -14,17 +14,21 @@ package org.eclipse.linuxtools.lttng2.kernel.core.event.matching;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import org.eclipse.linuxtools.internal.lttng2.kernel.core.TcpEventStrings;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.matching.ITmfNetworkMatchDefinition;
 import org.eclipse.linuxtools.tmf.core.event.matching.TmfEventMatching.MatchingType;
 import org.eclipse.linuxtools.tmf.core.event.matching.TmfNetworkEventMatching.Direction;
-import org.eclipse.linuxtools.tmf.core.event.matching.ITmfNetworkMatchDefinition;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.linuxtools.tmf.core.trace.TmfEventTypeCollectionHelper;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * Class to match tcp type events. This class applies to traces obtained with
  * the full network tracepoint data available from an experimental branch of
@@ -42,6 +46,10 @@ public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition {
     private static final String[] key_ackseq = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.ACKSEQ };
     private static final String[] key_flags = { TcpEventStrings.TRANSPORT_FIELDS, TcpEventStrings.TYPE_TCP, TcpEventStrings.FLAGS };
 
+    private static final ImmutableSet<String> REQUIRED_EVENTS = ImmutableSet.of(
+            TcpEventStrings.NET_DEV_QUEUE,
+            TcpEventStrings.NETIF_RECEIVE_SKB);
+
     private static boolean canMatchPacket(final ITmfEvent event) {
         TmfEventField field = (TmfEventField) event.getContent();
 
@@ -90,8 +98,10 @@ public class TcpLttngEventMatching implements ITmfNetworkMatchDefinition {
             return false;
         }
         CtfTmfTrace ktrace = (CtfTmfTrace) trace;
-        String[] events = { TcpEventStrings.NET_DEV_QUEUE, TcpEventStrings.NETIF_RECEIVE_SKB };
-        return (ktrace.hasAtLeastOneOfEvents(events));
+
+        Set<String> traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes());
+        traceEvents.retainAll(REQUIRED_EVENTS);
+        return !traceEvents.isEmpty();
     }
 
     @Override
index 73c737df0873ef661030553a208aaec33b34915a..13bdc3c38fa8c6c86d5bf64e6459a517146618e1 100644 (file)
@@ -17,8 +17,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 import java.util.Arrays;
+import java.util.Set;
 
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
 import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
@@ -86,23 +88,15 @@ public class TmfEventTypeManagerTest {
         fInstance.add(fContext2, fType2);
         fInstance.add(fContext2, fType3);
 
-        ITmfEventType[] types = fInstance.getTypes(fContext1);
-        assertEquals("getTypes", 2, types.length);
-        if (fType0 == types[0]) {
-            assertSame("getTypes", fType1, types[1]);
-        } else {
-            assertSame("getTypes", fType0, types[1]);
-            assertSame("getTypes", fType1, types[0]);
-        }
+        Set<ITmfEventType> types = fInstance.getTypes(fContext1);
+        assertEquals("getTypes", 2, types.size());
+        assertTrue(types.contains(fType1));
+        assertTrue(types.contains(fType0));
 
         types = fInstance.getTypes(fContext2);
-        assertEquals("getTypes", 2, types.length);
-        if (fType2 == types[0]) {
-            assertSame("getTypes", fType3, types[1]);
-        } else {
-            assertSame("getTypes", fType2, types[1]);
-            assertSame("getTypes", fType3, types[0]);
-        }
+        assertEquals("getTypes", 2, types.size());
+        assertTrue(types.contains(fType2));
+        assertTrue(types.contains(fType3));
     }
 
     @Test
@@ -140,7 +134,7 @@ public class TmfEventTypeManagerTest {
     public void testClear() {
         fInstance.clear();
         assertEquals("clear", 0, fInstance.getContexts().length);
-        assertEquals("clear", 0, fInstance.getTypes(null).length);
+        assertEquals("clear", 0, fInstance.getTypes(null).size());
         assertNull("clear", fInstance.getType(null, null));
         assertEquals("clear", "TmfEventTypeManager [fEventTypes={}]", fInstance.toString());
     }
@@ -159,8 +153,8 @@ public class TmfEventTypeManagerTest {
         assertEquals("clear context", 1, contexts.length);
         assertEquals("clear context", fContext2, contexts[0]);
 
-        ITmfEventType[] types = fInstance.getTypes(fContext1);
-        assertEquals("clear context", 0, types.length);
+        Set<ITmfEventType> types = fInstance.getTypes(fContext1);
+        assertEquals("clear context", 0, types.size());
 
         ITmfEventType type = fInstance.getType(fContext1, fType0.getName());
         assertNull("clear context", type);
@@ -168,13 +162,9 @@ public class TmfEventTypeManagerTest {
         assertNull("clear context", type);
 
         types = fInstance.getTypes(fContext2);
-        assertEquals("clear context", 2, types.length);
-        if (fType2 == types[0]) {
-            assertSame("clear context", fType3, types[1]);
-        } else {
-            assertSame("clear context", fType2, types[1]);
-            assertSame("clear context", fType3, types[0]);
-        }
+        assertEquals("clear context", 2, types.size());
+        assertTrue(types.contains(fType2));
+        assertTrue(types.contains(fType3));
     }
 
     @Test
@@ -186,9 +176,9 @@ public class TmfEventTypeManagerTest {
         assertEquals("add", 1, contexts.length);
         assertEquals("add", fContext1, contexts[0]);
 
-        final ITmfEventType[] types = fInstance.getTypes(contexts[0]);
-        assertEquals("add", 1, types.length);
-        assertSame("add", fType0, types[0]);
+        final Set<ITmfEventType> types = fInstance.getTypes(contexts[0]);
+        assertEquals("add", 1, types.size());
+        assertTrue(types.contains(fType0));
 
         ITmfEventType type = fInstance.getType(contexts[0], fType0.getName());
         assertSame("add", fType0, type);
@@ -211,23 +201,15 @@ public class TmfEventTypeManagerTest {
         assertEquals("add", fContext1, contexts[0]);
         assertEquals("add", fContext2, contexts[1]);
 
-        ITmfEventType[] types = fInstance.getTypes(fContext1);
-        assertEquals("add", 2, types.length);
-        if (fType0 == types[0]) {
-            assertSame("add", fType1, types[1]);
-        } else {
-            assertSame("add", fType0, types[1]);
-            assertSame("add", fType1, types[0]);
-        }
+        Set<ITmfEventType> types = fInstance.getTypes(fContext1);
+        assertEquals("add", 2, types.size());
+        assertTrue(types.contains(fType0));
+        assertTrue(types.contains(fType1));
 
         types = fInstance.getTypes(fContext2);
-        assertEquals("add", 2, types.length);
-        if (fType2 == types[0]) {
-            assertSame("add", fType3, types[1]);
-        } else {
-            assertSame("add", fType2, types[1]);
-            assertSame("add", fType3, types[0]);
-        }
+        assertEquals("add", 2, types.size());
+        assertTrue(types.contains(fType2));
+        assertTrue(types.contains(fType3));
 
         ITmfEventType type = fInstance.getType(fContext1, fType0.getName());
         assertSame("add", fType0, type);
index b2c3f8e0f6d03cca6e0f3f3047bfa2d58e9bd4d7..4a6a5bc2156be3219c77543b3a48d94f6e44b50a 100644 (file)
@@ -14,6 +14,9 @@ package org.eclipse.linuxtools.tmf.core.event;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+
+import com.google.common.collect.ImmutableSet;
 
 /**
  * A central repository for the available event types. Types are managed by
@@ -90,13 +93,14 @@ public final class TmfEventTypeManager {
      *
      * @param context the context to look into
      * @return the list of types defined for that context
+     * @since 3.0
      */
-    public synchronized ITmfEventType[] getTypes(final String context) {
+    public synchronized Set<ITmfEventType> getTypes(final String context) {
         final HashMap<String, ITmfEventType> types = fEventTypes.get(context);
         if (types != null) {
-            return types.values().toArray(new ITmfEventType[types.size()]);
+            return ImmutableSet.copyOf(types.values());
         }
-        return new ITmfEventType[0];
+        return ImmutableSet.of();
     }
 
     /**
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceWithPreDefinedEvents.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceWithPreDefinedEvents.java
new file mode 100644 (file)
index 0000000..093ccff
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2014 École Polytechnique de Montréal, Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Geneviève Bastien - Initial API and implementation
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace;
+
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+
+/**
+ * This interface should be implemented by all trace classes who have a way to
+ * know in advance what events it may contain. It allows analyses and other
+ * external components to ask the list of events for the trace might contain.
+ *
+ * The methods from this interface will typically be called to determine whether
+ * or not it is worth reading a trace. If we can know in advance that a trace
+ * does not contain the events required by an analysis, then the analysis will
+ * not be run. So the response should not involve having to actually read the
+ * trace.
+ *
+ * @author Geneviève Bastien
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public interface ITmfTraceWithPreDefinedEvents {
+
+    /**
+     * Return a set of event types declared in the trace, without actually
+     * reading the trace. This method can be called before reading a trace but
+     * after it is initialized, in order to compare this set with a set of
+     * events that a request handles, to determine whether or not it is worth
+     * reading the trace.
+     *
+     * Some trace types have ways to determine the events that were traced
+     * without having to read the whole trace and this is what this method will
+     * query. The presence of an event in the returned set does not guarantee
+     * that an event with this name actually happened during this trace, only
+     * that it can be there.
+     *
+     * The set should be immutable. Destructive set operations should be
+     * performed on a copy of this set.A helper class
+     * {@link TmfEventTypeCollectionHelper} will provide ways of working with
+     * this data structure.
+     *
+     * @return The set of events that might be present in the trace
+     */
+    Set<ITmfEventType> getContainedEventTypes();
+
+}
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfEventTypeCollectionHelper.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfEventTypeCollectionHelper.java
new file mode 100644 (file)
index 0000000..72bfe18
--- /dev/null
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.core.trace;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+
+/**
+ * Set Helper for sets of ITmfTraceType
+ *
+ * TODO Remove once Java 8 is used (replace with Streams)
+ *
+ * @author Matthew Khouzam
+ * @since 3.0
+ */
+public final class TmfEventTypeCollectionHelper {
+
+    private TmfEventTypeCollectionHelper() {
+    }
+
+    /**
+     * Gets the event names from a collection of event types
+     *
+     * @param eventTypes
+     *            an iterable collection of ITmfEventTypes
+     * @return a set of the names of these events, if some names are clashing
+     *         they will only appear once
+     */
+    public static Set<String> getEventNames(Iterable<ITmfEventType> eventTypes) {
+        Set<String> retSet = new HashSet<>();
+        for (ITmfEventType eventType : eventTypes) {
+            retSet.add(eventType.getName());
+        }
+        return retSet;
+    }
+}
index c8cd380ef3a983ac2af248feebc7e689a42fd7bf..6d2c204487a6b8a6c3511474a586a6ce617a8719 100644 (file)
@@ -20,10 +20,14 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeTrue;
 
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
-import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.signal.TmfEndSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignal;
@@ -31,6 +35,7 @@ import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.TmfEventTypeCollectionHelper;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfLocation;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfLocationInfo;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
@@ -84,7 +89,6 @@ public class CtfTmfTraceTest {
     public void testCtfTmfTrace() {
         try (CtfTmfTrace result = new CtfTmfTrace();) {
             assertNotNull(result);
-            assertNull(result.getEventType());
             assertEquals(1000, result.getCacheSize());
             assertEquals(0L, result.getNbEvents());
             assertEquals(0L, result.getStreamingInterval());
@@ -113,6 +117,15 @@ public class CtfTmfTraceTest {
         fixture.broadcast(signal);
     }
 
+    /**
+     * Run the void dispose() method test.
+     */
+    @Test
+    public void testClose() {
+        try (CtfTmfTrace emptyFixture = new CtfTmfTrace();) {
+        }
+    }
+
     /**
      * Run the int getCacheSize() method test.
      */
@@ -147,13 +160,12 @@ public class CtfTmfTraceTest {
      * Test the seekEvent() method with a location from a timestamp.
      */
     @Test
-    public void testSeekEventLoc_timetamp(){
+    public void testSeekEventLoc_timetamp() {
         CtfLocation loc = new CtfLocation(new CtfTmfTimestamp(0L));
         fixture.seekEvent(loc);
         assertNotNull(fixture);
     }
 
-
     /**
      * Run the ITmfTimestamp getEndTime() method test.
      */
@@ -170,16 +182,27 @@ public class CtfTmfTraceTest {
     public void testGetEnvValue() {
         String key = "tracer_name";
         String result = fixture.getTraceProperties().get(key);
-        assertEquals("\"lttng-modules\"",result);
+        assertEquals("\"lttng-modules\"", result);
     }
 
     /**
-     * Run the Class<CtfTmfEvent> getEventType() method test.
+     * Test the {@link CtfTmfTrace#getEventType()} method.
      */
     @Test
     public void testGetEventType() {
-        Class<? extends ITmfEvent> result = fixture.getEventType();
+        Class<?> result = fixture.getEventType();
+        assertNotNull(result);
+        assertEquals(CtfTmfEvent.class, result);
+    }
+
+    /**
+     * Run the Class<CtfTmfEvent> getContainedEventTypes() method test.
+     */
+    @Test
+    public void testGetContainedEventTypes() {
+        Set<ITmfEventType> result = fixture.getContainedEventTypes();
         assertNotNull(result);
+        assertFalse(result.isEmpty());
     }
 
     /**
@@ -342,14 +365,20 @@ public class CtfTmfTraceTest {
      */
     @Test
     public void testEventLookup() {
-        assertTrue(fixture.hasEvent("sched_switch"));
-        assertFalse(fixture.hasEvent("Sched_switch"));
+        Set<ITmfEventType> eventTypes = fixture.getContainedEventTypes();
+        Set<String> eventNames = TmfEventTypeCollectionHelper.getEventNames(eventTypes);
+        assertTrue(eventNames.contains("sched_switch"));
+        assertFalse(eventNames.contains("Sched_switch"));
         String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
-        assertTrue(fixture.hasAllEvents(events));
-        assertTrue(fixture.hasAtLeastOneOfEvents(events));
+        assertTrue(eventNames.containsAll(Arrays.asList(events)));
+        Set<String> copy = new HashSet<>(eventNames);
+        copy.retainAll(Arrays.asList(events));
+        assertFalse(copy.isEmpty());
         String[] names = { "inexistent", "sched_switch", "SomeThing" };
-        assertTrue(fixture.hasAtLeastOneOfEvents(names));
-        assertFalse(fixture.hasAllEvents(names));
+        copy = new HashSet<>(eventNames);
+        copy.retainAll(Arrays.asList(names));
+        assertTrue(!copy.isEmpty());
+        assertFalse(eventNames.containsAll(Arrays.asList(names)));
     }
 
     /**
index eb52863000c8bf9ec34c29b330cf60660af9d1d2..459474b70f49e7c9cc832d29a50e8bb432510ba8 100644 (file)
@@ -14,3 +14,5 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.linuxtools.tmf.core;bundle-version="3.0.0"
 Export-Package: org.eclipse.linuxtools.internal.tmf.ctf.core;x-internal:=true,
  org.eclipse.linuxtools.tmf.ctf.core
+Import-Package: com.google.common.collect,
+ org.eclipse.emf.common.util
index f23a0690d1efbb348fa935a91995556ca7a4ba9e..8d7ecac771dc3cb61f9645dce7db0ba2ae763b91 100644 (file)
@@ -16,7 +16,10 @@ package org.eclipse.linuxtools.tmf.ctf.core;
 
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
@@ -29,12 +32,17 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
 import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
 import org.eclipse.linuxtools.internal.tmf.ctf.core.Activator;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventField;
+import org.eclipse.linuxtools.tmf.core.event.TmfEventTypeManager;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceWithPreDefinedEvents;
 import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfPersistentlyIndexable;
@@ -44,6 +52,8 @@ import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.ITmfCheckpoint;
 import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpoint;
 import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
 
+import com.google.common.collect.ImmutableSet;
+
 /**
  * The CTf trace handler
  *
@@ -52,7 +62,7 @@ import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
  */
 public class CtfTmfTrace extends TmfTrace
         implements ITmfEventParser, ITmfTraceProperties, ITmfPersistentlyIndexable,
-        AutoCloseable {
+        ITmfTraceWithPreDefinedEvents, AutoCloseable {
 
     // -------------------------------------------
     // Constants
@@ -116,7 +126,29 @@ public class CtfTmfTrace extends TmfTrace
                 this.setStartTime(curTime);
                 this.setEndTime(curTime);
             }
-
+            /*
+             * Register every event type. When you call getType, it will
+             * register a trace to that type in the TmfEventTypeManager
+             */
+            try (CtfIterator iter = CtfIteratorManager.getIterator(this, ctx)) {
+                for (IEventDeclaration ied : iter.getEventDeclarations()) {
+                    CtfTmfEventType ctfTmfEventType = CtfTmfEventType.get(this, ied.getName());
+                    if (ctfTmfEventType == null) {
+                        List<ITmfEventField> content = new ArrayList<>();
+                        /* Should only return null the first time */
+                        for (String fieldName : ied.getFields().getFieldsList()) {
+                            content.add(new TmfEventField(fieldName, null, null));
+                        }
+                        ITmfEventField contentTree = new TmfEventField(
+                                ITmfEventField.ROOT_FIELD_ID,
+                                null,
+                                content.toArray(new ITmfEventField[content.size()])
+                                );
+
+                        ctfTmfEventType = new CtfTmfEventType(ied.getName(), this, contentTree);
+                    }
+                }
+            }
         } catch (final CTFReaderException e) {
             /*
              * If it failed at the init(), we can assume it's because the file
@@ -348,60 +380,15 @@ public class CtfTmfTrace extends TmfTrace
     }
 
     /**
-     * Returns whether or not an event is in the metadata of the trace,
-     * therefore if it can possibly be in the trace. It does not verify whether
-     * or not the event is actually in the trace
-     *
-     * @param eventName
-     *            The name of the event to check
-     * @return Whether the event is in the metadata or not
-     * @since 2.1
-     */
-    public boolean hasEvent(final String eventName) {
-        Map<Long, IEventDeclaration> events = fTrace.getEvents(0L);
-        if (events != null) {
-            for (IEventDeclaration decl : events.values()) {
-                if (decl.getName().equals(eventName)) {
-                    return true;
-                }
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Return whether all requested events are in the metadata
+     * Gets the list of declared events
      *
-     * @param names
-     *            The array of events to check for
-     * @return Whether all events are in the metadata
-     * @since 2.1
-     */
-    public boolean hasAllEvents(String[] names) {
-        for (String name : names) {
-            if (!hasEvent(name)) {
-                return false;
-            }
-        }
-        return true;
-    }
-
-    /**
-     * Returns whether the metadata contains at least one of the requested
-     * events
-     *
-     * @param names
-     *            The array of event names of check for
-     * @return Whether one of the event is present in trace metadata
-     * @since 2.1
+     * @since 3.0
      */
-    public boolean hasAtLeastOneOfEvents(String[] names) {
-        for (String name : names) {
-            if (hasEvent(name)) {
-                return true;
-            }
-        }
-        return false;
+    @Override
+    public Set<ITmfEventType> getContainedEventTypes() {
+        TmfEventTypeManager instance = TmfEventTypeManager.getInstance();
+        Set<ITmfEventType> eventTypes = instance.getTypes(CtfTmfEventType.computeContextName(this));
+        return ImmutableSet.copyOf(eventTypes);
     }
 
     // -------------------------------------------
This page took 0.044676 seconds and 5 git commands to generate.