ctf: support traces with no content but a packet size
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 27 Nov 2013 22:18:54 +0000 (17:18 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 4 Dec 2013 02:02:39 +0000 (21:02 -0500)
Change-Id: I979e3826580db246263cfcb219ee7f9cba968922
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/19023
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
IP-Clean: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java

index b8bd2f9113ae4071c2ed5877afd987ccc97fe857..3ee9963ed4987193b7a89734b66a76b30ce58a2a 100644 (file)
@@ -35,6 +35,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr
  * <b><u>StreamInput</u></b>
  * <p>
  * Represents a trace file that belongs to a certain stream.
+ *
  * @since 2.0
  */
 public class StreamInput implements IDefinitionScope {
@@ -124,8 +125,7 @@ public class StreamInput implements IDefinitionScope {
     }
 
     /**
-     * Gets the filechannel of the streamInput. This is a limited Java
-     * resource.
+     * Gets the filechannel of the streamInput. This is a limited Java resource.
      *
      * @return the filechannel
      */
@@ -245,7 +245,10 @@ public class StreamInput implements IDefinitionScope {
             StructDefinition streamPacketContextDef, BitBuffer bitBuffer)
             throws CTFReaderException {
 
-        /* Ignoring the return value, but this call is needed to initialize the input */
+        /*
+         * Ignoring the return value, but this call is needed to initialize the
+         * input
+         */
         createPacketBitBuffer(fileSizeBytes, packetOffsetBytes, packetIndex, bitBuffer);
 
         /*
@@ -272,8 +275,7 @@ public class StreamInput implements IDefinitionScope {
 
         if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex
                 .getOffsetBytes()) * 8)) {
-            throw new CTFReaderException(
-                    "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+            throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
         }
 
         /*
@@ -383,8 +385,7 @@ public class StreamInput implements IDefinitionScope {
             long streamID = streamIDDef.getValue();
 
             if (streamID != getStream().getId()) {
-                throw new CTFReaderException(
-                        "Stream ID changing within a StreamInput"); //$NON-NLS-1$
+                throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$
             }
         }
     }
@@ -429,15 +430,18 @@ public class StreamInput implements IDefinitionScope {
         String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$
         // LTTng Specific
         Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$
-        Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded");  //$NON-NLS-1$
+        Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$
 
         /* Read the content size in bits */
         if (contentSize != null) {
             packetIndex.setContentSizeBits(contentSize.intValue());
+        } else if (packetSize != null) {
+            packetIndex.setContentSizeBits(packetSize.longValue());
         } else {
             packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
         }
 
+
         /* Read the packet size in bits */
         if (packetSize != null) {
             packetIndex.setPacketSizeBits(packetSize.intValue());
index 257cedf5d7328ee5ae94ee213974919094f92996..ca847195e612ffa251c27051d0d50eca152d1065 100644 (file)
@@ -223,11 +223,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
                                 this.currentPacket.getOffsetBytes(),
                                 (this.currentPacket.getPacketSizeBits() + 7) / 8);
             } catch (IOException e) {
-                /*
-                 * The streamInputReader object is already allocated, so this
-                 * shouldn't fail bar some very bad kernel or RAM errors...
-                 */
-                e.printStackTrace();
+                throw new CTFReaderException(e.getMessage(), e);
             }
 
             bitBuffer.setByteBuffer(bb);
@@ -318,7 +314,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
 
         final StructDefinition sehd = streamEventHeaderDef;
         final BitBuffer currentBitBuffer = bitBuffer;
-
+        final long posStart = currentBitBuffer.position();
         /* Read the stream event header. */
         if (sehd != null) {
             sehd.read(currentBitBuffer);
@@ -394,6 +390,10 @@ public class StreamInputPacketReader implements IDefinitionScope {
          */
         eventDef.setTimestamp(timestamp);
 
+        if (posStart == currentBitBuffer.position()) {
+            throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
+        }
+
         return eventDef;
     }
 
index c92c5d7f4a766fc8ecd06c5f31da6b1cb269d2c6..468ade788a14dc9fe30f3949958d596c3d475c97 100644 (file)
@@ -243,15 +243,10 @@ public class StreamInputReader {
         if (getPacketSize() >= (packetIndex + 1)) {
             this.packetReader.setCurrentPacket(getPacket());
         } else {
-            try {
-                if (this.streamInput.addPacketHeaderIndex()) {
-                    packetIndex = getPacketSize() - 1;
-                    this.packetReader.setCurrentPacket(getPacket());
-                } else {
-                    this.packetReader.setCurrentPacket(null);
-                }
-
-            } catch (CTFReaderException e) {
+            if (this.streamInput.addPacketHeaderIndex()) {
+                packetIndex = getPacketSize() - 1;
+                this.packetReader.setCurrentPacket(getPacket());
+            } else {
                 this.packetReader.setCurrentPacket(null);
             }
         }
@@ -298,8 +293,8 @@ public class StreamInputReader {
         /*
          * Advance until either of these conditions are met
          * <ul>
-         *   <li> reached the end of the trace file (the given timestamp is after the last event), </li>
-         *   <li> found the first event with a timestamp greater or equal the given timestamp. </li>
+         *  <li> reached the end of the trace file (the given timestamp is after the last event), </li>
+         *  <li> found the first event with a timestamp greater  or equal the given timestamp. </li>
          * </ul>
          */
         readNextEvent();
This page took 0.030508 seconds and 5 git commands to generate.