From 57c073c5eb25dd8ef3d591acdfc096b405261213 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Tue, 1 May 2012 16:35:56 -0400 Subject: [PATCH] fix empty trace bug Signed-off-by: Matthew Khouzam --- .../tmf/core/ctfadaptor/CtfIterator.java | 71 +++++++++++++------ .../tmf/core/ctfadaptor/CtfLocation.java | 2 + .../tmf/core/ctfadaptor/CtfTmfTrace.java | 9 ++- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java index 751bc0a257..2435244398 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIterator.java @@ -6,10 +6,12 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfContext; import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; public class CtfIterator extends CTFTraceReader implements ITmfContext, -Comparable { + Comparable { private final CtfTmfTrace ctfTmfTrace; + final public static CtfLocation nullLocation = new CtfLocation( + CtfLocation.INVALID_LOCATION); private CtfLocation curLocation; private long curRank; @@ -22,21 +24,39 @@ Comparable { public CtfIterator(final CtfTmfTrace trace) { super(trace.getCTFTrace()); this.ctfTmfTrace = trace; + if (this.hasMoreEvents()) { - // FIXME put the real stuff here... - this.curLocation = new CtfLocation(trace.getStartTime()); - this.curRank = 0; + this.curLocation = new CtfLocation(trace.getStartTime()); + this.curRank = 0; + } else { + setUnknownLocation(); + } } - public CtfIterator(final CtfTmfTrace trace, final long timestampValue, final long rank) { + /** + * + */ + private void setUnknownLocation() { + this.curLocation = nullLocation; + this.curRank = UNKNOWN_RANK; + } + + public CtfIterator(final CtfTmfTrace trace, final long timestampValue, + final long rank) { super(trace.getCTFTrace()); + this.ctfTmfTrace = trace; - this.curLocation = (new CtfLocation(this.getCurrentEvent() - .getTimestampValue())); - if (this.getCurrentEvent().getTimestampValue() != timestampValue) - this.seek(timestampValue); + if (this.hasMoreEvents()) { + this.curLocation = (new CtfLocation(this.getCurrentEvent() + .getTimestampValue())); + if (this.getCurrentEvent().getTimestampValue() != timestampValue) { + this.seek(timestampValue); + this.curRank = rank; + } + } else { + setUnknownLocation(); + } - this.curRank = rank; } public CtfTmfTrace getCtfTmfTrace() { @@ -45,22 +65,27 @@ Comparable { public CtfTmfEvent getCurrentEvent() { final StreamInputReader top = super.prio.peek(); - if (top != null) - return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace); + if (top != null) { + return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), + ctfTmfTrace); + } return null; } @Override public boolean seek(final long timestamp) { boolean ret = false; - final long offsetTimestamp = timestamp - this.getCtfTmfTrace().getCTFTrace().getOffset(); - if( offsetTimestamp < 0 ) + final long offsetTimestamp = timestamp + - this.getCtfTmfTrace().getCTFTrace().getOffset(); + if (offsetTimestamp < 0) { ret = super.seek(timestamp); - else + } else { ret = super.seek(offsetTimestamp); + } - if (ret) + if (ret) { curLocation.setLocation(getCurrentEvent().getTimestampValue()); + } return ret; } @@ -68,8 +93,9 @@ Comparable { boolean ret = false; ret = super.seekIndex(rank); - if (ret) + if (ret) { curLocation.setLocation(getCurrentEvent().getTimestampValue()); + } return ret; } @@ -80,7 +106,9 @@ Comparable { @Override public void setRank(final long rank) { - seekRank(rank); + if(!this.curLocation.equals(nullLocation)) { + seekRank(rank); + } } /* @@ -106,7 +134,7 @@ Comparable { public void setLocation(final ITmfLocation location) { // FIXME alex: isn't there a cleaner way than a cast here? this.curLocation = (CtfLocation) location; - seek(((CtfLocation)location).getLocation()); + seek(((CtfLocation) location).getLocation()); } @Override @@ -131,10 +159,11 @@ Comparable { @Override public int compareTo(final CtfIterator o) { - if (this.getRank() < o.getRank()) + if (this.getRank() < o.getRank()) { return -1; - else if (this.getRank() > o.getRank()) + } else if (this.getRank() > o.getRank()) { return 1; + } return 0; } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java index e935ebdc71..4c7ebb1d04 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfLocation.java @@ -5,6 +5,8 @@ import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation; public class CtfLocation implements ITmfLocation { + public static final Long INVALID_LOCATION = -1L; + public CtfLocation(Long location) { setLocation(location); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java index 9ec3d43e55..b44a028348 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfTrace.java @@ -75,7 +75,10 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr throw new TmfTraceException(e.getMessage()); } this.iterator = new CtfIterator(this, 0, 0); - setStartTime(iterator.getCurrentEvent().getTimestamp()); + setStartTime(TmfTimestamp.BIG_BANG); + if( !this.iterator.getLocation().equals(CtfIterator.nullLocation)) { + setStartTime(iterator.getCurrentEvent().getTimestamp()); + } TmfSignalManager.register(this); // this.currLocation.setTimestamp(this.fEvent.getTimestamp().getValue()); // this.fStartTime = new TmfSimpleTimestamp(this.currLocation @@ -266,7 +269,9 @@ public class CtfTmfTrace extends TmfEventProvider implements ITmfTr if (currentLocation == null) { currentLocation = new CtfLocation(0L); } - iterator.setLocation(currentLocation); + if( !iterator.getLocation().equals(CtfIterator.nullLocation)) { + iterator.setLocation(currentLocation); + } return iterator; } -- 2.34.1