CTF : Handle traces with events without eventID
authorJean-Christian Kouamé <kadjo.gwandy.jean-christian.kouame@ericsson.com>
Fri, 17 May 2013 16:04:01 +0000 (12:04 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 4 Jul 2013 22:44:18 +0000 (18:44 -0400)
Bug 387039 : First, the eventID was set to null when the event was
created. We change it for -2 as default value when not set. Then, we
must change the way to look for packetIndexEntry to adapt it to the
particular case where there are many packetIndexEntry with the same
timestamp.

Change-Id: Ia3bf16cc1013e41c18b5305978d1b99c30624bdc
Signed-off-by: Jean-Christian Kouame
Reviewed-on: https://git.eclipse.org/r/12949
Tested-by: Hudson CI
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java

index 774a95e8878a3b35fb1e0aacfac914effba7a447..4482aecb22556ea2d05d793d35aa62abefde5e7b 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 
 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration;
 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
 
 /**
@@ -243,9 +244,12 @@ public class Stream {
         if (events.get(event.getId()) != null) {
             throw new ParseException("Event id already exists"); //$NON-NLS-1$
         }
-
-        /* Put the event in the map */
-        events.put(event.getId(), event);
+        if (event.getId() == null) {
+            events.put(EventDeclaration.UNSET_EVENT_ID, event);
+        } else {
+            /* Put the event in the map */
+            events.put(event.getId(), event);
+        }
     }
 
     /**
index 9bd42b8b71f6482e867e84d688702c9ca091698d..678cb029a6b2763980f39bcf8990c17726f967c8 100644 (file)
@@ -286,7 +286,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
      */
     public EventDefinition readNextEvent() throws CTFReaderException {
         /* Default values for those fields */
-        long eventID = 0;
+        long eventID = EventDeclaration.UNSET_EVENT_ID;
         long timestamp = 0;
 
         if (lostEventsInThisPacket > lostSoFar) {
index 26b3c75d431ec5c36a18bd1a11054b8396304698..28f5c7e06a7ac881c0dfd1ca1d3c59f7b74c127b 100644 (file)
@@ -28,6 +28,12 @@ import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
  */
 public class EventDeclaration implements IEventDeclaration {
 
+    /** Id of lost events */
+    public static final long LOST_EVENT_ID = -1L;
+
+    /** Id of events when not set */
+    public static final long UNSET_EVENT_ID = -2L;
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -50,7 +56,7 @@ public class EventDeclaration implements IEventDeclaration {
     /**
      * Event id (can be null if only event in the stream).
      */
-    private Long id = null;
+    private Long id = UNSET_EVENT_ID;
 
     /**
      * Stream to which belongs this event.
@@ -100,7 +106,7 @@ public class EventDeclaration implements IEventDeclaration {
     public static synchronized EventDeclaration getLostEventDeclaration() {
         EventDeclaration lostEvent = new EventDeclaration();
         lostEvent.fields = new StructDeclaration(1);
-        lostEvent.id = -1L;
+        lostEvent.id = LOST_EVENT_ID;
         lostEvent.name = "Lost event"; //$NON-NLS-1$
         return lostEvent;
     }
@@ -218,7 +224,7 @@ public class EventDeclaration implements IEventDeclaration {
      * @return is the id set?
      */
     public boolean idIsSet() {
-        return id != null;
+        return (id != null && id != UNSET_EVENT_ID);
     }
 
     /**
index 14366d45472200f56f002e69dac0c5c76c095104..ef74805e138d21539618240d5dcfa78970d348df 100644 (file)
@@ -40,6 +40,7 @@ public class StreamInputPacketIndex {
 
     /**
      * Gets the entries
+     *
      * @return the entries
      */
     public Vector<StreamInputPacketIndexEntry> getEntries() {
@@ -48,6 +49,7 @@ public class StreamInputPacketIndex {
 
     /**
      * Gets an iterator to the entries
+     *
      * @return an iterator to the entries
      */
     public ListIterator<StreamInputPacketIndexEntry> listIterator() {
@@ -56,7 +58,9 @@ public class StreamInputPacketIndex {
 
     /**
      * Gets an iterator to the entries at a given position
-     * @param n the position to get
+     *
+     * @param n
+     *            the position to get
      * @return the iterator
      */
     public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
@@ -81,15 +85,13 @@ public class StreamInputPacketIndex {
         assert (entry.getContentSizeBits() != 0);
 
         if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
-            throw new CTFReaderException(
-                    "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
+            throw new CTFReaderException("Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
         }
 
         if (!this.entries.isEmpty()) {
             if (entry.getTimestampBegin() < this.entries.lastElement()
                     .getTimestampBegin()) {
-                throw new CTFReaderException(
-                        "Packets begin timestamp decreasing"); //$NON-NLS-1$
+                throw new CTFReaderException("Packets begin timestamp decreasing"); //$NON-NLS-1$
             }
         }
 
@@ -119,7 +121,7 @@ public class StreamInputPacketIndex {
         /*
          * If the index is empty, return the iterator at the very beginning.
          */
-        ifthis.getEntries().isEmpty()) {
+        if (this.getEntries().isEmpty()) {
             return this.getEntries().listIterator();
         }
 
@@ -151,12 +153,30 @@ public class StreamInputPacketIndex {
                  * the packet to return is before the guess.
                  */
                 max = guessI - 1;
-            } else if (timestamp >= guessEntry.getTimestampBegin()) {
+            } else if (timestamp > guessEntry.getTimestampBegin()) {
                 /*
                  * If the timestamp is after the begin timestamp, we know that
                  * the packet to return is after the guess or is the guess.
                  */
                 min = guessI;
+            } else if (timestamp == guessEntry.getTimestampBegin()) {
+                /*
+                 * If the timestamp is equal to the begin timestamp, we want to
+                 * return the first packetIndexEntry that have this timestamp.
+                 */
+                if (guessI > 0) {
+                    StreamInputPacketIndexEntry previousGuessEntry = this.entries.get(guessI - 1);
+                    while (guessI > 0 && guessEntry.getTimestampBegin() == previousGuessEntry.getTimestampBegin()) {
+                        guessEntry = previousGuessEntry;
+                        guessI--;
+                        if (guessI - 1 >= 0) {
+                            previousGuessEntry = this.entries.get(guessI - 1);
+                        }
+                    }
+                    min = guessI;
+                    max = guessI;
+                }
+
             }
         }
 
This page took 0.028939 seconds and 5 git commands to generate.