X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.tmf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Ftmf%2Fcore%2Ftrace%2FTmfCheckpointIndexer.java;h=0dcfa9c18b4f26370771cd7b29914f7b658d29c6;hb=d62bb1853c3388385d5ce10b0302b3dde139c3ab;hp=70bb5a1405847eebe83789a20e2b476bcee92288;hpb=3427112be14fcc0666ef1718386dd85350b32159;p=deliverable%2Ftracecompass.git
diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
index 70bb5a1405..0dcfa9c18b 100644
--- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
+++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfCheckpointIndexer.java
@@ -1,11 +1,11 @@
/*******************************************************************************
* Copyright (c) 2012 Ericsson
- *
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
+ *
* Contributors:
* Francois Chouinard - Initial API and implementation
*******************************************************************************/
@@ -20,6 +20,8 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.internal.tmf.core.trace.TmfExperimentContext;
+import org.eclipse.linuxtools.tmf.core.component.TmfDataProvider;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
@@ -31,7 +33,7 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
/**
* A simple indexer that manages the trace index as an array of trace
- * checkpoints. Checkpoints are stored at fixed intervals (event rank) in
+ * checkpoints. Checkpoints are stored at fixed intervals (event rank) in
* ascending timestamp order.
*
* The goal being to access a random trace event reasonably fast from the user's
@@ -41,21 +43,21 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal;
*
* Locating a specific checkpoint is trivial for both rank (rank % interval) and
* timestamp (bsearch in the array).
- *
+ *
* @version 1.0
* @author Francois Chouinard
*
* @see ITmfTrace
* @see ITmfEvent
*/
-public class TmfCheckpointIndexer> implements ITmfTraceIndexer {
+public class TmfCheckpointIndexer implements ITmfTraceIndexer {
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
// The event trace to index
- private final ITmfTrace fTrace;
+ protected final ITmfTrace fTrace;
// The interval between checkpoints
private final int fCheckpointInterval;
@@ -67,13 +69,13 @@ public class TmfCheckpointIndexer> implements ITm
* The trace index. It is composed of checkpoints taken at intervals of
* fCheckpointInterval events.
*/
- private final List fTraceIndex;
+ protected final List fTraceIndex;
/**
- * The indexing request
+ * The indexing request
*/
- private ITmfEventRequest fIndexingRequest = null;
-
+ private ITmfEventRequest fIndexingRequest = null;
+
// ------------------------------------------------------------------------
// Construction
// ------------------------------------------------------------------------
@@ -81,20 +83,20 @@ public class TmfCheckpointIndexer> implements ITm
/**
* Basic constructor that uses the default trace block size as checkpoints
* intervals
- *
+ *
* @param trace the trace to index
*/
- public TmfCheckpointIndexer(final ITmfTrace trace) {
- this(trace, TmfTrace.DEFAULT_BLOCK_SIZE);
+ public TmfCheckpointIndexer(final ITmfTrace trace) {
+ this(trace, TmfDataProvider.DEFAULT_BLOCK_SIZE);
}
/**
* Full trace indexer
- *
+ *
* @param trace the trace to index
* @param interval the checkpoints interval
*/
- public TmfCheckpointIndexer(final ITmfTrace trace, final int interval) {
+ public TmfCheckpointIndexer(final ITmfTrace trace, final int interval) {
fTrace = trace;
fCheckpointInterval = interval;
fTraceIndex = new ArrayList();
@@ -129,11 +131,11 @@ public class TmfCheckpointIndexer> implements ITm
// ------------------------------------------------------------------------
/* (non-Javadoc)
- *
+ *
* The index is a list of contexts that point to events at regular interval
* (rank-wise) in the trace. After it is built, the index can be used to
* quickly access any event by rank or timestamp (using seekIndex()).
- *
+ *
* The index is built simply by reading the trace
*
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfTraceIndexer#buildIndex(long, org.eclipse.linuxtools.tmf.core.event.TmfTimeRange, boolean)
@@ -141,7 +143,7 @@ public class TmfCheckpointIndexer> implements ITm
@Override
public void buildIndex(final long offset, final TmfTimeRange range, final boolean waitForCompletion) {
- // Don't do anything if we are already indexing
+ // Don't do anything if we are already indexing
synchronized (fTraceIndex) {
if (fIsIndexing) {
return;
@@ -168,22 +170,13 @@ public class TmfCheckpointIndexer> implements ITm
// Build a background request for all the trace data. The index is
// updated as we go by readNextEvent().
- fIndexingRequest = new TmfEventRequest(ITmfEvent.class,
+ fIndexingRequest = new TmfEventRequest(ITmfEvent.class,
range, offset, TmfDataRequest.ALL_DATA, fCheckpointInterval, ITmfDataRequest.ExecutionType.BACKGROUND)
{
- private ITmfTimestamp startTime = null;
- private ITmfTimestamp lastTime = null;
-
@Override
public void handleData(final ITmfEvent event) {
super.handleData(event);
if (event != null) {
- final ITmfTimestamp timestamp = event.getTimestamp();
- if (startTime == null) {
- startTime = timestamp.clone();
- }
- lastTime = timestamp.clone();
-
// Update the trace status at regular intervals
if ((getNbRead() % fCheckpointInterval) == 0) {
updateTraceStatus();
@@ -204,8 +197,8 @@ public class TmfCheckpointIndexer> implements ITm
}
private void updateTraceStatus() {
- if (getNbRead() != 0) {
- signalNewTimeRange(startTime, lastTime);
+ if (fTrace.getNbEvents() > 0) {
+ signalNewTimeRange(fTrace.getStartTime(), fTrace.getEndTime());
}
}
};
@@ -222,7 +215,7 @@ public class TmfCheckpointIndexer> implements ITm
/**
* Notify the interested parties that the trace time range has changed
- *
+ *
* @param startTime the new start time
* @param endTime the new end time
*/
@@ -245,8 +238,7 @@ public class TmfCheckpointIndexer> implements ITm
final long position = rank / fCheckpointInterval;
// Add new entry at proper location (if empty)
if (fTraceIndex.size() == position) {
- final ITmfLocation> location = context.getLocation().clone();
- fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), location));
+ fTraceIndex.add(new TmfCheckpoint(timestamp.clone(), saveContext(context)));
}
}
}
@@ -276,7 +268,7 @@ public class TmfCheckpointIndexer> implements ITm
}
// Position the trace at the checkpoint
- return seekCheckpoint(index);
+ return restoreCheckpoint(index);
}
/* (non-Javadoc)
@@ -294,17 +286,17 @@ public class TmfCheckpointIndexer> implements ITm
final int index = (int) rank / fCheckpointInterval;
// Position the trace at the checkpoint
- return seekCheckpoint(index);
+ return restoreCheckpoint(index);
}
/**
* Position the trace at the given checkpoint
- *
+ *
* @param checkpoint the checkpoint index
* @return the corresponding context
*/
- private ITmfContext seekCheckpoint(final int checkpoint) {
- ITmfLocation> location = null;
+ private ITmfContext restoreCheckpoint(final int checkpoint) {
+ ITmfLocation location = null;
int index = 0;
synchronized (fTraceIndex) {
if (!fTraceIndex.isEmpty()) {
@@ -312,7 +304,7 @@ public class TmfCheckpointIndexer> implements ITm
if (index >= fTraceIndex.size()) {
index = fTraceIndex.size() - 1;
}
- location = fTraceIndex.get(index).getLocation();
+ return restoreContext(fTraceIndex.get(index).getContext());
}
}
final ITmfContext context = fTrace.seekEvent(location);
@@ -330,4 +322,66 @@ public class TmfCheckpointIndexer> implements ITm
protected List getTraceIndex() {
return fTraceIndex;
}
+
+ // ------------------------------------------------------------------------
+ // Context conversion functions
+ // ------------------------------------------------------------------------
+
+ private static ITmfContext saveContext(ITmfContext context) {
+ if (context instanceof TmfExperimentContext) {
+ return saveExpContext(context);
+ }
+ TmfContext ctx = new TmfContext(context.getLocation(), context.getRank());
+ return ctx;
+ }
+
+ private static ITmfContext saveExpContext(ITmfContext context) {
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
+ int size = expContext.getContexts().length;
+ ITmfContext[] trcCtxts = new TmfContext[size];
+ for (int i = 0; i < size; i++) {
+ ITmfContext ctx = expContext.getContexts()[i];
+ trcCtxts[i] = (ctx != null) ? new TmfContext(ctx.getLocation(), ctx.getRank()) : null;
+ }
+ TmfExperimentContext expCtx = new TmfExperimentContext(trcCtxts);
+ expCtx.setLocation(context.getLocation());
+ expCtx.setRank(context.getRank());
+ ITmfEvent[] trcEvts = expCtx.getEvents();
+ for (int i = 0; i < size; i++) {
+ ITmfEvent event = expContext.getEvents()[i];
+ trcEvts[i] = (event != null) ? event.clone() : null;
+ }
+ return expCtx;
+ }
+
+ private ITmfContext restoreContext(ITmfContext context) {
+ if (context instanceof TmfExperimentContext) {
+ return restoreExpContext(context);
+ }
+ ITmfContext ctx = fTrace.seekEvent(context.getLocation());
+ ctx.setRank(context.getRank());
+ return ctx;
+ }
+
+ private ITmfContext restoreExpContext(ITmfContext context) {
+ TmfExperimentContext expContext = (TmfExperimentContext) context;
+ int size = expContext.getContexts().length;
+ ITmfContext[] trcCtxts = new ITmfContext[size];
+ for (int i = 0; i < size; i++) {
+ ITmfTrace trace = ((TmfExperiment) fTrace).getTraces()[i];
+ ITmfContext ctx = expContext.getContexts()[i];
+ trcCtxts[i] = trace.seekEvent(ctx.getLocation());
+ trcCtxts[i].setRank(ctx.getRank());
+ }
+ TmfExperimentContext ctx = new TmfExperimentContext(trcCtxts);
+ ctx.setLocation(context.getLocation());
+ ctx.setRank(context.getRank());
+ ITmfEvent[] trcEvts = expContext.getEvents();
+ for (int i = 0; i < size; i++) {
+ ITmfEvent event = trcEvts[i];
+ ctx.getEvents()[i] = (event != null) ? event.clone() : null;
+ }
+ return ctx;
+ }
+
}