From 409bea2046c7c88331a32222818733094446e1f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Wed, 5 Mar 2014 09:59:17 -0500 Subject: [PATCH] tmf: Add new interface to get pre-defined data types MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Matthew Khouzam Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/22937 Tested-by: Hudson CI --- .../core/event/matching/TcpEventMatching.java | 14 ++- .../event/matching/TcpLttngEventMatching.java | 16 +++- .../tests/event/TmfEventTypeManagerTest.java | 68 +++++-------- .../tmf/core/event/TmfEventTypeManager.java | 10 +- .../trace/ITmfTraceWithPreDefinedEvents.java | 59 ++++++++++++ .../trace/TmfEventTypeCollectionHelper.java | 48 ++++++++++ .../tmf/ctf/core/tests/CtfTmfTraceTest.java | 55 ++++++++--- .../META-INF/MANIFEST.MF | 2 + .../linuxtools/tmf/ctf/core/CtfTmfTrace.java | 95 ++++++++----------- 9 files changed, 249 insertions(+), 118 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceWithPreDefinedEvents.java create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfEventTypeCollectionHelper.java diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpEventMatching.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpEventMatching.java index dba8b31f43..339779b3ad 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpEventMatching.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpEventMatching.java @@ -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 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 traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes()); + traceEvents.retainAll(REQUIRED_EVENTS); + return !traceEvents.isEmpty(); } @Override diff --git a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpLttngEventMatching.java b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpLttngEventMatching.java index 0d6fe3573c..9c35b41a00 100644 --- a/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpLttngEventMatching.java +++ b/org.eclipse.linuxtools.lttng2.kernel.core/src/org/eclipse/linuxtools/lttng2/kernel/core/event/matching/TcpLttngEventMatching.java @@ -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 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 traceEvents = TmfEventTypeCollectionHelper.getEventNames(ktrace.getContainedEventTypes()); + traceEvents.retainAll(REQUIRED_EVENTS); + return !traceEvents.isEmpty(); } @Override diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java index 73c737df08..13bdc3c38f 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/event/TmfEventTypeManagerTest.java @@ -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 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 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 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 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); diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java index b2c3f8e0f6..4a6a5bc215 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/event/TmfEventTypeManager.java @@ -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 getTypes(final String context) { final HashMap 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 index 0000000000..093ccfffdc --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTraceWithPreDefinedEvents.java @@ -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 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 index 0000000000..72bfe18574 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfEventTypeCollectionHelper.java @@ -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 getEventNames(Iterable eventTypes) { + Set retSet = new HashSet<>(); + for (ITmfEventType eventType : eventTypes) { + retSet.add(eventType.getName()); + } + return retSet; + } +} diff --git a/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfTraceTest.java b/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfTraceTest.java index c8cd380ef3..6d2c204487 100644 --- a/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfTraceTest.java @@ -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 getEventType() method test. + * Test the {@link CtfTmfTrace#getEventType()} method. */ @Test public void testGetEventType() { - Class result = fixture.getEventType(); + Class result = fixture.getEventType(); + assertNotNull(result); + assertEquals(CtfTmfEvent.class, result); + } + + /** + * Run the Class getContainedEventTypes() method test. + */ + @Test + public void testGetContainedEventTypes() { + Set 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 eventTypes = fixture.getContainedEventTypes(); + Set 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 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))); } /** diff --git a/org.eclipse.linuxtools.tmf.ctf.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ctf.core/META-INF/MANIFEST.MF index eb52863000..459474b70f 100644 --- a/org.eclipse.linuxtools.tmf.ctf.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ctf.core/META-INF/MANIFEST.MF @@ -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 diff --git a/org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfTrace.java index f23a0690d1..8d7ecac771 100644 --- a/org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.ctf.core/src/org/eclipse/linuxtools/tmf/ctf/core/CtfTmfTrace.java @@ -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 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 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 getContainedEventTypes() { + TmfEventTypeManager instance = TmfEventTypeManager.getInstance(); + Set eventTypes = instance.getTypes(CtfTmfEventType.computeContextName(this)); + return ImmutableSet.copyOf(eventTypes); } // ------------------------------------------- -- 2.34.1