Add incremental indexing support Bug 380952
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / StreamInputPacketReader.java
index cc9f556b51f525b4e332aab9b00a19005217c049..50193e553cec1b02f50044347781a152e77d3ba4 100644 (file)
@@ -19,7 +19,6 @@ import java.util.HashMap;
 
 import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.types.Definition;
 import org.eclipse.linuxtools.ctf.core.event.types.EnumDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
@@ -27,6 +26,9 @@ import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
 import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
 
 /**
  * <b><u>StreamInputPacketReader</u></b>
@@ -92,6 +94,13 @@ public class StreamInputPacketReader implements IDefinitionScope {
      */
     private int currentCpu = 0;
 
+    /**
+     * number of lost events in this packet
+     */
+    private int lostEvents;
+
+    private int lostSoFar;
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -108,12 +117,15 @@ public class StreamInputPacketReader implements IDefinitionScope {
         /*
          * Set the BitBuffer's byte order.
          */
-        getBitBuffer().setByteOrder(streamInputReader.getStreamInput().getStream().getTrace().getByteOrder());
+        getBitBuffer().setByteOrder(streamInputReader.getByteOrder());
 
         /*
          * Create definitions needed to read the events.
          */
         createDefinitions();
+
+        lostEvents = 0 ;
+        lostSoFar = 0 ;
     }
 
     // ------------------------------------------------------------------------
@@ -248,10 +260,22 @@ public class StreamInputPacketReader implements IDefinitionScope {
              */
             if (getStreamPacketContextDef() != null) {
                 getStreamPacketContextDef().read(getBitBuffer());
+                /*
+                 * Read CPU ID
+                 */
+
                 Definition cpuiddef = getStreamPacketContextDef().lookupDefinition("cpu_id"); //$NON-NLS-1$
                 if (cpuiddef instanceof IntegerDefinition) {
                     currentCpu = (int) ((IntegerDefinition) cpuiddef).getValue();
                 }
+                /*
+                 * Read number of lost events
+                 */
+                Definition lostEventsdef = getStreamPacketContextDef().lookupDefinition("events_discarded"); //$NON-NLS-1$
+                if (cpuiddef instanceof IntegerDefinition) {
+                    lostEvents = (int) ((IntegerDefinition) lostEventsdef).getValue();
+                }
+
             }
 
             /*
@@ -287,20 +311,30 @@ public class StreamInputPacketReader implements IDefinitionScope {
      */
     public EventDefinition readNextEvent() throws CTFReaderException {
         /* WARNING: This is very LTTng-specific. */
-
         Long eventID = null;
         long timestamp = 0;
 
+
+        if( lostEvents > lostSoFar)
+        {
+            EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition(streamInputReader);
+            eventDef.setTimestamp(this.lastTimestamp);
+            ++lostSoFar;
+            return eventDef;
+        }
+        StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long variable name
+        BitBuffer currentBitBuffer = getBitBuffer();
         /*
-         * Read thestream event header.
+         * Read the stream event header.
          */
-        if (getStreamEventHeaderDef() != null) {
-            getStreamEventHeaderDef().read(getBitBuffer());
+
+        if (sehd != null) {
+            sehd.read(currentBitBuffer);
 
             /*
              * Check for an event id.
              */
-            EnumDefinition idEnumDef = (EnumDefinition) getStreamEventHeaderDef().lookupDefinition("id"); //$NON-NLS-1$
+            EnumDefinition idEnumDef = (EnumDefinition) sehd.lookupDefinition("id"); //$NON-NLS-1$
             assert (idEnumDef != null);
 
             eventID = idEnumDef.getIntegerValue();
@@ -308,7 +342,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
             /*
              * Check for the variant v.
              */
-            VariantDefinition variantDef = (VariantDefinition) getStreamEventHeaderDef().lookupDefinition("v"); //$NON-NLS-1$
+            VariantDefinition variantDef = (VariantDefinition) sehd.lookupDefinition("v"); //$NON-NLS-1$
             assert (variantDef != null);
 
             /*
@@ -324,7 +358,6 @@ public class StreamInputPacketReader implements IDefinitionScope {
             IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
             if (idIntegerDef != null) {
                 eventID = idIntegerDef.getValue();
-
             }
 
             /*
@@ -343,7 +376,7 @@ public class StreamInputPacketReader implements IDefinitionScope {
          * Read the stream event context.
          */
         if (getStreamEventContextDef() != null) {
-            getStreamEventContextDef().read(getBitBuffer());
+            getStreamEventContextDef().read(currentBitBuffer);
         }
 
         /*
@@ -357,22 +390,22 @@ public class StreamInputPacketReader implements IDefinitionScope {
         /*
          * Read the event context.
          */
-        if (eventDef.context != null) {
-            eventDef.context.read(getBitBuffer());
+        if (eventDef.getContext() != null) {
+            eventDef.getContext().read(currentBitBuffer);
         }
 
         /*
          * Read the event fields.
          */
-        if (eventDef.fields != null) {
-            eventDef.fields.read(getBitBuffer());
+        if (eventDef.getFields() != null) {
+            eventDef.getFields().read(currentBitBuffer);
         }
 
         /*
          * Set the event timestamp using the timestamp calculated by
          * updateTimestamp.
          */
-        eventDef.timestamp = timestamp;
+        eventDef.setTimestamp(timestamp);
 
         return eventDef;
     }
This page took 0.025649 seconds and 5 git commands to generate.