import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTimestamp.TimestampType;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
-import org.eclipse.linuxtools.tmf.core.statesystem.IStateSystemQuerier;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
import org.eclipse.linuxtools.tmf.core.trace.ITmfEventParser;
import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
* @version 1.0
* @author Matthew khouzam
*/
-public class CtfTmfTrace extends TmfTrace<CtfTmfEvent> implements ITmfEventParser<CtfTmfEvent>{
+public class CtfTmfTrace extends TmfTrace implements ITmfEventParser {
//-------------------------------------------
//-------------------------------------------
/** Reference to the state system assigned to this trace */
- protected IStateSystemQuerier ss = null;
+ protected ITmfStateSystem ss = null;
/* Reference to the CTF Trace */
private CTFTrace fTrace;
* If something when wrong while reading the trace
*/
@Override
- public void initTrace(final IResource resource, final String path, final Class<CtfTmfEvent> eventType)
+ public void initTrace(final IResource resource, final String path, final Class<? extends ITmfEvent> eventType)
throws TmfTraceException {
/*
* Set the cache size. This has to be done before the call to super()
* because the super needs to know the cache size.
*/
setCacheSize();
- super.initTrace(resource, path, eventType);
@SuppressWarnings("unused")
CtfTmfEventType type;
CtfIteratorManager.addTrace(this);
CtfTmfLightweightContext ctx;
/* Set the start and (current) end times for this trace */
- ctx = new CtfTmfLightweightContext(this);
- ctx.setLocation(new CtfLocation(0L));
+ ctx = (CtfTmfLightweightContext) seekEvent(0L);
+ CtfTmfEvent event = getNext(ctx);
if((ctx.getLocation().equals(CtfIterator.NULL_LOCATION)) || (ctx.getCurrentEvent() == null)) {
/* Handle the case where the trace is empty */
this.setStartTime(TmfTimestamp.BIG_BANG);
} else {
- final ITmfTimestamp curTime = ctx.getCurrentEvent().getTimestamp();
+ final ITmfTimestamp curTime = event.getTimestamp();
this.setStartTime(curTime);
this.setEndTime(curTime);
}
throw new TmfTraceException(e.getMessage(), e);
}
+ super.initTrace(resource, path, eventType);
+
//FIXME This should be called via the ExperimentUpdated signal
buildStateSystem();
* @see org.eclipse.linuxtools.tmf.core.trace.ITmfTrace#getCurrentLocation()
*/
@Override
- public ITmfLocation<?> getCurrentLocation() {
+ public ITmfLocation getCurrentLocation() {
return null;
}
@Override
- public double getLocationRatio(ITmfLocation<?> location) {
+ public double getLocationRatio(ITmfLocation location) {
final CtfLocation curLocation = (CtfLocation) location;
final CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
context.setLocation(curLocation);
- context.seek(curLocation.getLocation());
- final long currentTime = ((Long)context.getLocation().getLocation());
+ context.seek(curLocation.getLocationInfo());
+ final CtfLocationData currentTime = ((CtfLocationData)context.getLocation().getLocationInfo());
final long startTime = getIterator(this, context).getStartTime();
final long endTime = getIterator(this, context).getEndTime();
- return ((double) currentTime - startTime)
+ return ((double) currentTime.getTimestamp() - startTime)
/ (endTime - startTime);
}
* @return ITmfContext
*/
@Override
- public ITmfContext seekEvent(final ITmfLocation<?> location) {
+ public ITmfContext seekEvent(final ITmfLocation location) {
CtfLocation currentLocation = (CtfLocation) location;
CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
/*
* by rank for now.
*/
if (currentLocation == null) {
- currentLocation = new CtfLocation(0L);
+ currentLocation = new CtfLocation(new CtfLocationData(0L, 0L));
context.setRank(0);
}
- if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) {
+ if (currentLocation.getLocationInfo() == CtfLocation.INVALID_LOCATION) {
((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS);
- currentLocation.setLocation(getEndTime().getValue() + 1);
+ currentLocation = new CtfLocation(getEndTime().getValue() + 1, 0L);
}
context.setLocation(currentLocation);
+ if (location == null) {
+ CtfTmfEvent event = getIterator(this, context).getCurrentEvent();
+ if (event != null) {
+ currentLocation = new CtfLocation(event.getTimestamp().getValue(), 0);
+ }
+ }
if(context.getRank() != 0) {
context.setRank(ITmfContext.UNKNOWN_RANK);
}
@Override
public ITmfContext seekEvent(double ratio) {
CtfTmfLightweightContext context = new CtfTmfLightweightContext(this);
- context.seek(Math.round(this.getNbEvents() * ratio));
+ final long end = this.getEndTime().getValue();
+ final long start = this.getStartTime().getValue();
+ final long diff = end - start;
+ final long ratioTs = Math.round(diff * ratio) + start;
+ context.seek(ratioTs);
context.setRank(ITmfContext.UNKNOWN_RANK);
return context;
}
public synchronized CtfTmfEvent getNext(final ITmfContext context) {
CtfTmfEvent event = null;
if (context instanceof CtfTmfLightweightContext) {
- if (CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocation())) {
+ if (CtfLocation.INVALID_LOCATION.equals(context.getLocation().getLocationInfo())) {
return null;
}
CtfTmfLightweightContext ctfContext = (CtfTmfLightweightContext) context;
}
/**
- * Method getStateSystem.
- *
- * @return IStateSystemQuerier
+ * @since 2.0
*/
- public IStateSystemQuerier getStateSystem() {
+ @Override
+ public ITmfStateSystem getStateSystem() {
return this.ss;
}