aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeneviève Bastien2013-05-17 16:11:33 (EDT)
committerAlexandre Montplaisir2013-06-26 16:17:56 (EDT)
commit5d2b64c8a3de3ee58f363cd51db26c739b8f455a (patch)
tree74e5986852a9e3ccf66c0f4b8f0bededfc621603
parent0a73ff18a683a73d6a89e12054747bdb79745892 (diff)
downloadorg.eclipse.linuxtools-5d2b64c8a3de3ee58f363cd51db26c739b8f455a.zip
org.eclipse.linuxtools-5d2b64c8a3de3ee58f363cd51db26c739b8f455a.tar.gz
org.eclipse.linuxtools-5d2b64c8a3de3ee58f363cd51db26c739b8f455a.tar.bz2
TMF: Add functions to verify if events are present in a CTF Tracerefs/changes/52/12952/6
These functions verify whether one, some or all events are present in the metadata of a CTF trace. It is useful to verify the presence of events before doing an analysis that requires them. Change-Id: Ieed7f9bcd905bf354aa5550b10c6304e534e5728 Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net> Reviewed-on: https://git.eclipse.org/r/12952 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im> IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java16
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java60
2 files changed, 75 insertions, 1 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
index 4eb1603..913e465 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
@@ -14,6 +14,7 @@
package org.eclipse.linuxtools.tmf.core.tests.ctfadaptor;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -348,4 +349,19 @@ public class CtfTmfTraceTest {
IStatus result = fixture.validate(project, path);
assertTrue(result.isOK());
}
+
+ /**
+ * Run the boolean hasEvent(final String) method test
+ */
+ @Test
+ public void testEventLookup() {
+ assertTrue(fixture.hasEvent("sched_switch"));
+ assertFalse(fixture.hasEvent("Sched_switch"));
+ String[] events = { "sched_switch", "sched_wakeup", "timer_init" };
+ assertTrue(fixture.hasAllEvents(events));
+ assertTrue(fixture.hasAtLeastOneOfEvents(events));
+ String[] names = { "inexistent", "sched_switch", "SomeThing" };
+ assertTrue(fixture.hasAtLeastOneOfEvents(names));
+ assertFalse(fixture.hasAllEvents(names));
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
index 1cfa63b..700b0a9 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java
@@ -20,6 +20,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
@@ -29,9 +30,9 @@ 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.ITmfTraceProperties;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTraceProperties;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
/**
@@ -307,6 +308,63 @@ public class CtfTmfTrace extends TmfTrace
return 0;
}
+ /**
+ * 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
+ *
+ * @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
+ */
+ public boolean hasAtLeastOneOfEvents(String[] names) {
+ for (String name : names) {
+ if (hasEvent(name)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
// -------------------------------------------
// Parser
// -------------------------------------------