import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
import org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment;
+import com.google.common.annotations.VisibleForTesting;
+
/**
* Abstract analysis module to generate a state system. It is a base class that
* can be used as a shortcut by analysis who just need to build a single state
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 ITmfEventRequest fRequest;
+ private @Nullable TmfTimeRange fTimeRange = null;
private int fNbRead = 0;
private boolean fInitializationSucceeded;
+ private volatile @Nullable ITmfStateProvider fStateProvider;
+
/**
* State system backend types
*
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
// ------------------------------------------------------------------------
- private @Nullable File getSsFile() {
+ /**
+ * Get the file where to save the results of the analysis
+ *
+ * @return The file to save the results in
+ * @since 2.3
+ */
+ @VisibleForTesting
+ protected @Nullable File getSsFile() {
ITmfTrace trace = getTrace();
if (trace == null) {
return null;
/* Get the state system according to backend */
StateSystemBackendType backend = getBackendType();
-
ITmfTrace trace = getTrace();
if (trace == null) {
// Analysis was cancelled in the meantime
try {
IStateHistoryBackend backend = StateHistoryBackendFactory.createHistoryTreeBackendExistingFile(
id, htFile, version);
- fHtBackend = backend;
fStateSystem = StateSystemFactory.newStateSystem(backend, false);
analysisReady(true);
return;
try {
IStateHistoryBackend backend = StateHistoryBackendFactory.createHistoryTreeBackendNewFile(
id, htFile, provider.getVersion(), provider.getStartTime(), QUEUE_SIZE);
- fHtBackend = backend;
fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
provider.assignTargetStateSystem(realSS);
/* 7 */
- fHtBackend = partialBackend;
fStateSystem = realSS;
build(provider);
*/
private void createNullHistory(String id, ITmfStateProvider provider) {
IStateHistoryBackend backend = StateHistoryBackendFactory.createNullBackend(id);
- fHtBackend = backend;
fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
*/
private void createInMemoryHistory(String id, ITmfStateProvider provider) {
IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(id, provider.getStartTime());
- fHtBackend = backend;
fStateSystem = StateSystemFactory.newStateSystem(backend);
provider.assignTargetStateSystem(fStateSystem);
build(provider);
if (provider != null) {
provider.dispose();
}
- if (deleteFiles && (fHtBackend != null)) {
- fHtBackend.removeFiles();
+ fStateProvider = null;
+ if (deleteFiles && (fStateSystem != null)) {
+ fStateSystem.removeFiles();
}
}
private void build(ITmfStateProvider provider) {
- if ((fStateSystem == null) || (fHtBackend == null)) {
+ if (fStateSystem == null) {
throw new IllegalArgumentException();
}
fStateProvider = provider;
synchronized (fRequestSyncObj) {
startRequest();
+ request = fRequest;
}
/*
* progress monitor displays that it is running).
*/
try {
- if (fRequest != null) {
- fRequest.waitForCompletion();
+ if (request != null) {
+ request.waitForCompletion();
+ if (request.isFailed()) {
+ Throwable failureCause = request.getFailureCause();
+ if (failureCause != null) {
+ fail(failureCause);
+ } else {
+ fail(new RuntimeException("Event request failed without a cause")); //$NON-NLS-1$
+ }
+ }
}
} catch (InterruptedException e) {
- e.printStackTrace();
+ fail(e);
}
}
- private class StateSystemEventRequest extends TmfEventRequest {
+ /**
+ * A request to build a state system from a state provider
+ *
+ * @since 2.3
+ */
+ @VisibleForTesting
+ protected class StateSystemEventRequest extends TmfEventRequest {
private final ITmfStateProvider sci;
private final ITmfTrace trace;
+ /**
+ * Constructor
+ *
+ * @param sp
+ * The state provider used to build the state system
+ * @param timeRange
+ * The requested time range for the request
+ * @param index
+ * The event number at which to start the request
+ */
public StateSystemEventRequest(ITmfStateProvider sp, TmfTimeRange timeRange, int index) {
super(ITmfEvent.class,
timeRange,
index,
ITmfEventRequest.ALL_DATA,
- ITmfEventRequest.ExecutionType.BACKGROUND);
+ ITmfEventRequest.ExecutionType.BACKGROUND,
+ TmfStateSystemAnalysisModule.this.getDependencyLevel());
this.sci = sp;
trace = sci.getTrace();
@Override
public void handleCancel() {
super.handleCancel();
- if (isCompleteTrace(trace)) {
- disposeProvider(true);
- }
+ disposeProvider(true);
}
@Override
if (stateProvider == null || timeRange == null) {
return;
}
- ITmfEventRequest request = new StateSystemEventRequest(stateProvider, timeRange, fNbRead);
+ ITmfEventRequest request = createEventRequest(stateProvider, timeRange, fNbRead);
stateProvider.getTrace().sendRequest(request);
fRequest = request;
}
+ /**
+ * Create a new event request
+ *
+ * @param stateProvider
+ * The state provider used to build the state system
+ * @param timeRange
+ * The requested time range for the request
+ * @param nbRead
+ * The event number at which to start the request
+ * @return A new event request
+ * @since 2.3
+ */
+ @VisibleForTesting
+ protected ITmfEventRequest createEventRequest(ITmfStateProvider stateProvider, TmfTimeRange timeRange, int nbRead) {
+ return new StateSystemEventRequest(stateProvider, timeRange, nbRead);
+ }
+
private static boolean isCompleteTrace(ITmfTrace trace) {
return !(trace instanceof ITmfTraceCompleteness) || ((ITmfTraceCompleteness) trace).isComplete();
}