From cf9a28dad5c4aa68903345439f9466407a3cd666 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Wed, 27 Nov 2013 17:18:54 -0500 Subject: [PATCH] ctf: support traces with no content but a packet size Change-Id: I979e3826580db246263cfcb219ee7f9cba968922 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/19023 Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir Tested-by: Hudson CI --- .../ctf/core/trace/StreamInput.java | 20 +++++++++++-------- .../core/trace/StreamInputPacketReader.java | 12 +++++------ .../ctf/core/trace/StreamInputReader.java | 17 ++++++---------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java index b8bd2f9113..3ee9963ed4 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInput.java @@ -35,6 +35,7 @@ import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntr * StreamInput *

* Represents a trace file that belongs to a certain stream. + * * @since 2.0 */ public class StreamInput implements IDefinitionScope { @@ -124,8 +125,7 @@ public class StreamInput implements IDefinitionScope { } /** - * Gets the filechannel of the streamInput. This is a limited Java - * resource. + * Gets the filechannel of the streamInput. This is a limited Java resource. * * @return the filechannel */ @@ -245,7 +245,10 @@ public class StreamInput implements IDefinitionScope { StructDefinition streamPacketContextDef, BitBuffer bitBuffer) throws CTFReaderException { - /* Ignoring the return value, but this call is needed to initialize the input */ + /* + * Ignoring the return value, but this call is needed to initialize the + * input + */ createPacketBitBuffer(fileSizeBytes, packetOffsetBytes, packetIndex, bitBuffer); /* @@ -272,8 +275,7 @@ public class StreamInput implements IDefinitionScope { if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex .getOffsetBytes()) * 8)) { - throw new CTFReaderException( - "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$ + throw new CTFReaderException("Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$ } /* @@ -383,8 +385,7 @@ public class StreamInput implements IDefinitionScope { long streamID = streamIDDef.getValue(); if (streamID != getStream().getId()) { - throw new CTFReaderException( - "Stream ID changing within a StreamInput"); //$NON-NLS-1$ + throw new CTFReaderException("Stream ID changing within a StreamInput"); //$NON-NLS-1$ } } } @@ -429,15 +430,18 @@ public class StreamInput implements IDefinitionScope { String device = (String) packetIndex.lookupAttribute("device"); //$NON-NLS-1$ // LTTng Specific Long cpuId = (Long) packetIndex.lookupAttribute("cpu_id"); //$NON-NLS-1$ - Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$ + Long lostEvents = (Long) packetIndex.lookupAttribute("events_discarded"); //$NON-NLS-1$ /* Read the content size in bits */ if (contentSize != null) { packetIndex.setContentSizeBits(contentSize.intValue()); + } else if (packetSize != null) { + packetIndex.setContentSizeBits(packetSize.longValue()); } else { packetIndex.setContentSizeBits((int) (fileSizeBytes * 8)); } + /* Read the packet size in bits */ if (packetSize != null) { packetIndex.setPacketSizeBits(packetSize.intValue()); 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 257cedf5d7..ca847195e6 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 @@ -223,11 +223,7 @@ public class StreamInputPacketReader implements IDefinitionScope { this.currentPacket.getOffsetBytes(), (this.currentPacket.getPacketSizeBits() + 7) / 8); } catch (IOException e) { - /* - * The streamInputReader object is already allocated, so this - * shouldn't fail bar some very bad kernel or RAM errors... - */ - e.printStackTrace(); + throw new CTFReaderException(e.getMessage(), e); } bitBuffer.setByteBuffer(bb); @@ -318,7 +314,7 @@ public class StreamInputPacketReader implements IDefinitionScope { final StructDefinition sehd = streamEventHeaderDef; final BitBuffer currentBitBuffer = bitBuffer; - + final long posStart = currentBitBuffer.position(); /* Read the stream event header. */ if (sehd != null) { sehd.read(currentBitBuffer); @@ -394,6 +390,10 @@ public class StreamInputPacketReader implements IDefinitionScope { */ eventDef.setTimestamp(timestamp); + if (posStart == currentBitBuffer.position()) { + throw new CTFReaderException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$ + } + return eventDef; } diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java index c92c5d7f4a..468ade788a 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputReader.java @@ -243,15 +243,10 @@ public class StreamInputReader { if (getPacketSize() >= (packetIndex + 1)) { this.packetReader.setCurrentPacket(getPacket()); } else { - try { - if (this.streamInput.addPacketHeaderIndex()) { - packetIndex = getPacketSize() - 1; - this.packetReader.setCurrentPacket(getPacket()); - } else { - this.packetReader.setCurrentPacket(null); - } - - } catch (CTFReaderException e) { + if (this.streamInput.addPacketHeaderIndex()) { + packetIndex = getPacketSize() - 1; + this.packetReader.setCurrentPacket(getPacket()); + } else { this.packetReader.setCurrentPacket(null); } } @@ -298,8 +293,8 @@ public class StreamInputReader { /* * Advance until either of these conditions are met *

    - *
  • reached the end of the trace file (the given timestamp is after the last event),
  • - *
  • found the first event with a timestamp greater or equal the given timestamp.
  • + *
  • reached the end of the trace file (the given timestamp is after the last event),
  • + *
  • found the first event with a timestamp greater or equal the given timestamp.
  • *
*/ readNextEvent(); -- 2.34.1