Contribution for Bug353020
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / trace / StateTraceManager.java
index 64cdddca531c8abea66a344cdc3f224ff8144eb4..9679f0c1f1773f3fde3f2624465afe18032e1647 100644 (file)
@@ -194,9 +194,9 @@ public class StateTraceManager extends LTTngTreeNode implements IStateTraceManag
         */
        @Override
        @SuppressWarnings("unchecked")
-       public TmfTimestamp restoreCheckPointByTimestamp(TmfTimestamp eventTime) {
+       public TmfCheckpoint restoreCheckPointByTimestamp(TmfTimestamp eventTime) {
                TmfTimeRange experimentRange = fExperiment.getTimeRange();
-               TmfTimestamp nearestTimeStamp = fTrace.getStartTime();
+               TmfCheckpoint checkpoint = new TmfCheckpoint(fTrace.getStartTime(), new TmfLocation<Long>(0L));
 
                // The GUI can have time limits higher than this log, since GUI can
                // handle multiple logs
@@ -229,8 +229,7 @@ public class StateTraceManager extends LTTngTreeNode implements IStateTraceManag
                    } else {
 
                        // Useful CheckPoint found
-                       TmfCheckpoint checkpoint = timestampCheckpointsList.get(index);
-                       nearestTimeStamp = checkpoint.getTimestamp();
+                       checkpoint = timestampCheckpointsList.get(index);
                        // get the location associated with the checkpoint
                        TmfLocation<Long> location = (TmfLocation<Long>) checkpoint.getLocation();
                        // reference a new copy of the checkpoint template
@@ -244,7 +243,49 @@ public class StateTraceManager extends LTTngTreeNode implements IStateTraceManag
                        fStateModel = traceState;
                }
 
-               return nearestTimeStamp;
+               return checkpoint;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.linuxtools.lttng.state.trace.IStateTraceManager#restoreCheckPointByIndex(long)
+        */
+       @Override
+       public TmfCheckpoint restoreCheckPointByIndex(long eventIndex) {
+               TmfCheckpoint checkpoint = new TmfCheckpoint(fTrace.getStartTime(), new TmfLocation<Long>(0L));
+
+           LttngTraceState traceState;
+               synchronized (fCheckPointsLock) {
+                   Collections.sort(timestampCheckpointsList);
+                   // Initiate the compare with a checkpoint containing the target time
+                   // stamp to find
+                   int index = Collections.binarySearch(timestampCheckpointsList, new TmfCheckpoint(null,
+                           new TmfLocation<Long>(eventIndex)));
+                   // adjust index to round down to earlier checkpoint when exact match not found
+                   index = getPrevIndex(index);
+
+                   if (index == 0) {
+                       // No checkpoint restore is needed, start with a brand new
+                       // TraceState
+                       traceState = StateModelFactory.getStateEntryInstance(this);
+                   } else {
+
+                       // Useful CheckPoint found
+                       checkpoint = timestampCheckpointsList.get(index);
+                       // get the location associated with the checkpoint
+                       @SuppressWarnings("unchecked")
+                               TmfLocation<Long> location = (TmfLocation<Long>) checkpoint.getLocation();
+                       // reference a new copy of the checkpoint template
+                       traceState = stateCheckpointsList.get(location.getLocation()).clone();
+                   }
+
+               }
+
+               // Restore the stored traceState
+               synchronized (fStateModelLock) {
+                       fStateModel = traceState;
+               }
+
+               return checkpoint;
        }
 
        /**
This page took 0.027232 seconds and 5 git commands to generate.