From 4a1108602318db28683d50e17642d73074a10c1b Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 31 May 2012 15:18:54 -0400 Subject: [PATCH] Fix ranks in CtfTmfTrace as part of bug #389051 Signed-off-by: Alexandre Montplaisir --- .../ctf/core/trace/CTFTraceReader.java | 3 -- .../core/trace/StreamInputPacketIndex.java | 7 +++++ .../tmf/core/ctfadaptor/CtfIterator.java | 5 +++- .../tmf/core/ctfadaptor/CtfTmfTrace.java | 29 +++++++++++-------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java index 42ae663ee0..08f9d181ab 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTraceReader.java @@ -245,9 +245,6 @@ public class CTFTraceReader { final long topEnd = top.getCurrentEvent().getTimestamp() + this.getTrace().getOffset(); this.setEndTime( Math.max(topEnd, this.getEndTime())); this.eventCountPerTraceFile[top.getName()]++; - /* - * increment the index - */ if (top.getCurrentEvent() != null) { this.endTime = Math.max(top.getCurrentEvent().getTimestamp(), diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java index 234b887ced..b295342b7f 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInputPacketIndex.java @@ -102,6 +102,13 @@ public class StreamInputPacketIndex { int guessI; StreamInputPacketIndexEntry guessEntry = null; + /* + * If the index is empty, return the iterator at the very beginning. + */ + if( this.getEntries().isEmpty()) { + return this.getEntries().listIterator(); + } + if (timestamp < 0) { throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$ } 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 a15b4200d8..2c2efbc1ea 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 @@ -195,7 +195,10 @@ public class CtfIterator extends CTFTraceReader implements ITmfContext, Comparab */ @Override public void increaseRank() { - curRank++; + /* Only increase the rank if it's valid */ + if(hasValidRank()) { + curRank++; + } } /** 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 c21ecbc5a1..be3f94d457 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 @@ -63,13 +63,15 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParse @Override public void initTrace(final IResource resource, final String path, final Class 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); EventDeclaration ed; ITmfEventField eventField; - // Set the cache size - setCacheSize(); - @SuppressWarnings("unused") CtfTmfEventType type; @@ -92,12 +94,6 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParse this.setStartTime(TmfTimestamp.BIG_BANG); } else { this.setStartTime(iterator.getCurrentEvent().getTimestamp()); - /* - * is the trace empty - */ - if( iterator.hasMoreEvents()){ - iterator.goToLastEvent(); - } this.setEndTime(iterator.getCurrentEvent().getTimestamp()); } @@ -172,16 +168,22 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParse @Override public ITmfContext seekEvent(final ITmfLocation location) { CtfLocation currentLocation = (CtfLocation) location; + CtfIterator context = new CtfIterator(this); + /* + * The rank is set to 0 if the iterator seeks the beginning. If not, it + * will be set to UNKNOWN_RANK, since CTF traces don't support seeking + * by rank for now. + */ if (currentLocation == null) { currentLocation = new CtfLocation(0L); + context.setRank(0); } - CtfIterator context = new CtfIterator(this); - if (currentLocation.getLocation() == CtfLocation.INVALID_LOCATION) { ((CtfTmfTimestamp) getEndTime()).setType(TimestampType.NANOS); currentLocation.setLocation(getEndTime().getValue() + 1); } context.setLocation(currentLocation); + if(context.getRank() != 0) context.setRank(ITmfContext.UNKNOWN_RANK); return context; } @@ -207,11 +209,14 @@ public class CtfTmfTrace extends TmfTrace implements ITmfEventParse if (context instanceof CtfIterator) { CtfIterator ctfIterator = (CtfIterator) context; event = ctfIterator.getCurrentEvent(); - ctfIterator.advance(); + if (event != null) { updateAttributes(context, event.getTimestamp()); + ctfIterator.advance(); + ctfIterator.increaseRank(); } } + return event; } -- 2.34.1