diff options
author | Alexandre Montplaisir | 2012-08-09 20:26:00 +0000 |
---|---|---|
committer | Alexandre Montplaisir | 2012-08-15 18:46:11 +0000 |
commit | 56431d7b01633456204bef22df590af5b1023e26 (patch) | |
tree | a765d4e4992110b6e6063d0ec9c8d66259ceb73f /lttng/org.eclipse.linuxtools.ctf.core | |
parent | 8906f97969591fc16c2ad34f72c4f4034fe7f655 (diff) | |
download | org.eclipse.linuxtools-56431d7b01633456204bef22df590af5b1023e26.tar.gz org.eclipse.linuxtools-56431d7b01633456204bef22df590af5b1023e26.tar.xz org.eclipse.linuxtools-56431d7b01633456204bef22df590af5b1023e26.zip |
ctf: Handle absence of stream and event IDs
As per the CTF spec, a trace could define no stream_id field
in its packet headers. In such a case, the parser should assign
it ID 0.
Similarly, if only one event type is present, the event id field
is optional, and 0 should be used if it's not explicitely set.
Partially fixes bug #387039
Change-Id: I38dcdbdefc6c18a16b2ad8fb9ad6135303da208f
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/7203
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
Diffstat (limited to 'lttng/org.eclipse.linuxtools.ctf.core')
3 files changed, 44 insertions, 66 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java index eac8cb87fb..2404de4cbe 100644 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -569,18 +569,17 @@ public class CTFTrace implements IDefinitionScope { } } - /* Read stream ID */ - // TODO: it hasn't been checked that the stream_id field exists and - // is an unsigned - // integer - IntegerDefinition streamIDDef = (IntegerDefinition) packetHeaderDef - .lookupDefinition("stream_id"); //$NON-NLS-1$ - assert (streamIDDef != null); - - long streamID = streamIDDef.getValue(); - - /* Get the stream to which this trace file belongs to */ - stream = streams.get(streamID); + /* Read the stream ID */ + Definition streamIDDef = packetHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$ + + if (streamIDDef instanceof IntegerDefinition) { //this doubles as a null check + long streamID = ((IntegerDefinition) streamIDDef).getValue(); + stream = streams.get(streamID); + } else { + /* No stream_id in the packet header */ + stream = streams.get(null); + } + } else { /* No packet header, we suppose there is only one stream */ stream = streams.get(null); diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java index 0e301b0b8a..565a68095b 100644 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java +++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java @@ -333,98 +333,77 @@ public class StreamInputPacketReader implements IDefinitionScope { * If there was a problem reading the trace */ public EventDefinition readNextEvent() throws CTFReaderException { - /* WARNING: This is still LTTng-specific. */ - Long eventID = null; + /* Default values for those fields */ + long eventID = 0; long timestamp = 0; if (lostEventsInThisPacket > lostSoFar) { - EventDefinition eventDef = EventDeclaration - .getLostEventDeclaration().createDefinition( - streamInputReader); + EventDefinition eventDef = EventDeclaration.getLostEventDeclaration().createDefinition( + streamInputReader); eventDef.setTimestamp(this.lastTimestamp); ++lostSoFar; return eventDef; } - StructDefinition sehd = getStreamEventHeaderDef(); // acronym for a long - // variable name - BitBuffer currentBitBuffer = getBitBuffer(); - /* - * Read the stream event header. - */ + final StructDefinition sehd = getStreamEventHeaderDef(); + final BitBuffer currentBitBuffer = getBitBuffer(); + /* Read the stream event header. */ if (sehd != null) { sehd.read(currentBitBuffer); - /* - * Check for an event id. - */ - SimpleDatatypeDefinition idDef = (SimpleDatatypeDefinition) sehd - .lookupDefinition("id"); //$NON-NLS-1$ - IntegerDefinition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$ - eventID = idDef.getIntegerValue(); + /* Check for the event id. */ + Definition idDef = sehd.lookupDefinition("id"); //$NON-NLS-1$ + if (idDef instanceof SimpleDatatypeDefinition) { + eventID = ((SimpleDatatypeDefinition) idDef).getIntegerValue(); + } // else, eventID remains 0 - /* - * Check for the variant v. - */ - VariantDefinition variantDef = (VariantDefinition) sehd - .lookupDefinition("v"); //$NON-NLS-1$ + /* Get the timestamp from the event header (may be overridden later on) */ + Definition timestampDef = sehd.lookupInteger("timestamp"); //$NON-NLS-1$ + + /* Check for the variant v. */ + VariantDefinition variantDef = (VariantDefinition) sehd.lookupDefinition("v"); //$NON-NLS-1$ if (variantDef != null) { - /* - * Get the variant current field - */ - StructDefinition variantCurrentField = (StructDefinition) variantDef - .getCurrentField(); + /* Get the variant current field */ + StructDefinition variantCurrentField = (StructDefinition) variantDef.getCurrentField(); /* * Try to get the id field in the current field of the variant. * If it is present, it overrides the previously read event id. */ - IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField - .lookupDefinition("id"); //$NON-NLS-1$ + IntegerDefinition idIntegerDef = (IntegerDefinition) variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$ if (idIntegerDef != null) { eventID = idIntegerDef.getValue(); } - /* - * Get the timestamp. - */ - timestampDef = (IntegerDefinition) variantCurrentField - .lookupDefinition("timestamp"); //$NON-NLS-1$ + /* Get the timestamp. */ + timestampDef = variantCurrentField.lookupDefinition("timestamp"); //$NON-NLS-1$ } - /* - * Calculate the event timestamp. - */ - timestamp = calculateTimestamp(timestampDef); + /* Calculate the event timestamp. */ + if (timestampDef instanceof IntegerDefinition) { + timestamp = calculateTimestamp((IntegerDefinition) timestampDef); + } // else timestamp remains 0 } - /* - * Read the stream event context. - */ - if (getStreamEventContextDef() != null) { - getStreamEventContextDef().read(currentBitBuffer); + /* Read the stream event context. */ + if (streamEventContextDef != null) { + streamEventContextDef.read(currentBitBuffer); } - /* - * Get the right event definition using the event id. - */ + /* Get the right event definition using the event id. */ EventDefinition eventDef = events.get(eventID); if (eventDef == null) { throw new CTFReaderException("Incorrect event id : " + eventID); //$NON-NLS-1$ } - /* - * Read the event context. - */ + /* Read the event context. */ if (eventDef.getContext() != null) { eventDef.getContext().read(currentBitBuffer); } - /* - * Read the event fields. - */ + /* Read the event fields. */ if (eventDef.getFields() != null) { eventDef.getFields().read(currentBitBuffer); } diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java index b431a0fb88..fd7baefc0f 100644 --- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java +++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/trace/StreamInput.java @@ -97,7 +97,7 @@ public class StreamInput implements IDefinitionScope { this.stream = stream; this.fileChannel = fileChannel; this.file = file; - index = stream.getTrace().getIndex(this); + this.index = stream.getTrace().getIndex(this); } // ------------------------------------------------------------------------ |