From 91dc8d51c4da5108282aedea2c9119c325fa1042 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Fri, 1 Apr 2016 17:45:17 -0400 Subject: [PATCH] tmf: Fix the actual end time of state system modules MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-on: https://git.eclipse.org/r/69760 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- .../statesystem/AbstractTmfStateProvider.java | 15 +++++++++- .../core/statesystem/ITmfStateProvider.java | 11 +++++++ .../TmfStateSystemAnalysisModule.java | 30 +++++++++++++------ 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/AbstractTmfStateProvider.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/AbstractTmfStateProvider.java index 46dd6ceff4..319f620c0a 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/AbstractTmfStateProvider.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/AbstractTmfStateProvider.java @@ -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(); } diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfStateProvider.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfStateProvider.java index c29fee2a5c..8e40dc4392 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfStateProvider.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/ITmfStateProvider.java @@ -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 diff --git a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java index ae98a632e1..9b2c3fb6dd 100644 --- a/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java +++ b/tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/statesystem/TmfStateSystemAnalysisModule.java @@ -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 -- 2.34.1