package org.eclipse.linuxtools.tmf.core.trace;
import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest;
+import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
private long fNbEvents = 0;
// The time span of the event stream
- private ITmfTimestamp fStartTime = TmfTimestamp.BIG_CRUNCH;
+ private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
private ITmfTimestamp fEndTime = TmfTimestamp.BIG_BANG;
// The trace streaming interval (0 = no streaming)
// The trace's statistics
private ITmfStatistics fStatistics;
+ // The current selected time
+ private ITmfTimestamp fCurrentTime = TmfTimestamp.ZERO;
+
+ // The current selected range
+ private TmfTimeRange fCurrentRange = TmfTimeRange.NULL_RANGE;
+
+ /**
+ * The collection of state systems that are registered with this trace. Each
+ * sub-class can decide to add its (one or many) state system to this map
+ * during their {@link #buildStateSystem()}.
+ *
+ * @since 2.0
+ */
+ protected final Map<String, ITmfStateSystem> fStateSystems =
+ new HashMap<String, ITmfStateSystem>();
+
// ------------------------------------------------------------------------
// Construction
// ------------------------------------------------------------------------
}
}
super.init(traceName, type);
-
- buildStatistics();
}
/**
fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
}
+ /**
+ * Build the state system(s) associated with this trace type.
+ *
+ * Suppressing the warning, because the 'throws' will usually happen in
+ * sub-classes.
+ *
+ * @throws TmfTraceException
+ * If there is a problem during the build
+ * @since 2.0
+ */
+ @SuppressWarnings("unused")
+ protected void buildStateSystem() throws TmfTraceException {
+ /*
+ * Nothing is done in the base implementation, please specify
+ * how/if to register a new state system in derived classes.
+ */
+ return;
+ }
+
/**
* Clears the trace
*/
if (fStatistics != null) {
fStatistics.dispose();
}
+
+ /* Clean up the state systems */
+ for (ITmfStateSystem ss : fStateSystems.values()) {
+ ss.dispose();
+ }
+
super.dispose();
}
* @since 2.0
*/
@Override
- public ITmfStateSystem getStateSystem() {
- /*
- * By default, no state system is used. Sub-classes can specify their
- * own behaviour.
- */
- return null;
+ public final ITmfStateSystem getStateSystem(String id) {
+ return fStateSystems.get(id);
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public final Collection<String> listStateSystems() {
+ return fStateSystems.keySet();
}
// ------------------------------------------------------------------------
return fEndTime;
}
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentTime()
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public ITmfTimestamp getCurrentTime() {
+ return fCurrentTime;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentRange()
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public TmfTimeRange getCurrentRange() {
+ return fCurrentRange;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getInitialRangeOffset()
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public ITmfTimestamp getInitialRangeOffset() {
+ final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
+ return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
+ }
+
// ------------------------------------------------------------------------
- // Convenience setters/getters
+ // Convenience setters
// ------------------------------------------------------------------------
/**
if (fEndTime.equals(TmfTimestamp.BIG_CRUNCH) || (fEndTime.compareTo(timestamp, false) < 0)) {
fEndTime = timestamp;
}
+ if (fCurrentRange == TmfTimeRange.NULL_RANGE) {
+ fCurrentTime = timestamp;
+ ITmfTimestamp initialOffset = getInitialRangeOffset();
+ long endValue = timestamp.getValue() + initialOffset.normalize(0, timestamp.getScale()).getValue();
+ ITmfTimestamp endTimestamp = new TmfTimestamp(endValue, timestamp.getScale());
+ fCurrentRange = new TmfTimeRange(timestamp, endTimestamp);
+ }
if (context.hasValidRank()) {
long rank = context.getRank();
if (fNbEvents <= rank) {
// TmfDataProvider
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest)
+ /**
+ * @since 2.0
*/
@Override
- protected ITmfContext armRequest(final ITmfDataRequest request) {
+ public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
+ if (executorIsShutdown()) {
+ return null;
+ }
if ((request instanceof ITmfEventRequest)
&& !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
&& (request.getIndex() == 0))
return seekEvent(request.getIndex());
}
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the Trace Opened signal
+ *
+ * @param signal
+ * The incoming signal
+ * @since 2.0
+ */
+ @TmfSignalHandler
+ public void traceOpened(TmfTraceOpenedSignal signal) {
+ ITmfTrace trace = signal.getTrace();
+ if (signal.getTrace() instanceof TmfExperiment) {
+ TmfExperiment experiment = (TmfExperiment) signal.getTrace();
+ for (ITmfTrace expTrace : experiment.getTraces()) {
+ if (expTrace == this) {
+ trace = expTrace;
+ break;
+ }
+ }
+ }
+ if (trace == this) {
+ /* the signal is for this trace or for an experiment containing this trace */
+ try {
+ buildStatistics();
+ } catch (TmfTraceException e) {
+ e.printStackTrace();
+ }
+ try {
+ buildStateSystem();
+ } catch (TmfTraceException e) {
+ e.printStackTrace();
+ }
+
+ /* Refresh the project, so it can pick up new files that got created. */
+ try {
+ if (fResource != null) {
+ fResource.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+ if (signal.getTrace() == this) {
+ /* the signal is for this trace or experiment */
+ if (getNbEvents() == 0) {
+ return;
+ }
+
+ final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
+ final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
+
+ // Broadcast in separate thread to prevent deadlock
+ new Thread() {
+ @Override
+ public void run() {
+ broadcast(rangeUpdatedsignal);
+ }
+ }.start();
+ return;
+ }
+ }
+
+ /**
+ * Signal handler for the TmfTraceRangeUpdatedSignal signal
+ *
+ * @param signal The incoming signal
+ * @since 2.0
+ */
+ @TmfSignalHandler
+ public void traceRangeUpdated(final TmfTraceRangeUpdatedSignal signal) {
+ if (signal.getTrace() == this) {
+ getIndexer().buildIndex(getNbEvents(), signal.getRange(), false);
+ }
+ }
+
+ /**
+ * Signal handler for the TmfTimeSynchSignal signal
+ *
+ * @param signal The incoming signal
+ * @since 2.0
+ */
+ @TmfSignalHandler
+ public void synchToTime(final TmfTimeSynchSignal signal) {
+ if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
+ fCurrentTime = signal.getCurrentTime();
+ }
+ }
+
+ /**
+ * Signal handler for the TmfRangeSynchSignal signal
+ *
+ * @param signal The incoming signal
+ * @since 2.0
+ */
+ @TmfSignalHandler
+ public void synchToRange(final TmfRangeSynchSignal signal) {
+ if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
+ fCurrentTime = signal.getCurrentTime();
+ }
+ if (signal.getCurrentRange().getIntersection(getTimeRange()) != null) {
+ fCurrentRange = signal.getCurrentRange().getIntersection(getTimeRange());
+ }
+ }
+
// ------------------------------------------------------------------------
// toString
// ------------------------------------------------------------------------