import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
-import org.eclipse.linuxtools.tmf.core.trace.TmfCheckpoint;
import org.eclipse.linuxtools.tmf.core.trace.TmfContext;
import org.eclipse.linuxtools.tmf.core.trace.TmfLocation;
import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
public LTTngTextTrace(final IResource resource, final String path, final boolean skipIndexing) throws Exception {
// super(null, LttngEvent.class, path, 1, !skipIndexing);
- super(null, LttngEvent.class, path, 1);
+ super(null, LttngEvent.class, path, 1000);
tracepath = path;
traceTypes = new HashMap<String, LttngEventType>();
if ( positionToFirstEvent() == false )
throw new IOException("Fail to position to the beginning of the trace"); //$NON-NLS-1$
else {
- fCacheSize = 1000;
+// fCacheSize = 1000;
// Skip indexing if asked
// if ( skipIndexing == true ) {
- fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation<Long>(0L)));
+// fCheckpoints.add(new TmfCheckpoint(new LttngTimestamp(0L), new TmfLocation<Long>(0L)));
+ ITmfContext context = new TmfContext(new TmfLocation<Long>(0L), 0);
+ fIndexer.updateIndex(context, new LttngTimestamp(0L));
// }
// else {
// indexTrace(true);
// *** VERIFY ***
// Is this safe?
- fCheckpoints = oldTrace.fCheckpoints;
+// fCheckpoints = oldTrace.fCheckpoints;
}
private boolean positionToFirstEvent() {
*/
public LTTngTrace(final LTTngTrace other) throws Exception {
this(other.getResource(), other.getPath(), other.getTraceLibPath(), false, true);
- this.fCheckpoints = other.fCheckpoints;
+// this.fCheckpoints = other.fCheckpoints;
setTimeRange(new TmfTimeRange(new LttngTimestamp(other.getStartTime()), new LttngTimestamp(other.getEndTime())));
}
if (PRINT_DEBUG)
System.out.println("seekEvent(rank) rank -> " + rank); //$NON-NLS-1$
- ITmfTimestamp timestamp = null;
+// ITmfTimestamp timestamp = null;
+// long index = rank / getCacheSize();
+//
+// // Get the timestamp of the closest check point to the given position
+// if (fCheckpoints.size() > 0) {
+// if (index >= fCheckpoints.size())
+// index = fCheckpoints.size() - 1;
+// timestamp = fCheckpoints.elementAt((int) index).getTimestamp();
+// } else
+// timestamp = getStartTime();
+
+ // Position the trace at the checkpoint
+ final ITmfContext checkpointContext = fIndexer.seekIndex(rank);
+ LttngLocation location = (LttngLocation) checkpointContext.getLocation();
+ ITmfTimestamp timestamp = location.getLocation();
long index = rank / getCacheSize();
- // Get the timestamp of the closest check point to the given position
- if (fCheckpoints.size() > 0) {
- if (index >= fCheckpoints.size())
- index = fCheckpoints.size() - 1;
- timestamp = fCheckpoints.elementAt((int) index).getTimestamp();
- } else
- timestamp = getStartTime();
-
// Seek to the found time
final TmfContext tmpContext = seekEvent(timestamp);
tmpContext.setRank((index + 1) * fCacheSize);
// long eventTime = eventTimestamp.getValue();
previousLocation.setOperationTime(eventTimestamp.getValue());
curLocation.setOperationTime(eventTimestamp.getValue());
- updateIndex(context, context.getRank(), eventTimestamp);
+ updateAttributes(context, eventTimestamp);
context.increaseRank();
}
return -1;
}
- /**
- * Print the content of the checkpoint vector.
- * <p>
- *
- * This is intended for debug purpose only.
- */
- public void printCheckpointsVector() {
- System.out.println("StartTime : " //$NON-NLS-1$
- + getTimeRange().getStartTime().getValue());
- System.out.println("EndTime : " //$NON-NLS-1$
- + getTimeRange().getEndTime().getValue());
-
- for (int pos = 0; pos < fCheckpoints.size(); pos++) {
- System.out.print(pos + ": " + "\t"); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.print(fCheckpoints.get(pos).getTimestamp() + "\t"); //$NON-NLS-1$
- System.out.println(fCheckpoints.get(pos).getLocation());
- }
- }
+// /**
+// * Print the content of the checkpoint vector.
+// * <p>
+// *
+// * This is intended for debug purpose only.
+// */
+// public void printCheckpointsVector() {
+// System.out.println("StartTime : " //$NON-NLS-1$
+// + getTimeRange().getStartTime().getValue());
+// System.out.println("EndTime : " //$NON-NLS-1$
+// + getTimeRange().getEndTime().getValue());
+//
+// for (int pos = 0; pos < fCheckpoints.size(); pos++) {
+// System.out.print(pos + ": " + "\t"); //$NON-NLS-1$ //$NON-NLS-2$
+// System.out.print(fCheckpoints.get(pos).getTimestamp() + "\t"); //$NON-NLS-1$
+// System.out.println(fCheckpoints.get(pos).getLocation());
+// }
+// }
@Override
public synchronized void dispose() {
}
/**
- * Initialize the provider based on the request. The context is provider specific and will be updated by getNext().
+ * Initialize the provider based on the request. The context is provider
+ * specific and will be updated by getNext().
*
* @param request
* @return an application specific context; null if request can't be serviced
*/
public abstract ITmfContext armRequest(ITmfDataRequest<T> request);
+ /**
+ * Return the next event based on the context supplied. The context
+ * will be updated for the subsequent read.
+ *
+ * @param context the trace read context (updated)
+ * @return the event referred to by context
+ */
public abstract T getNext(ITmfContext context);
/**
* For convenience, a free-form reference field is also provided. It could be
* used as e.g. a location marker (filename:lineno) to indicate where the event
* was generated.
+ *
+ * @see ITmfTimestamp
+ * @see ITmfEventType
+ * @see ITmfEvetnField
+ * @see TmfEvent
*/
public interface ITmfEvent extends Cloneable {
* <li>[precision] indicates the error on the value (useful for comparing
* timestamps in different scales). Default: 0.
* </ul>
+ *
+ * @since 1.0
+ * @version 1.0
+ * @author Francois Chouinard
+ * @see TmfTimestamp
+ * @see TmfSimpleTimestamp
+ * @see TmfTimeRange
*/
public interface ITmfTimestamp extends Cloneable, Comparable<ITmfTimestamp> {
* trace. Seek operations can be performed for a particular event (by rank or
* timestamp) or for a plain trace location.
* <p>
- * <b>Example 1</b>: Read a whole trace
+ * <b>Example 1</b>: Process a whole trace
* <pre>
* ITmfContext context = trace.seekLocationt(null);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfEvent event = trace.getNextEvent(context);
* while (event != null) {
- * // Do something ...
- * event = trace.getEvent(context);
+ * processEvent(event);
+ * event = trace.getNextEvent(context);
* }
* </pre>
* <b>Example 2</b>: Process 50 events starting from the 1000th event
* <pre>
* int nbEventsRead = 0;
* ITmfContext context = trace.seekEvent(1000);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfEvent event = trace.getNextEvent(context);
* while (event != null && nbEventsRead < 50) {
* nbEventsRead++;
- * // Do something ...
- * event = trace.getEvent(context);
+ * processEvent(event);
+ * event = trace.getNextEvent(context);
* }
* </pre>
* <b>Example 3</b>: Process the events between 2 timestamps (inclusive)
* ITmfTimestamp startTime = ...;
* ITmfTimestamp endTime = ...;
* ITmfContext context = trace.seekEvent(startTime);
- * ITmfEvent event = trace.getEvent(context);
+ * ITmfEvent event = trace.getNextEvent(context);
* while (event != null && event.getTimestamp().compareTo(endTime) <= 0) {
- * // Do something ...
- * event = trace.getEvent(context);
+ * processEvent(event);
+ * event = trace.getNextEvent(context);
* }
* </pre>
+ * A trace is also an event provider so it can process event requests
+ * asynchronously (and coalesce compatible requests).
+ * <p>
+ * </pre>
+ * <b>Example 4</b>: Process a whole trace
+ * <pre>
+ * ITmfRequest request = new TmfEventRequest<MyEventType>(MyEventType.class) {
+ * @Override
+ * public void handleData(MyEventType event) {
+ * super.handleData(event);
+ * processEvent(event);
+ * }
+ * @Override
+ * public void handleCompleted() {
+ * finish();
+ * super.handleCompleted();
+ * }
+ * };
+ * fTrace.handleRequest(request);
+ * if (youWant) {
+ * request.waitForCompletion();
+ * }
+ * </pre>
+ * @see ITmfEvent
+ * @see ITmfEventProvider
+ * @see ITmfRequest
*/
public interface ITmfTrace<T extends ITmfEvent> extends ITmfDataProvider<T> {
* Initialize a newly instantiated "empty" trace object. This is used to
* properly parameterize an ITmfTrace instantiated with its parameterless
* constructor.
- *
+ * <p>
* Typically, the parameterless constructor will provide the block size
* and its associated parser and indexer.
*
* Adds an entry to the trace index.
*
* @param context
- * @param rank
* @param timestamp
*/
- public void updateIndex(ITmfContext context, long rank, ITmfTimestamp timestamp);
+ public void updateIndex(ITmfContext context, ITmfTimestamp timestamp);
/**
* Returns the context of the checkpoint immediately preceding the requested
import java.io.File;
import java.io.FileNotFoundException;
-import java.util.Vector;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
protected int fCacheSize = DEFAULT_TRACE_CACHE_SIZE;
// The set of event stream checkpoints
- protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
+// protected Vector<TmfCheckpoint> fCheckpoints = new Vector<TmfCheckpoint>();
// The number of events collected
protected long fNbEvents = 0;
super();
fCacheSize = (cacheSize > 0) ? cacheSize : DEFAULT_TRACE_CACHE_SIZE;
fStreamingInterval = interval;
- fIndexer = (indexer != null) ? indexer : new TmfTraceIndexer(this);
+ fIndexer = (indexer != null) ? indexer : new TmfTraceIndexer(this, fCacheSize);
initialize(resource, path, type);
}
// ITmfTrace - Read operations (returning an actual event)
// ------------------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#parseEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
+ */
+ @Override
+ public synchronized ITmfEvent parseEvent(final ITmfContext context) {
+ final ITmfContext tmpContext = context.clone();
+ final ITmfEvent event = getNextEvent(tmpContext);
+ return event;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getNextEvent(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
*/
// parseEvent() does not update the context
final ITmfEvent event = parseEvent(context);
if (event != null) {
- updateIndex(context, context.getRank(), event.getTimestamp());
+ updateAttributes(context, event.getTimestamp());
context.setLocation(getCurrentLocation());
context.increaseRank();
processEvent(event);
}
/**
- * Hook for special processing by the concrete class (called by
- * getNextEvent())
+ * Hook for special event processing by the concrete class
+ * (called by TmfTrace.getNextEvent())
*
- * @param event
+ * @param event the event
*/
protected void processEvent(final ITmfEvent event) {
- // Do nothing by default
+ // Do nothing
}
- protected synchronized void updateIndex(final ITmfContext context, final long rank, final ITmfTimestamp timestamp) {
+ /**
+ * Update the trace attributes
+ *
+ * @param context the current trace context
+ * @param rank
+ * @param timestamp
+ */
+ protected synchronized void updateAttributes(final ITmfContext context, final ITmfTimestamp timestamp) {
if (fStartTime.compareTo(timestamp, false) > 0) {
fStartTime = timestamp;
}
fEndTime = timestamp;
}
if (context.hasValidRank()) {
+ long rank = context.getRank();
if (fNbEvents <= rank) {
fNbEvents = rank + 1;
}
- // Build the index as we go along
- if ((rank % fCacheSize) == 0) {
- // Determine the table position
- final long position = rank / fCacheSize;
- // Add new entry at proper location (if empty)
- if (fCheckpoints.size() == position) {
- final ITmfLocation<?> location = context.getLocation().clone();
- fCheckpoints.add(new TmfCheckpoint(timestamp.clone(), location));
- // System.out.println(getName() + "[" + (fCheckpoints.size() + "] " + timestamp + ", " + location.toString());
- }
- }
+ fIndexer.updateIndex(context, timestamp);
}
}
// ------------------------------------------------------------------------
- // TmfProvider
+ // TmfDataProvider
// ------------------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#armRequest(org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest)
+ */
@Override
public ITmfContext armRequest(final ITmfDataRequest<T> request) {
if (request instanceof ITmfEventRequest<?>
return seekEvent(request.getIndex());
}
- /**
- * Return the next piece of data based on the context supplied. The context
- * would typically be updated for the subsequent read.
- *
- * @param context
- * @return the event referred to by context
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.component.TmfDataProvider#getNext(org.eclipse.linuxtools.tmf.core.trace.ITmfContext)
*/
@Override
@SuppressWarnings("unchecked")
// toString
// ------------------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
@Override
@SuppressWarnings("nls")
public String toString() {
// updated as we go by getNextEvent().
final ITmfEventRequest<ITmfEvent> request = new TmfEventRequest<ITmfEvent>(ITmfEvent.class, TmfTimeRange.ETERNITY,
TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
- {
+ {
ITmfTimestamp startTime = null;
ITmfTimestamp lastTime = null;
notifyListeners(startTime, lastTime);
}
}
- };
+ };
- // Submit the request and wait for completion if required
- fTrace.sendRequest(request);
- if (waitForCompletion) {
- try {
- request.waitForCompletion();
- } catch (final InterruptedException e) {
- }
- }
+ // Submit the request and wait for completion if required
+ fTrace.sendRequest(request);
+ if (waitForCompletion) {
+ try {
+ request.waitForCompletion();
+ } catch (final InterruptedException e) {
+ }
+ }
}
private void notifyListeners(final ITmfTimestamp startTime, final ITmfTimestamp endTime) {
// ITmfTraceIndexer - updateIndex
// ------------------------------------------------------------------------
+ /* (non-Javadoc)
+ * @see org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer#updateIndex(org.eclipse.linuxtools.tmf.core.trace.ITmfContext, org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp)
+ */
@Override
- public void updateIndex(final ITmfContext context, final long rank, final ITmfTimestamp timestamp) {
+ public synchronized void updateIndex(final ITmfContext context, final ITmfTimestamp timestamp) {
+ final long rank = context.getRank();
if ((rank % fCheckpointInterval) == 0) {
// Determine the table position
final long position = rank / fCheckpointInterval;
if (fTraceIndex.size() == position) {
final ITmfLocation<?> location = context.getLocation().clone();
fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), location));
- // System.out.println(getName() + "[" + (fCheckpoints.size() - 1) + "] " + timestamp + ", " + location.toString());
}
}
}
final ITmfContext savedContext = context.clone();\r
final TmfEvent event = parseEvent(context);\r
if (event != null) {\r
- updateIndex(savedContext, savedContext.getRank(), event.getTimestamp());\r
+ updateAttributes(savedContext, event.getTimestamp());\r
context.increaseRank();\r
}\r
return event;\r
final ITmfContext savedContext = context.clone();\r
final TmfEvent event = parseEvent(context);\r
if (event != null) {\r
- updateIndex(savedContext, savedContext.getRank(), event.getTimestamp());\r
+ updateAttributes(savedContext, event.getTimestamp());\r
context.increaseRank();\r
}\r
return event;\r