From b73145e2d8aa6178efec22b81807eea9126631cc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Christian=20Kouam=C3=A9?= Date: Fri, 17 May 2013 12:04:01 -0400 Subject: [PATCH] CTF : Handle traces with events without eventID Bug 387039 : First, the eventID was set to null when the event was created. We change it for -2 as default value when not set. Then, we must change the way to look for packetIndexEntry to adapt it to the particular case where there are many packetIndexEntry with the same timestamp. Change-Id: Ia3bf16cc1013e41c18b5305978d1b99c30624bdc Signed-off-by: Jean-Christian Kouame Reviewed-on: https://git.eclipse.org/r/12949 Tested-by: Hudson CI IP-Clean: Alexandre Montplaisir Tested-by: Alexandre Montplaisir Reviewed-by: Alexandre Montplaisir --- .../linuxtools/ctf/core/trace/Stream.java | 10 ++++-- .../core/trace/StreamInputPacketReader.java | 2 +- .../ctf/core/event/EventDeclaration.java | 12 +++++-- .../core/trace/StreamInputPacketIndex.java | 34 +++++++++++++++---- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java index 774a95e887..4482aecb22 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Stream.java @@ -19,6 +19,7 @@ import java.util.Set; import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration; +import org.eclipse.linuxtools.internal.ctf.core.event.EventDeclaration; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** @@ -243,9 +244,12 @@ public class Stream { if (events.get(event.getId()) != null) { throw new ParseException("Event id already exists"); //$NON-NLS-1$ } - - /* Put the event in the map */ - events.put(event.getId(), event); + if (event.getId() == null) { + events.put(EventDeclaration.UNSET_EVENT_ID, event); + } else { + /* Put the event in the map */ + events.put(event.getId(), event); + } } /** diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java index 9bd42b8b71..678cb029a6 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -286,7 +286,7 @@ public class StreamInputPacketReader implements IDefinitionScope { */ public EventDefinition readNextEvent() throws CTFReaderException { /* Default values for those fields */ - long eventID = 0; + long eventID = EventDeclaration.UNSET_EVENT_ID; long timestamp = 0; if (lostEventsInThisPacket > lostSoFar) { diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java index 26b3c75d43..28f5c7e06a 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java @@ -28,6 +28,12 @@ import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader; */ public class EventDeclaration implements IEventDeclaration { + /** Id of lost events */ + public static final long LOST_EVENT_ID = -1L; + + /** Id of events when not set */ + public static final long UNSET_EVENT_ID = -2L; + // ------------------------------------------------------------------------ // Attributes // ------------------------------------------------------------------------ @@ -50,7 +56,7 @@ public class EventDeclaration implements IEventDeclaration { /** * Event id (can be null if only event in the stream). */ - private Long id = null; + private Long id = UNSET_EVENT_ID; /** * Stream to which belongs this event. @@ -100,7 +106,7 @@ public class EventDeclaration implements IEventDeclaration { public static synchronized EventDeclaration getLostEventDeclaration() { EventDeclaration lostEvent = new EventDeclaration(); lostEvent.fields = new StructDeclaration(1); - lostEvent.id = -1L; + lostEvent.id = LOST_EVENT_ID; lostEvent.name = "Lost event"; //$NON-NLS-1$ return lostEvent; } @@ -218,7 +224,7 @@ public class EventDeclaration implements IEventDeclaration { * @return is the id set? */ public boolean idIsSet() { - return id != null; + return (id != null && id != UNSET_EVENT_ID); } /** 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 14366d4547..ef74805e13 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 @@ -40,6 +40,7 @@ public class StreamInputPacketIndex { /** * Gets the entries + * * @return the entries */ public Vector getEntries() { @@ -48,6 +49,7 @@ public class StreamInputPacketIndex { /** * Gets an iterator to the entries + * * @return an iterator to the entries */ public ListIterator listIterator() { @@ -56,7 +58,9 @@ public class StreamInputPacketIndex { /** * Gets an iterator to the entries at a given position - * @param n the position to get + * + * @param n + * the position to get * @return the iterator */ public ListIterator listIterator(int n) { @@ -81,15 +85,13 @@ public class StreamInputPacketIndex { assert (entry.getContentSizeBits() != 0); if (entry.getTimestampBegin() > entry.getTimestampEnd()) { - throw new CTFReaderException( - "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$ + throw new CTFReaderException("Packet begin timestamp is after end timestamp"); //$NON-NLS-1$ } if (!this.entries.isEmpty()) { if (entry.getTimestampBegin() < this.entries.lastElement() .getTimestampBegin()) { - throw new CTFReaderException( - "Packets begin timestamp decreasing"); //$NON-NLS-1$ + throw new CTFReaderException("Packets begin timestamp decreasing"); //$NON-NLS-1$ } } @@ -119,7 +121,7 @@ public class StreamInputPacketIndex { /* * If the index is empty, return the iterator at the very beginning. */ - if( this.getEntries().isEmpty()) { + if (this.getEntries().isEmpty()) { return this.getEntries().listIterator(); } @@ -151,12 +153,30 @@ public class StreamInputPacketIndex { * the packet to return is before the guess. */ max = guessI - 1; - } else if (timestamp >= guessEntry.getTimestampBegin()) { + } else if (timestamp > guessEntry.getTimestampBegin()) { /* * If the timestamp is after the begin timestamp, we know that * the packet to return is after the guess or is the guess. */ min = guessI; + } else if (timestamp == guessEntry.getTimestampBegin()) { + /* + * If the timestamp is equal to the begin timestamp, we want to + * return the first packetIndexEntry that have this timestamp. + */ + if (guessI > 0) { + StreamInputPacketIndexEntry previousGuessEntry = this.entries.get(guessI - 1); + while (guessI > 0 && guessEntry.getTimestampBegin() == previousGuessEntry.getTimestampBegin()) { + guessEntry = previousGuessEntry; + guessI--; + if (guessI - 1 >= 0) { + previousGuessEntry = this.entries.get(guessI - 1); + } + } + min = guessI; + max = guessI; + } + } } -- 2.34.1