Fix ranks in CtfTmfTrace as part of bug #389051
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfTrace.java
index 4976ea570a3a633064315918e3edbfacdebc24e9..be3f94d45792899f06e4a2e407a6d41bccbd3b9c 100644 (file)
@@ -23,7 +23,6 @@ import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp.TimestampType;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
 import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
 import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
@@ -32,11 +31,19 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
 
 public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParser<CtfTmfEvent>{
 
+    //-------------------------------------------
+    //        Constants
+    //-------------------------------------------
+    /**
+     * Default cache size for CTF traces
+     */
+    protected static final int DEFAULT_CACHE_SIZE = 50000;
+    
     //-------------------------------------------
     //        Fields
     //-------------------------------------------
 
-    /* Reference to the state system assigned to this trace */
+    /** Reference to the state system assigned to this trace */
     protected IStateSystemQuerier ss = null;
 
     /* Reference to the CTF Trace */
@@ -56,9 +63,15 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
     @Override
     public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
             throws TmfTraceException {
+        /*
+         * Set the cache size. This has to be done before the call to super()
+         * because the super needs to know the cache size.
+         */
+        setCacheSize();
         super.initTrace(resource, path, eventType);
         EventDeclaration ed;
         ITmfEventField eventField;
+
         @SuppressWarnings("unused")
         CtfTmfEventType type;
 
@@ -81,12 +94,6 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
                 this.setStartTime(TmfTimestamp.BIG_BANG);
             } else {
                 this.setStartTime(iterator.getCurrentEvent().getTimestamp());
-                /*
-                 * is the trace empty
-                 */
-                if( iterator.hasMoreEvents()){
-                    iterator.goToLastEvent();
-                }
                 this.setEndTime(iterator.getCurrentEvent().getTimestamp());
             }
 
@@ -99,7 +106,6 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
             throw new TmfTraceException(e.getMessage(), e);
         }
 
-        TmfSignalManager.register(this);
         //FIXME This should be called via the ExperimentUpdated signal
         buildStateSystem();
 
@@ -162,16 +168,22 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
     @Override
     public ITmfContext seekEvent(final ITmfLocation<?> location) {
         CtfLocation currentLocation = (CtfLocation) location;
+        CtfIterator context = new CtfIterator(this);
+        /*
+         * The rank is set to 0 if the iterator seeks the beginning. If not, it
+         * will be set to UNKNOWN_RANK, since CTF traces don't support seeking
+         * by rank for now.
+         */
         if (currentLocation == null) {
             currentLocation = new CtfLocation(0L);
+            context.setRank(0);
         }
-        CtfIterator context = new CtfIterator(this);
-
         if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) {
             ((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS);
             currentLocation.setLocation(getEndTime().getValue() + 1);
         }
         context.setLocation(currentLocation);
+        if(context.getRank() != 0)
         context.setRank(ITmfContext.UNKNOWN_RANK);
         return context;
     }
@@ -197,8 +209,14 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
         if (context instanceof CtfIterator) {
             CtfIterator ctfIterator = (CtfIterator) context;
             event = ctfIterator.getCurrentEvent();
-            ctfIterator.advance();
+
+            if (event != null) {
+                updateAttributes(context, event.getTimestamp());
+                ctfIterator.advance();
+                ctfIterator.increaseRank();
+            }
         }
+
         return event;
     }
 
@@ -302,5 +320,12 @@ public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParse
         }
         return event;
     }
+    
+    /**
+     * Sets the cache size for a CtfTmfTrace. 
+     */
+    protected void setCacheSize() {
+        setCacheSize(DEFAULT_CACHE_SIZE);
+    }
 
 }
This page took 0.030989 seconds and 5 git commands to generate.