TMF: Add functions to verify if events are present in a CTF Trace
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 17 May 2013 20:11:33 +0000 (16:11 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 26 Jun 2013 20:17:56 +0000 (16:17 -0400)
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>

org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/ctfadaptor/CtfTmfTraceTest.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java

index 4eb16037e4b7486eb7b09ce86fe4805f1aab48ee..913e465d56ed6b2dcd37176ce58ea751feb3e533 100644 (file)
@@ -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));
+    }
 }
index 1cfa63b3c3e80e574608bb0585997daac9f98481..700b0a9d7d228c807e0bbe948349375249192527 100644 (file)
@@ -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
     // -------------------------------------------
This page took 0.03085 seconds and 5 git commands to generate.