ctf: Attempt to gracefully recover from a malformed packet context
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 26 Jan 2016 11:15:28 +0000 (06:15 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 29 Jan 2016 02:07:01 +0000 (21:07 -0500)
If a packet context has an end time that is less than the start time
tracecompass will give an error message and refuse to read the trace.

This patch makes tracecompass log a warning instead and try to read
the trace.

Seeking should not be affected.

Bug 486670

Change-Id: I352af4c79476c73b0ced2cefd65f82bd04d6762d
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/65168
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Hudson CI
ctf/org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/trace/CTFStreamInputPacketIndexTest.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndex.java
ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/trace/StreamInputPacketIndexEntry.java

index 2d505fce3d14044f0e2c1bd4cfdbe87789aa597f..b826252ecc53cacff7b69c950b780821a533a099 100644 (file)
@@ -23,8 +23,7 @@ import org.junit.Test;
  * The class <code>StreamInputPacketIndexTest</code> contains tests for the
  * class <code>{@link StreamInputPacketIndex}</code>.
  *
- * @author ematkho
- * @version $Revision: 1.0 $
+ * @author Matthew Khouzam
  */
 @SuppressWarnings("javadoc")
 public class CTFStreamInputPacketIndexTest {
@@ -37,7 +36,7 @@ public class CTFStreamInputPacketIndexTest {
      * @throws CTFException
      */
     @Before
-    public void setUp() throws CTFException {
+    public void setUp() {
         fixture = new StreamInputPacketIndex();
         fixture.append(new StreamInputPacketIndexEntry(1L,0L));
     }
index 34cd54acbcdd5198483b15681350fde79082152e..91d31649aa622ec70482f1e9a41c2d8bf15688ea 100644 (file)
@@ -24,9 +24,10 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.TreeSet;
 
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.ctf.core.CTFException;
 import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
+import org.eclipse.tracecompass.internal.ctf.core.Activator;
 
 /**
  * <b><u>StreamInputPacketIndex</u></b>
@@ -75,12 +76,8 @@ public class StreamInputPacketIndex {
      *
      * @param preParsedIndex
      *            the pre-parsed index file
-     *
-     * @throws CTFException
-     *             If there was a problem reading the entry
      */
-    public void appendAll(Collection<ICTFPacketDescriptor> preParsedIndex)
-            throws CTFException {
+    public void appendAll(Collection<ICTFPacketDescriptor> preParsedIndex) {
         for (ICTFPacketDescriptor sipie : preParsedIndex) {
             append(checkNotNull(sipie));
         }
@@ -92,26 +89,25 @@ public class StreamInputPacketIndex {
      * @param entry
      *            element to be appended to this index, cannot be null
      * @return {@code true} (as specified by {@link Collection#add})
-     * @throws CTFException
-     *             If there was a problem reading the entry
      */
-    public synchronized boolean append(@NonNull ICTFPacketDescriptor entry)
-            throws CTFException {
-
+    public synchronized boolean append(@NonNull ICTFPacketDescriptor entry) {
+        ICTFPacketDescriptor entryToAdd = entry;
         /* Validate consistent entry. */
-        if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
-            throw new CTFException("Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
+        if (entryToAdd.getTimestampBegin() > entryToAdd.getTimestampEnd()) {
+            Activator.log(IStatus.WARNING, "Packet at offset " + entryToAdd.getOffsetBytes() + //$NON-NLS-1$
+                          " begin timestamp is after end timestamp"); //$NON-NLS-1$
+            entryToAdd = new StreamInputPacketIndexEntry(entryToAdd, Long.MAX_VALUE);
         }
 
         /*
          * Validate entries are inserted in monotonic increasing timestamp
          * order.
          */
-        if (!fEntries.isEmpty() && (entry.getTimestampBegin() < lastElement().getTimestampBegin())) {
+        if (!fEntries.isEmpty() && (entryToAdd.getTimestampBegin() < lastElement().getTimestampBegin())) {
             return false;
         }
 
-        fEntries.add(entry);
+        fEntries.add(entryToAdd);
         return true;
     }
 
@@ -127,9 +123,9 @@ public class StreamInputPacketIndex {
         /*
          * Search using binary search.
          *
-         * As the entries in fEntries are IndexEntries, the key to search for needs to be one too.
-         * We are looking for a timestamp though, so we use the dataOffset which is a long and use
-         * it as a timestamp holder.
+         * As the entries in fEntries are IndexEntries, the key to search for
+         * needs to be one too. We are looking for a timestamp though, so we use
+         * the dataOffset which is a long and use it as a timestamp holder.
          */
         int index = Collections.binarySearch(fEntries, new StreamInputPacketIndexEntry(timestamp, 0), new FindTimestamp());
         if (index < 0) {
@@ -177,12 +173,12 @@ public class StreamInputPacketIndex {
      *         contain the element
      * @throws ClassCastException
      *             if the type of the specified element is incompatible with
-     *             this data structure (<a
-     *             href="Collection.html#optional-restrictions">optional</a>)
+     *             this data structure (
+     *             <a href="Collection.html#optional-restrictions">optional</a>)
      * @throws NullPointerException
      *             if the specified element is null and this data structure does
-     *             not permit null elements (<a
-     *             href="Collection.html#optional-restrictions">optional</a>)
+     *             not permit null elements (
+     *             <a href="Collection.html#optional-restrictions">optional</a>)
      */
     public int indexOf(ICTFPacketDescriptor element) {
         int indexOf = -1;
@@ -235,11 +231,12 @@ public class StreamInputPacketIndex {
         @Override
         public int compare(ICTFPacketDescriptor value, ICTFPacketDescriptor key) {
             /*
-             * It is assumed that the second packet descriptor is the key, a wrapped timestamp in a
-             * PacketDescriptor. So we need to extract the timestamp. Then we have 3 choices, the
-             * if the timestamp is in the interval, we return 0 or found. If the timestamp is
-             * before or after, we just need to compare it to a value in the segment (like start) to
-             * know if it is greater or lesser to the current packet.
+             * It is assumed that the second packet descriptor is the key, a
+             * wrapped timestamp in a PacketDescriptor. So we need to extract
+             * the timestamp. Then we have 3 choices, the if the timestamp is in
+             * the interval, we return 0 or found. If the timestamp is before or
+             * after, we just need to compare it to a value in the segment (like
+             * start) to know if it is greater or lesser to the current packet.
              */
             long ts = key.getOffsetBits();
             if (value.includes(ts)) {
index bda26442b426f944d2750b7d392e2bfb44e63ce8..e92eba70d70f527da6076433148e5784e87043cb 100644 (file)
@@ -173,6 +173,33 @@ public class StreamInputPacketIndexEntry implements ICTFPacketDescriptor {
         fLostEvents = computeLostEvents(lostSoFar);
     }
 
+    /**
+     * Copy constructor that updates the timestamp end
+     *
+     * @param entryToAdd
+     *            the original {@link StreamInputPacketIndexEntry}
+     * @param newTimestampEnd
+     *            the new timestamp end
+     */
+    public StreamInputPacketIndexEntry(ICTFPacketDescriptor entryToAdd, long newTimestampEnd) {
+        fEndPacketHeaderBits = entryToAdd.getPayloadStartBits();
+        fAttributes = entryToAdd.getAttributes();
+        fContentSizeBits = entryToAdd.getContentSizeBits();
+        fPacketSizeBits = entryToAdd.getPacketSizeBits();
+        fTimestampBegin = entryToAdd.getTimestampBegin();
+        fTimestampEnd = newTimestampEnd;
+        fOffsetBits = entryToAdd.getOffsetBits();
+        fOffsetBytes = entryToAdd.getOffsetBits();
+
+        // LTTng Specific
+        fTarget = entryToAdd.getTarget();
+        fTargetID = entryToAdd.getTargetId();
+        Target target = new Target();
+        target.number = fTargetID;
+        target.string = fTarget;
+        fLostEvents = entryToAdd.getLostEvents();
+    }
+
     private static @NonNull Map<String, Object> computeAttributeMap(StructDefinition streamPacketContextDef) {
         Builder<String, Object> attributeBuilder = ImmutableMap.<String, Object> builder();
         for (String field : streamPacketContextDef.getDeclaration().getFieldsList()) {
This page took 0.029194 seconds and 5 git commands to generate.