/*******************************************************************************
- * Copyright (c) 2009, 2010, 2012, 2013 Ericsson
+ * Copyright (c) 2009, 2014 Ericsson, École Polytechnique de Montréal
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* Francois Chouinard - Initial API and implementation
* Francois Chouinard - Updated as per TMF Trace Model 1.0
* Patrick Tasse - Updated for removal of context clone
+ * Geneviève Bastien - Added timestamp transforms, its saving to file and
+ * timestamp creation functions
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.trace;
import java.io.File;
-import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.internal.tmf.core.Activator;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule;
+import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModuleHelper;
+import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisManager;
import org.eclipse.linuxtools.tmf.core.component.TmfEventProvider;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
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.TmfSignalManager;
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;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform;
+import org.eclipse.linuxtools.tmf.core.synchronization.TimestampTransformFactory;
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfNanoTimestamp;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.ITmfTraceIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
+import org.eclipse.linuxtools.tmf.core.trace.location.ITmfLocation;
/**
* Abstract implementation of ITmfTrace.
* <li> public double getLocationRatio(ITmfLocation<?> location)
* <li> public ITmfContext seekEvent(ITmfLocation<?> location)
* <li> public ITmfContext seekEvent(double ratio)
- * <li> public boolean validate(IProject project, String path)
+ * <li> public IStatus validate(IProject project, String path)
* </ul>
* A concrete trace must provide its corresponding parser. A common way to
* accomplish this is by making the concrete class extend TmfTrace and
* implement ITmfEventParser.
* <p>
+ * When constructing an event, the concrete trace should use the trace's
+ * timestamp transform to create the timestamp, by either transforming the
+ * parsed time value directly or by using the method createTimestamp().
+ * <p>
* The concrete class can either specify its own indexer or use the provided
* TmfCheckpointIndexer (default). In this case, the trace cache size will be
* used as checkpoint interval.
* @see ITmfTraceIndexer
* @see ITmfEventParser
*/
-public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace {
+public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace, ITmfTraceCompleteness {
// ------------------------------------------------------------------------
// Attributes
private int fCacheSize = ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
// The number of events collected (so far)
- private long fNbEvents = 0;
+ private volatile long fNbEvents = 0;
// The time span of the event stream
private ITmfTimestamp fStartTime = TmfTimestamp.BIG_BANG;
// The trace parser
private ITmfEventParser fParser;
- // The trace's statistics
- private ITmfStatistics fStatistics;
-
- // The current selected time
- private ITmfTimestamp fCurrentTime = TmfTimestamp.ZERO;
+ private ITmfTimestampTransform fTsTransform;
- // 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>();
+ private final Map<String, IAnalysisModule> fAnalysisModules =
+ Collections.synchronizedMap(new LinkedHashMap<String, IAnalysisModule>());
// ------------------------------------------------------------------------
// Construction
*/
public TmfTrace() {
super();
+ fIndexer = createIndexer(DEFAULT_BLOCK_SIZE);
}
/**
- * The standard constructor (non-live trace). Applicable when the trace
- * implements its own parser and if at checkpoint-based index is OK.
- *
- * @param resource the resource associated to the trace
- * @param type the trace event type
- * @param path the trace path
- * @param cacheSize the trace cache size
- * @throws TmfTraceException If something failed during the opening
- */
- protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize) throws TmfTraceException {
- this(resource, type, path, cacheSize, 0);
- }
-
- /**
- * The standard constructor (live trace). Applicable when the trace
- * implements its own parser and if at checkpoint-based index is OK.
- *
- * @param resource the resource associated to the trace
- * @param type the trace event type
- * @param path the trace path
- * @param cacheSize the trace cache size
- * @param interval the trace streaming interval
- * @throws TmfTraceException If something failed during the opening
- */
- protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize, final long interval) throws TmfTraceException {
- this(resource, type, path, cacheSize, interval, null);
- }
-
- /**
- * The 'non-default indexer' constructor. Allows to provide a trace
- * specific indexer.
- *
- * @param resource the resource associated to the trace
- * @param type the trace event type
- * @param path the trace path
- * @param cacheSize the trace cache size
- * @param interval the trace streaming interval
- * @param indexer the trace indexer
- * @throws TmfTraceException If something failed during the opening
- */
- protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
- final long interval, final ITmfTraceIndexer indexer) throws TmfTraceException {
- this(resource, type, path, cacheSize, interval, indexer, null);
- }
-
- /**
- * The full constructor where trace specific indexer/parser are provided.
+ * Full constructor.
*
- * @param resource the resource associated to the trace
- * @param type the trace event type
- * @param path the trace path
- * @param cacheSize the trace cache size
- * @param interval the trace streaming interval
- * @param indexer the trace indexer
- * @param parser the trace event parser
- * @throws TmfTraceException If something failed during the opening
- */
- protected TmfTrace(final IResource resource, final Class<? extends ITmfEvent> type, final String path, final int cacheSize,
- final long interval, final ITmfTraceIndexer indexer, final ITmfEventParser parser) throws TmfTraceException {
+ * @param resource
+ * The resource associated to the trace
+ * @param type
+ * The type of events that will be read from this trace
+ * @param path
+ * The path to the trace on the filesystem
+ * @param cacheSize
+ * The trace cache size. Pass '-1' to use the default specified
+ * in {@link ITmfTrace#DEFAULT_TRACE_CACHE_SIZE}
+ * @param interval
+ * The trace streaming interval. You can use '0' for post-mortem
+ * traces.
+ * @param parser
+ * The trace event parser. Use 'null' if (and only if) the trace
+ * object itself is also the ITmfEventParser to be used.
+ * @throws TmfTraceException
+ * If something failed during the opening
+ */
+ protected TmfTrace(final IResource resource,
+ final Class<? extends ITmfEvent> type,
+ final String path,
+ final int cacheSize,
+ final long interval,
+ final ITmfEventParser parser)
+ throws TmfTraceException {
super();
fCacheSize = (cacheSize > 0) ? cacheSize : ITmfTrace.DEFAULT_TRACE_CACHE_SIZE;
fStreamingInterval = interval;
- fIndexer = (indexer != null) ? indexer : new TmfCheckpointIndexer(this, fCacheSize);
fParser = parser;
initialize(resource, path, type);
}
}
fCacheSize = trace.getCacheSize();
fStreamingInterval = trace.getStreamingInterval();
- fIndexer = new TmfCheckpointIndexer(this);
fParser = trace.fParser;
initialize(trace.getResource(), trace.getPath(), trace.getEventType());
}
+ /**
+ * Creates the indexer instance. Classes extending this class can override
+ * this to provide a different indexer implementation.
+ *
+ * @param interval the checkpoints interval
+ *
+ * @return the indexer
+ * @since 3.0
+ */
+ protected ITmfTraceIndexer createIndexer(int interval) {
+ return new TmfCheckpointIndexer(this, interval);
+ }
+
// ------------------------------------------------------------------------
// ITmfTrace - Initializers
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#initTrace(org.eclipse.core.resources.IResource, java.lang.String, java.lang.Class)
- */
+ @Override
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type, String name) throws TmfTraceException {
+ setName(name);
+ initTrace(resource, path, type);
+ }
+
@Override
public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
- fIndexer = new TmfCheckpointIndexer(this, fCacheSize);
initialize(resource, path, type);
}
*
* @throws TmfTraceException If something failed during the initialization
*/
- protected void initialize(final IResource resource, final String path, final Class<? extends ITmfEvent> type) throws TmfTraceException {
+ protected void initialize(final IResource resource,
+ final String path,
+ final Class<? extends ITmfEvent> type)
+ throws TmfTraceException {
if (path == null) {
throw new TmfTraceException("Invalid trace path"); //$NON-NLS-1$
}
fPath = path;
fResource = resource;
- String traceName = (resource != null) ? resource.getName() : null;
- // If no resource was provided, extract the display name the trace path
- if (traceName == null) {
- final int sep = path.lastIndexOf(IPath.SEPARATOR);
- traceName = (sep >= 0) ? path.substring(sep + 1) : path;
+ String traceName = getName();
+ if (traceName == null || traceName.isEmpty()) {
+ traceName = (resource != null) ? resource.getName() : new Path(path).lastSegment();
}
if (fParser == null) {
if (this instanceof ITmfEventParser) {
}
}
super.init(traceName, type);
+ // register as VIP after super.init() because TmfComponent registers to signal manager there
+ TmfSignalManager.registerVIP(this);
+ if (fIndexer != null) {
+ fIndexer.dispose();
+ }
+ fIndexer = createIndexer(fCacheSize);
}
/**
}
/**
- * Index the trace
- *
- * @param waitForCompletion index synchronously (true) or not (false)
+ * @since 2.0
*/
- protected void indexTrace(boolean waitForCompletion) {
+ @Override
+ public void indexTrace(boolean waitForCompletion) {
getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion);
}
/**
- * The default implementation of TmfTrace uses a TmfStatistics back-end.
- * Override this if you want to specify another type (or none at all).
+ * Instantiate the applicable analysis modules and executes the analysis
+ * modules that are meant to be automatically executed
*
- * @throws TmfTraceException
- * If there was a problem setting up the statistics
- * @since 2.0
+ * @return An IStatus indicating whether the analysis could be run
+ * successfully or not
+ * @since 3.0
+ */
+ protected IStatus executeAnalysis() {
+ MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null);
+ Map<String, IAnalysisModuleHelper> modules = TmfAnalysisManager.getAnalysisModules(this.getClass());
+ for (IAnalysisModuleHelper helper : modules.values()) {
+ try {
+ IAnalysisModule module = helper.newModule(this);
+ fAnalysisModules.put(module.getId(), module);
+ if (module.isAutomatic()) {
+ status.add(module.schedule());
+ }
+ } catch (TmfAnalysisException e) {
+ status.add(new Status(IStatus.WARNING, Activator.PLUGIN_ID, e.getMessage()));
+ }
+ }
+ return status;
+ }
+
+ /**
+ * @since 3.0
*/
- protected void buildStatistics() throws TmfTraceException {
- /*
- * Initialize the statistics provider, but only if a Resource has been
- * set (so we don't build it for experiments, for unit tests, etc.)
- */
- fStatistics = (fResource == null ? null : new TmfStateStatistics(this) );
+ @Override
+ public IAnalysisModule getAnalysisModule(String analysisId) {
+ return fAnalysisModules.get(analysisId);
}
+
/**
- * 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
+ * @since 3.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;
+ @Override
+ public Iterable<IAnalysisModule> getAnalysisModules() {
+ synchronized (fAnalysisModules) {
+ Set<IAnalysisModule> modules = new HashSet<>(fAnalysisModules.values());
+ return modules;
+ }
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public <T extends IAnalysisModule> T getAnalysisModuleOfClass(Class<T> moduleClass, String id) {
+ Iterable<T> modules = getAnalysisModulesOfClass(moduleClass);
+ for (T module : modules) {
+ if (id.equals(module.getId())) {
+ return module;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public <T> Iterable<T> getAnalysisModulesOfClass(Class<T> moduleClass) {
+ Set<T> modules = new HashSet<>();
+ synchronized (fAnalysisModules) {
+ for (Entry<String, IAnalysisModule> entry : fAnalysisModules.entrySet()) {
+ if (moduleClass.isAssignableFrom(entry.getValue().getClass())) {
+ modules.add(moduleClass.cast(entry.getValue()));
+ }
+ }
+ }
+ return modules;
}
/**
getIndexer().dispose();
}
- /* Clean up the statistics */
- if (fStatistics != null) {
- fStatistics.dispose();
- }
-
- /* Clean up the state systems */
- for (ITmfStateSystem ss : fStateSystems.values()) {
- ss.dispose();
+ /* Clean up the analysis modules */
+ synchronized (fAnalysisModules) {
+ for (IAnalysisModule module : fAnalysisModules.values()) {
+ module.dispose();
+ }
+ fAnalysisModules.clear();
}
super.dispose();
// ITmfTrace - Basic getters
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEventType()
- */
@Override
- public Class<ITmfEvent> getEventType() {
- return (Class<ITmfEvent>) super.getType();
+ public Class<? extends ITmfEvent> getEventType() {
+ return super.getType();
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getResource()
- */
@Override
public IResource getResource() {
return fResource;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getPath()
- */
@Override
public String getPath() {
return fPath;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getIndexPageSize()
- */
@Override
public int getCacheSize() {
return fCacheSize;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStreamingInterval()
- */
@Override
public long getStreamingInterval() {
return fStreamingInterval;
/**
* @return the trace indexer
+ * @since 3.0
*/
protected ITmfTraceIndexer getIndexer() {
return fIndexer;
return fParser;
}
- /**
- * @since 2.0
- */
- @Override
- public ITmfStatistics getStatistics() {
- return fStatistics;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public final ITmfStateSystem getStateSystem(String id) {
- return fStateSystems.get(id);
- }
-
- /**
- * @since 2.0
- */
- @Override
- public final Collection<String> listStateSystems() {
- return fStateSystems.keySet();
- }
-
// ------------------------------------------------------------------------
// ITmfTrace - Trace characteristics getters
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNbEvents()
- */
@Override
- public synchronized long getNbEvents() {
+ public long getNbEvents() {
return fNbEvents;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getTimeRange()
+ /**
+ * @since 2.0
*/
@Override
public TmfTimeRange getTimeRange() {
return new TmfTimeRange(fStartTime, fEndTime);
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getStartTime()
+ /**
+ * @since 2.0
*/
@Override
public ITmfTimestamp getStartTime() {
return fStartTime;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getEndTime()
- */
- @Override
- public ITmfTimestamp getEndTime() {
- return fEndTime;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentTime()
- */
/**
* @since 2.0
*/
@Override
- public ITmfTimestamp getCurrentTime() {
- return fCurrentTime;
+ public ITmfTimestamp getEndTime() {
+ return fEndTime;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentRange()
- */
/**
* @since 2.0
*/
@Override
- public TmfTimeRange getCurrentRange() {
- return fCurrentRange;
+ public ITmfTimestamp getInitialRangeOffset() {
+ final long DEFAULT_INITIAL_OFFSET_VALUE = (1L * 100 * 1000 * 1000); // .1sec
+ return new TmfTimestamp(DEFAULT_INITIAL_OFFSET_VALUE, ITmfTimestamp.NANOSECOND_SCALE);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getInitialRangeOffset()
- */
/**
- * @since 2.0
+ * @since 3.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);
+ public String getHostId() {
+ return this.getName();
}
// ------------------------------------------------------------------------
* Update the trace events time range
*
* @param range the new time range
+ * @since 2.0
*/
protected void setTimeRange(final TmfTimeRange range) {
fStartTime = range.getStartTime();
* Update the trace chronologically first event timestamp
*
* @param startTime the new first event timestamp
+ * @since 2.0
*/
protected void setStartTime(final ITmfTimestamp startTime) {
fStartTime = startTime;
* Update the trace chronologically last event timestamp
*
* @param endTime the new last event timestamp
+ * @since 2.0
*/
protected void setEndTime(final ITmfTimestamp endTime) {
fEndTime = endTime;
fStreamingInterval = (interval > 0) ? interval : 0;
}
- /**
- * Set the trace indexer. Must be done at initialization time.
- *
- * @param indexer the trace indexer
- */
- protected void setIndexer(final ITmfTraceIndexer indexer) {
- fIndexer = indexer;
- }
-
/**
* Set the trace parser. Must be done at initialization time.
*
// ITmfTrace - SeekEvent operations (returning a trace context)
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(long)
- */
@Override
public synchronized ITmfContext seekEvent(final long rank) {
return context;
}
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#seekEvent(org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
+ /**
+ * @since 2.0
*/
@Override
public synchronized ITmfContext seekEvent(final ITmfTimestamp timestamp) {
// ITmfTrace - Read operations (returning an actual event)
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#readNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
- */
@Override
public synchronized ITmfEvent getNext(final ITmfContext context) {
// parseEvent() does not update the context
*
* @param context the current trace context
* @param timestamp the corresponding timestamp
+ * @since 2.0
*/
protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
if (fStartTime.equals(TmfTimestamp.BIG_BANG) || (fStartTime.compareTo(timestamp, false) > 0)) {
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) {
* @since 2.0
*/
@Override
- public synchronized ITmfContext armRequest(final ITmfDataRequest request) {
+ public synchronized ITmfContext armRequest(final ITmfEventRequest request) {
if (executorIsShutdown()) {
return null;
}
- if ((request instanceof ITmfEventRequest)
- && !TmfTimestamp.BIG_BANG.equals(((ITmfEventRequest) request).getRange().getStartTime())
- && (request.getIndex() == 0))
- {
- final ITmfContext context = seekEvent(((ITmfEventRequest) request).getRange().getStartTime());
- ((ITmfEventRequest) request).setStartIndex((int) context.getRank());
+ if (!TmfTimestamp.BIG_BANG.equals(request.getRange().getStartTime())
+ && (request.getIndex() == 0)) {
+ final ITmfContext context = seekEvent(request.getRange().getStartTime());
+ request.setStartIndex((int) context.getRank());
return context;
}
*/
@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;
- }
+ boolean signalIsForUs = false;
+ for (ITmfTrace trace : TmfTraceManager.getTraceSet(signal.getTrace())) {
+ if (trace == this) {
+ signalIsForUs = true;
+ 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 (!signalIsForUs) {
+ return;
}
+
+ /*
+ * The signal is either for this trace, or for an experiment containing
+ * this trace.
+ */
+ IStatus status = executeAnalysis();
+ if (!status.isOK()) {
+ Activator.log(status);
+ }
+
+ TmfTraceManager.refreshSupplementaryFiles(this);
+
if (signal.getTrace() == this) {
- /* the signal is for this trace or experiment */
+ /* Additionally, the signal is directly for this trace. */
if (getNbEvents() == 0) {
return;
}
- final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
- final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
+ /* For a streaming trace, the range updated signal should be sent
+ * by the subclass when a new safe time is determined.
+ */
+ if (getStreamingInterval() > 0) {
+ return;
+ }
- // Broadcast in separate thread to prevent deadlock
- new Thread() {
- @Override
- public void run() {
- broadcast(rangeUpdatedsignal);
- }
- }.start();
+ if (isComplete()) {
+ final TmfTimeRange timeRange = new TmfTimeRange(getStartTime(), TmfTimestamp.BIG_CRUNCH);
+ final TmfTraceRangeUpdatedSignal rangeUpdatedsignal = new TmfTraceRangeUpdatedSignal(this, this, timeRange);
+
+ // Broadcast in separate thread to prevent deadlock
+ broadcastAsync(rangeUpdatedsignal);
+ }
return;
}
}
}
/**
- * Signal handler for the TmfTimeSynchSignal signal
+ * Signal handler for the TmfTraceUpdatedSignal signal
*
* @param signal The incoming signal
- * @since 2.0
+ * @since 3.0
*/
@TmfSignalHandler
- public void synchToTime(final TmfTimeSynchSignal signal) {
- if (signal.getCurrentTime().compareTo(fStartTime) >= 0 && signal.getCurrentTime().compareTo(fEndTime) <= 0) {
- fCurrentTime = signal.getCurrentTime();
+ public void traceUpdated(final TmfTraceUpdatedSignal signal) {
+ if (signal.getSource() == getIndexer()) {
+ fNbEvents = signal.getNbEvents();
+ fStartTime = signal.getRange().getStartTime();
+ fEndTime = signal.getRange().getEndTime();
}
}
+ // ------------------------------------------------------------------------
+ // Timestamp transformation functions
+ // ------------------------------------------------------------------------
+
/**
- * Signal handler for the TmfRangeSynchSignal signal
- *
- * @param signal The incoming signal
- * @since 2.0
+ * @since 3.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());
+ @Override
+ public ITmfTimestampTransform getTimestampTransform() {
+ if (fTsTransform == null) {
+ fTsTransform = TimestampTransformFactory.getTimestampTransform(getResource());
}
+ return fTsTransform;
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public void setTimestampTransform(final ITmfTimestampTransform tt) {
+ fTsTransform = tt;
+ TimestampTransformFactory.setTimestampTransform(getResource(), tt);
+ }
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public ITmfTimestamp createTimestamp(long ts) {
+ return new TmfNanoTimestamp(getTimestampTransform().transform(ts));
}
// ------------------------------------------------------------------------
// toString
// ------------------------------------------------------------------------
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
@Override
@SuppressWarnings("nls")
public synchronized String toString() {
+ ", fEndTime=" + fEndTime + ", fStreamingInterval=" + fStreamingInterval + "]";
}
+ /**
+ * @since 3.1
+ */
+ @Override
+ public boolean isComplete() {
+ /*
+ * Be default, all traces are "complete" which means no more data will
+ * be added later
+ */
+ return true;
+ }
+
+ /**
+ * @since 3.1
+ */
+ @Override
+ public void setComplete(boolean isComplete) {
+ /*
+ * This should be overridden by trace classes that can support live
+ * reading (traces in an incomplete state)
+ */
+ }
}