tmf: Fix the actual end time of state system modules
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Fri, 1 Apr 2016 21:45:17 +0000 (17:45 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 4 May 2016 13:48:18 +0000 (09:48 -0400)
State providers keep track of the latest event that was handled is returns
this time as the current end time.

State system analysis module use this time to determine if an analysis is ready
to be queried. Also on the way to fix bug 488757.

Change-Id: I58308da05c3105f0a528398622658c3fb3f2250f
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/69760
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/AbstractTmfStateProvider.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfStateProvider.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java

index 46dd6ceff4cd0cfc87973945e06aae871d3bb30c..319f620c0a7a0a3232b86def800081b2885628e4 100644 (file)
@@ -45,10 +45,12 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
     private final Thread fEventHandlerThread;
 
     private boolean fStateSystemAssigned;
-
     /** State system in which to insert the state changes */
     private @Nullable ITmfStateSystemBuilder fSS = null;
 
+    /* The last safe time at which this state provider can be queried */
+    private volatile long fSafeTime;
+
     /**
      * Instantiate a new state provider plugin.
      *
@@ -61,6 +63,8 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
         fTrace = trace;
         fEventsQueue = new BufferedBlockingQueue<>(DEFAULT_EVENTS_QUEUE_SIZE, DEFAULT_EVENTS_CHUNK_SIZE);
         fStateSystemAssigned = false;
+        // set the safe time to before the trace start, the analysis has not yet started
+        fSafeTime = trace.getStartTime().toNanos() - 1;
 
         fEventHandlerThread = new Thread(new EventProcessor(), id + " Event Handler"); //$NON-NLS-1$
     }
@@ -84,6 +88,14 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
         return fTrace.getStartTime().toNanos();
     }
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    public long getLatestSafeTime() {
+        return fSafeTime;
+    }
+
     @Override
     public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) {
         fSS = ssb;
@@ -197,6 +209,7 @@ public abstract class AbstractTmfStateProvider implements ITmfStateProvider {
                     continue;
                 }
                 currentEvent = event;
+                fSafeTime = event.getTimestamp().toNanos() - 1;
                 eventHandle(event);
                 event = fEventsQueue.take();
             }
index c29fee2a5c0069d01ab23655dcb802f132f94854..8e40dc4392b264805a12e73bbd9e9617c20707c1 100644 (file)
@@ -55,6 +55,17 @@ public interface ITmfStateProvider {
      */
     long getStartTime();
 
+    /**
+     * Return the last time at which it is safe to query the state system under
+     * construction, ie not the current end time of the underlying state system,
+     * but the time just before the latest event that has been processed.
+     *
+     * @return The last timestamp at which it is safe to query the state system
+     *         underneath
+     * @since 2.0
+     */
+    long getLatestSafeTime();
+
     /**
      * Assign the target state system where this SCI will insert its state
      * changes. Because of dependencies issues, this can normally not be done at
index ae98a632e1f7677526be6ace8e5a5226770c1df0..9b2c3fb6dd774c3c8100924225dd39776ef90dc4 100644 (file)
@@ -66,15 +66,16 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
     private final CountDownLatch fInitialized = new CountDownLatch(1);
     private final Object fRequestSyncObj = new Object();
 
-    @Nullable private ITmfStateSystemBuilder fStateSystem;
-    @Nullable private ITmfStateProvider fStateProvider;
-    @Nullable private IStateHistoryBackend fHtBackend;
-    @Nullable private ITmfEventRequest fRequest;
-    @Nullable private TmfTimeRange fTimeRange = null;
+    private @Nullable ITmfStateSystemBuilder fStateSystem;
+    private @Nullable IStateHistoryBackend fHtBackend;
+    private @Nullable ITmfEventRequest fRequest;
+    private @Nullable TmfTimeRange fTimeRange = null;
 
     private int fNbRead = 0;
     private boolean fInitializationSucceeded;
 
+    private volatile @Nullable ITmfStateProvider fStateProvider;
+
     /**
      * State system backend types
      *
@@ -172,6 +173,19 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         return fInitializationSucceeded;
     }
 
+    /**
+     * @since 2.0
+     */
+    @Override
+    public boolean isQueryable(long ts) {
+        /* Return true if there is no state provider available (the analysis is not being built) */
+        ITmfStateProvider provider = fStateProvider;
+        if (provider == null) {
+            return true;
+        }
+        return ts <= provider.getLatestSafeTime();
+    }
+
     // ------------------------------------------------------------------------
     // TmfAbstractAnalysisModule
     // ------------------------------------------------------------------------
@@ -198,7 +212,6 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
             /* Get the state system according to backend */
             StateSystemBackendType backend = getBackendType();
 
-
             ITmfTrace trace = getTrace();
             if (trace == null) {
                 // Analysis was cancelled in the meantime
@@ -425,6 +438,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         if (provider != null) {
             provider.dispose();
         }
+        fStateProvider = null;
         if (deleteFiles && (fHtBackend != null)) {
             fHtBackend.removeFiles();
         }
@@ -525,9 +539,7 @@ public abstract class TmfStateSystemAnalysisModule extends TmfAbstractAnalysisMo
         @Override
         public void handleCancel() {
             super.handleCancel();
-            if (isCompleteTrace(trace)) {
-                disposeProvider(true);
-            }
+            disposeProvider(true);
         }
 
         @Override
This page took 0.027914 seconds and 5 git commands to generate.