private final ICompositeDefinition fFields;
/**
- * The cpu number of the event, can be UNKNOWN
+ * The current cpu, could be @link {@link IPacketHeader#UNKNOWN_CPU}
*/
private final int fCpu;
* @param eventContext
* The event context
* @param packetContext
- * the packet context
+ * the packet context (the one with content size, not magic number)
* @param streamContext
* the stream context
* @param fields
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
* Get all the event declarations in this stream.
*
* @return The event declarations for this stream
+ * @since 2.0
*/
- public @NonNull Collection<@NonNull IEventDeclaration> getEventDeclarations() {
- List<@NonNull IEventDeclaration> retVal = new ArrayList<>();
- for (IEventDeclaration eventDeclaration : fEvents) {
- if (eventDeclaration != null) {
- retVal.add(eventDeclaration);
- }
- }
- return retVal;
+ public @NonNull List<IEventDeclaration> getEventDeclarations() {
+ return NonNullUtils.checkNotNull(Collections.unmodifiableList(fEvents));
}
/**
BitBuffer bitBuffer) throws CTFException {
ICTFPacketDescriptor packetIndex;
StructDefinition streamPacketContextDef = fStreamPacketContextDecl.createDefinition(this, ILexicalScope.STREAM_PACKET_CONTEXT, bitBuffer);
- packetIndex = new StreamInputPacketIndexEntry(dataOffsetBits, streamPacketContextDef, fileSizeBytes, fLostSoFar);
+ packetIndex = new StreamInputPacketIndexEntry(dataOffsetBits, streamPacketContextDef, fileSizeBytes, fLostSoFar, bitBuffer.position());
fLostSoFar = packetIndex.getLostEvents() + fLostSoFar;
setTimestampEnd(packetIndex.getTimestampEnd());
return packetIndex;
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011, 2015 Ericsson, Ecole Polytechnique de Montreal and others
- *
- * All rights reserved. This program and the accompanying materials are made
- * available under the terms of the Eclipse Public License v1.0 which
- * accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Matthew Khouzam - Initial API and implementation
- * Simon Marchi - Initial API and implementation
- * Patrick Tasse - Bug 470754 - Incorrect time range in CTF Lost Event
- *******************************************************************************/
-package org.eclipse.tracecompass.ctf.core.trace;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.FileChannel.MapMode;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.eclipse.tracecompass.ctf.core.CTFException;
-import org.eclipse.tracecompass.ctf.core.CTFStrings;
-import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
-import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
-import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
-import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
-import org.eclipse.tracecompass.ctf.core.event.scope.LexicalScope;
-import org.eclipse.tracecompass.ctf.core.event.types.Definition;
-import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IEventHeaderDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.SimpleDatatypeDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
-import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
-import org.eclipse.tracecompass.internal.ctf.core.SafeMappedByteBuffer;
-import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
-import org.eclipse.tracecompass.internal.ctf.core.event.types.composite.EventHeaderDefinition;
-
-/**
- * CTF trace packet reader. Reads the events of a packet of a trace file.
- *
- * @author Matthew Khouzam
- * @author Simon Marchi
- */
-public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseable {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private static final int BITS_PER_BYTE = Byte.SIZE;
-
- private static final IDefinitionScope EVENT_HEADER_SCOPE = new IDefinitionScope() {
-
- @Override
- public IDefinition lookupDefinition(String lookupPath) {
- return null;
- }
-
- @Override
- public ILexicalScope getScopePath() {
- return null;
- }
- };
-
- /** BitBuffer used to read the trace file. */
- @Nullable
- private BitBuffer fBitBuffer;
-
- /** StreamInputReader that uses this StreamInputPacketReader. */
- private final CTFStreamInputReader fStreamInputReader;
-
- /** Trace packet header. */
- private final StructDeclaration fTracePacketHeaderDecl;
-
- /** Stream packet context definition. */
- private final StructDeclaration fStreamPacketContextDecl;
-
- /** Stream event header definition. */
- private final IDeclaration fStreamEventHeaderDecl;
-
- /** Stream event context definition. */
- private final StructDeclaration fStreamEventContextDecl;
-
- private ICompositeDefinition fCurrentTracePacketHeaderDef;
- private ICompositeDefinition fCurrentStreamEventHeaderDef;
- private ICompositeDefinition fCurrentStreamPacketContextDef;
- /** Reference to the index entry of the current packet. */
- private ICTFPacketDescriptor fCurrentPacket = null;
-
- /**
- * Last timestamp recorded.
- *
- * Needed to calculate the complete timestamp values for the events with
- * compact headers.
- */
- private long fLastTimestamp = 0;
-
- /** CPU id of current packet. */
- private int fCurrentCpu = 0;
-
- private int fLostEventsInThisPacket;
-
- private boolean fHasLost = false;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Constructs a StreamInputPacketReader.
- *
- * @param streamInputReader
- * The StreamInputReader to which this packet reader belongs to.
- */
- public CTFStreamInputPacketReader(CTFStreamInputReader streamInputReader) {
- fStreamInputReader = streamInputReader;
-
- /* Set the BitBuffer's byte order. */
- ByteBuffer allocateDirect = ByteBuffer.allocateDirect(0);
- if (allocateDirect == null) {
- throw new IllegalStateException("Unable to allocate 0 bytes!"); //$NON-NLS-1$
- }
- fBitBuffer = new BitBuffer(allocateDirect);
-
- final CTFStream currentStream = streamInputReader.getStreamInput().getStream();
- fTracePacketHeaderDecl = currentStream.getTrace().getPacketHeader();
- fStreamPacketContextDecl = currentStream.getPacketContextDecl();
- fStreamEventHeaderDecl = currentStream.getEventHeaderDeclaration();
- fStreamEventContextDecl = currentStream.getEventContextDecl();
- }
-
- /**
- * Get the event context defintiion
- *
- * @param input
- * the bitbuffer to read from
- * @return an context definition, can be null
- * @throws CTFException
- * out of bounds exception or such
- */
- public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFException {
- return fStreamEventContextDecl.createDefinition(fStreamInputReader.getStreamInput(), ILexicalScope.STREAM_EVENT_CONTEXT, input);
- }
-
- /**
- * Get the packet context defintiion
- *
- * @param input
- * the bitbuffer to read from
- * @return an context definition, can be null
- * @throws CTFException
- * out of bounds exception or such
- */
- public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFException {
- return fStreamPacketContextDecl.createDefinition(fStreamInputReader.getStreamInput(), ILexicalScope.STREAM_PACKET_CONTEXT, input);
- }
-
- /**
- * Get the event header defintiion
- *
- * @param input
- * the bitbuffer to read from
- * @return an header definition, can be null
- * @throws CTFException
- * out of bounds exception or such
- */
- public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFException {
- return fTracePacketHeaderDecl.createDefinition(fStreamInputReader.getStreamInput().getStream().getTrace(), ILexicalScope.TRACE_PACKET_HEADER, input);
- }
-
- /**
- * Dispose the StreamInputPacketReader
- */
- @Override
- public void close() {
- fBitBuffer = null;
- }
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- /**
- * Gets the current packet
- *
- * @return the current packet
- */
- ICTFPacketDescriptor getCurrentPacket() {
- return fCurrentPacket;
- }
-
- /**
- * Gets the CPU (core) number
- *
- * @return the CPU (core) number
- */
- public int getCPU() {
- return fCurrentCpu;
- }
-
- @Override
- public LexicalScope getScopePath() {
- return ILexicalScope.PACKET;
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- @NonNull
- private ByteBuffer getByteBufferAt(long position, long size) throws CTFException, IOException {
- ByteBuffer map = SafeMappedByteBuffer.map(fStreamInputReader.getFc(), MapMode.READ_ONLY, position, size);
- if (map == null) {
- throw new CTFIOException("Failed to allocate mapped byte buffer"); //$NON-NLS-1$
- }
- return map;
- }
-
- /**
- * Changes the current packet to the given one.
- *
- * @param currentPacket
- * The index entry of the packet to switch to.
- * @throws CTFException
- * If we get an error reading the packet
- * @since 1.0
- */
- public void setCurrentPacket(ICTFPacketDescriptor currentPacket) throws CTFException {
- fCurrentPacket = currentPacket;
- fHasLost = false;
-
- if (fCurrentPacket != null) {
- /*
- * Change the map of the BitBuffer.
- */
- ByteBuffer bb = null;
- try {
- bb = getByteBufferAt(fCurrentPacket.getOffsetBytes(), (fCurrentPacket.getPacketSizeBits() + BITS_PER_BYTE - 1) / BITS_PER_BYTE);
- } catch (IOException e) {
- throw new CTFIOException(e.getMessage(), e);
- }
-
- BitBuffer bitBuffer = new BitBuffer(bb);
- fBitBuffer = bitBuffer;
- /*
- * Read trace packet header.
- */
- if (fTracePacketHeaderDecl != null) {
- fCurrentTracePacketHeaderDef = getTracePacketHeaderDefinition(bitBuffer);
- }
-
- /*
- * Read stream packet context.
- */
- if (fStreamPacketContextDecl != null) {
- fCurrentStreamPacketContextDef = getStreamPacketContextDefinition(bitBuffer);
-
- /* Read CPU ID */
- if (getCurrentPacket().getTarget() != null) {
- fCurrentCpu = (int) getCurrentPacket().getTargetId();
- }
-
- /* Read number of lost events */
- fLostEventsInThisPacket = (int) getCurrentPacket().getLostEvents();
- if (fLostEventsInThisPacket != 0) {
- fHasLost = true;
- }
- }
-
- /*
- * Use the timestamp begin of the packet as the reference for the
- * timestamp reconstitution.
- */
- fLastTimestamp = Math.max(currentPacket.getTimestampBegin(), 0);
- } else {
- fBitBuffer = null;
- fLastTimestamp = 0;
- }
- }
-
- /**
- * Returns whether it is possible to read any more events from this packet.
- *
- * @return True if it is possible to read any more events from this packet.
- */
- public boolean hasMoreEvents() {
- BitBuffer bitBuffer = fBitBuffer;
- ICTFPacketDescriptor currentPacket = fCurrentPacket;
- if (currentPacket != null && bitBuffer != null) {
- return fHasLost || (bitBuffer.position() < currentPacket.getContentSizeBits());
- }
- return false;
- }
-
- /**
- * Reads the next event of the packet into the right event definition.
- *
- * @return The event definition containing the event data that was just
- * read.
- * @throws CTFException
- * If there was a problem reading the trace
- */
- public EventDefinition readNextEvent() throws CTFException {
- /* Default values for those fields */
- // compromise since we cannot have 64 bit addressing of arrays yet.
- int eventID = (int) IEventDeclaration.UNSET_EVENT_ID;
- final BitBuffer currentBitBuffer = fBitBuffer;
- final ICTFPacketDescriptor currentPacket = fCurrentPacket;
- if (currentBitBuffer == null || currentPacket == null) {
- return null;
- }
- final long posStart = currentBitBuffer.position();
- /*
- * Return the Lost Event after all other events in this packet.
- */
- if (fHasLost && posStart >= currentPacket.getContentSizeBits()) {
- fHasLost = false;
- IEventDeclaration lostEventDeclaration = LostEventDeclaration.INSTANCE;
- StructDeclaration lostFields = lostEventDeclaration.getFields();
- // this is a hard coded map, we know it's not null
- IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_FIELD);
- if (lostFieldsDecl == null)
- {
- throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$
- }
- IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_DURATION);
- if (lostEventsDurationDecl == null) {
- throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$
- }
- long lostEventsTimestamp = fLastTimestamp;
- long lostEventsDuration = currentPacket.getTimestampEnd() - lostEventsTimestamp;
- IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, lostEventsDuration);
- IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fLostEventsInThisPacket);
- IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
- return new EventDefinition(
- lostEventDeclaration,
- fStreamInputReader.getCPU(),
- lostEventsTimestamp,
- null,
- null,
- null,
- null,
- new StructDefinition(
- lostFields,
- this, "fields", //$NON-NLS-1$
- fields
- ));
-
- }
-
- /* Read the stream event header. */
- if (fStreamEventHeaderDecl != null) {
- if (fStreamEventHeaderDecl instanceof IEventHeaderDeclaration) {
- fCurrentStreamEventHeaderDef = (ICompositeDefinition) fStreamEventHeaderDecl.createDefinition(EVENT_HEADER_SCOPE, "", currentBitBuffer); //$NON-NLS-1$
- EventHeaderDefinition ehd = (EventHeaderDefinition) fCurrentStreamEventHeaderDef;
- eventID = ehd.getId();
- } else {
- fCurrentStreamEventHeaderDef = ((StructDeclaration) fStreamEventHeaderDecl).createDefinition(EVENT_HEADER_SCOPE, ILexicalScope.EVENT_HEADER, currentBitBuffer);
- StructDefinition StructEventHeaderDef = (StructDefinition) fCurrentStreamEventHeaderDef;
- /* Check for the event id. */
- IDefinition idDef = StructEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$
- SimpleDatatypeDefinition simpleIdDef = null;
- if (idDef instanceof SimpleDatatypeDefinition) {
- simpleIdDef = ((SimpleDatatypeDefinition) idDef);
- } else if (idDef != null) {
- throw new CTFIOException("Id defintion not an integer, enum or float definiton in event header."); //$NON-NLS-1$
- }
- /* Check for the variant v. */
- IDefinition variantDef = StructEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$
- if (variantDef instanceof VariantDefinition) {
-
- /* Get the variant current field */
- StructDefinition variantCurrentField = (StructDefinition) ((VariantDefinition) 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.
- */
- IDefinition vIdDef = variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
- if (vIdDef instanceof IntegerDefinition) {
- simpleIdDef = (SimpleDatatypeDefinition) vIdDef;
- }
-
- }
- if (simpleIdDef != null) {
- eventID = simpleIdDef.getIntegerValue().intValue();
- }
- }
- }
- /* Get the right event definition using the event id. */
- EventDeclaration eventDeclaration = (EventDeclaration) fStreamInputReader.getStreamInput().getStream().getEventDeclaration(eventID);
- if (eventDeclaration == null) {
- throw new CTFIOException("Incorrect event id : " + eventID); //$NON-NLS-1$
- }
- EventDefinition eventDef = eventDeclaration.createDefinition(fStreamInputReader, fCurrentStreamEventHeaderDef, currentBitBuffer, fLastTimestamp);
- fLastTimestamp = eventDef.getTimestamp();
- /*
- * Set the event timestamp using the timestamp calculated by
- * updateTimestamp.
- */
-
- if (posStart == currentBitBuffer.position()) {
- throw new CTFIOException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
- }
-
- return eventDef;
- }
-
- @Override
- public Definition lookupDefinition(String lookupPath) {
- if (lookupPath.equals(ILexicalScope.STREAM_PACKET_CONTEXT.getPath())) {
- return (Definition) fCurrentStreamPacketContextDef;
- }
- if (lookupPath.equals(ILexicalScope.TRACE_PACKET_HEADER.getPath())) {
- return (Definition) fCurrentTracePacketHeaderDef;
- }
- return null;
- }
-
-
- /**
- * Get stream event header
- *
- * @return the stream event header
- */
- public ICompositeDefinition getStreamEventHeaderDefinition() {
- return fCurrentStreamEventHeaderDef;
- }
-
- /**
- * Get the current packet event header
- *
- * @return the current packet event header
- */
- public StructDefinition getCurrentPacketEventHeader() {
- if (fCurrentTracePacketHeaderDef instanceof StructDefinition) {
- return (StructDefinition) fCurrentTracePacketHeaderDef;
- }
- return null;
- }
-}
import java.io.File;
import java.io.IOException;
+import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
import java.nio.file.StandardOpenOption;
+import java.util.List;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.ctf.core.CTFException;
import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
+import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
import org.eclipse.tracecompass.internal.ctf.core.Activator;
-
-import com.google.common.collect.ImmutableList;
+import org.eclipse.tracecompass.internal.ctf.core.SafeMappedByteBuffer;
+import org.eclipse.tracecompass.internal.ctf.core.trace.CTFPacketReader;
+import org.eclipse.tracecompass.internal.ctf.core.trace.NullPacketReader;
/**
* A CTF trace event reader. Reads the events of a trace file.
@NonNullByDefault
public class CTFStreamInputReader implements AutoCloseable {
+ private static final int BITS_PER_BYTE = Byte.SIZE;
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
/**
* The packet reader used to read packets from this trace file.
*/
- private final CTFStreamInputPacketReader fPacketReader;
+ private IPacketReader fPacketReader;
/**
* Iterator on the packet index
throw new CTFIOException(e);
}
try {
- fPacketReader = new CTFStreamInputPacketReader(this);
/*
* Get the iterator on the packet index.
*/
/*
* Make first packet the current one.
*/
- goToNextPacket();
+ // did we already index the packet?
+ if (getPacketSize() < (fPacketIndex + 1)) {
+ // go to the next packet if there is one, index it at the same
+ // time
+ if (fStreamInput.addPacketHeaderIndex()) {
+ fPacketIndex = getPacketSize() - 1;
+ }
+ }
+ ICTFPacketDescriptor packet = getPacket();
+ fPacketReader = getCurrentPacketReader(packet);
} catch (Exception e) {
try {
close();
}
}
+ private IPacketReader getCurrentPacketReader(@Nullable ICTFPacketDescriptor packet) throws CTFException {
+ IPacketReader ctfPacketReader = NullPacketReader.INSTANCE;
+ if (packet != null) {
+ long size = packet.getContentSizeBits();
+ if (size < 0) {
+ throw new CTFIOException("Cannot have negative sized buffers."); //$NON-NLS-1$
+ }
+ BitBuffer bitBuffer = new BitBuffer(getByteBufferAt(packet.getOffsetBits(), size));
+ bitBuffer.position(packet.getPayloadStartBits());
+ IDeclaration eventHeaderDeclaration = getStreamInput().getStream().getEventHeaderDeclaration();
+ CTFTrace trace = getStreamInput().getStream().getTrace();
+ StructDefinition packetHeaderDef = checkNotNull(trace.getPacketHeaderDef());
+ ctfPacketReader = new CTFPacketReader(bitBuffer, packet, getEventDeclarations(), eventHeaderDeclaration, getStreamEventContextDecl(), packetHeaderDef, trace);
+ }
+ return ctfPacketReader;
+ }
+
+ /**
+ * Get a bytebuffer map of the file
+ *
+ * @param position
+ * start offset in bits
+ * @param size
+ * size of the map in bits, use caution
+ * @return a byte buffer
+ * @throws CTFException
+ * if the map failed in its allocation
+ *
+ * @since 2.0
+ */
+ public ByteBuffer getByteBufferAt(long position, long size) throws CTFException {
+ ByteBuffer map;
+ try {
+ map = SafeMappedByteBuffer.map(fFileChannel, MapMode.READ_ONLY, position / BITS_PER_BYTE, (size + BITS_PER_BYTE - 1) / BITS_PER_BYTE);
+ } catch (IOException e) {
+ throw new CTFIOException(e.getMessage(), e);
+ }
+ if (map == null) {
+ throw new CTFIOException("Failed to allocate mapped byte buffer"); //$NON-NLS-1$
+ }
+ return map;
+ }
+
/**
* Dispose the StreamInputReader, closes the file channel and its packet
* reader
if (fFileChannel != null) {
fFileChannel.close();
}
- fPacketReader.close();
+ fPacketReader = NullPacketReader.INSTANCE;
}
// ------------------------------------------------------------------------
* Gets the event definition set for this StreamInput
*
* @return Unmodifiable set with the event definitions
+ * @since 2.0
*/
- public Iterable<IEventDeclaration> getEventDeclarations() {
- return checkNotNull(ImmutableList.copyOf(fStreamInput.getStream().getEventDeclarations()));
+ public List<IEventDeclaration> getEventDeclarations() {
+ return fStreamInput.getStream().getEventDeclarations();
}
/**
private void goToNextPacket() throws CTFException {
fPacketIndex++;
// did we already index the packet?
- if (getPacketSize() >= (fPacketIndex + 1)) {
- fPacketReader.setCurrentPacket(getPacket());
- } else {
+ while (getPacketSize() < (fPacketIndex + 1)) {
// go to the next packet if there is one, index it at the same time
if (fStreamInput.addPacketHeaderIndex()) {
fPacketIndex = getPacketSize() - 1;
- fPacketReader.setCurrentPacket(getPacket());
} else {
- // out of packets
- fPacketReader.setCurrentPacket(null);
+ fPacketReader = NullPacketReader.INSTANCE;
+ return;
}
+
}
+ ICTFPacketDescriptor packet = getPacket();
+ fPacketReader = getCurrentPacketReader(packet);
+
}
/**
/*
* Go to last indexed packet
*/
- fPacketReader.setCurrentPacket(getPacket());
+ fPacketReader = getCurrentPacketReader(getPacket());
/*
* Keep going until you cannot
*/
for (int pos = lastPacketIndex; pos > 0; pos--) {
fPacketIndex = pos;
- fPacketReader.setCurrentPacket(getPacket());
+ fPacketReader = getCurrentPacketReader(getPacket());
if (fPacketReader.hasMoreEvents()) {
break;
}
/**
- * Get the file channel wrapped by this reader
+ * Get the current packet reader
*
- * @return the file channel
- */
- @Nullable
- FileChannel getFc() {
- return fFileChannel;
- }
-
- /**
* @return the packetReader
+ * @since 2.0
*/
- public CTFStreamInputPacketReader getPacketReader() {
+ public IPacketReader getCurrentPacketReader() {
return fPacketReader;
}
/* Shouldn't happen at this stage if every other check passed */
throw new CTFException(e);
}
- if (fPacketHeaderDef != null) {
- validateMagicNumber(fPacketHeaderDef);
+ final StructDefinition packetHeaderDef = getPacketHeaderDef();
+ if (packetHeaderDef != null) {
+ validateMagicNumber(packetHeaderDef);
- validateUUID(fPacketHeaderDef);
+ validateUUID(packetHeaderDef);
/* Read the stream ID */
- IDefinition streamIDDef = fPacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
+ IDefinition streamIDDef = packetHeaderDef.lookupDefinition(MetadataStrings.STREAM_ID);
if (streamIDDef instanceof IntegerDefinition) {
/* This doubles as a null check */
@Override
public Definition lookupDefinition(String lookupPath) {
if (lookupPath.equals(ILexicalScope.TRACE_PACKET_HEADER.getPath())) {
- return fPacketHeaderDef;
+ return getPacketHeaderDef();
}
return null;
}
public DeclarationScope getScope() {
return fScope;
}
+
+ /**
+ * Gets the packet header definition (UUID, magic number and such)
+ *
+ * @return the packet header definition
+ *
+ * @since 2.0
+ */
+ public StructDefinition getPacketHeaderDef() {
+ return fPacketHeaderDef;
+ }
}
class MetadataFileFilter implements FileFilter {
import org.eclipse.tracecompass.internal.ctf.core.Activator;
import org.eclipse.tracecompass.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-
/**
* A CTF trace reader. Reads the events of a trace.
*
*/
fStartTime = 0;
if (hasMoreEvents()) {
- EventDefinition currentEvent = getTopStream().getCurrentEvent();
- if (currentEvent != null) {
- fStartTime = currentEvent.getTimestamp();
- setEndTime(fStartTime);
- }
+ fStartTime = checkNotNull(getTopStream().getCurrentEvent()).getTimestamp();
+ setEndTime(fStartTime);
}
}
*/
CTFStreamInputReader streamInputReader = new CTFStreamInputReader(checkNotNull(streamInput));
+
/*
* Add it to the group.
*/
* @return the iterable of the stream input readers
*/
public Iterable<IEventDeclaration> getEventDeclarations() {
- ImmutableSet.Builder<IEventDeclaration> builder = new Builder<>();
+ Set<IEventDeclaration> retSet = new HashSet<>();
for (CTFStreamInputReader sir : fStreamInputReaders) {
- builder.addAll(sir.getEventDeclarations());
+ retSet.addAll(sir.getEventDeclarations());
}
- return builder.build();
+ retSet.remove(null);
+ return retSet;
}
/**
*/
long getOffsetBytes();
+ /**
+ * Get the offset where the events start and the packet header ends
+ *
+ * @return the offset in the file of the end of the packet header
+ * @since 2.0
+ */
+ long getPayloadStartBits();
+
}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.ctf.core.trace;
+
+import org.eclipse.tracecompass.ctf.core.CTFException;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
+
+/**
+ * Packet reader interface, allows for more flexible packet readers. A packet
+ * reader must be able to do one thing only: read a ctf packet.
+ *
+ * In order to do that, it will have access to the packet and can then iterate
+ * over the packet with two main functions {@link #readNextEvent()} and
+ * {@link #hasMoreEvents()}. The packet reader must also have a notion of
+ * whether a given packet has an assigned CPU or not, which will be given
+ * by @link {@link #getCPU()}, as well as the event header, defined in
+ * {@link #getCurrentPacketEventHeader()}. The packet description in the reader
+ * can be obtained by calling {@link #getCurrentPacket()}
+ *
+ * @author Matthew Khouzam
+ *
+ * @since 2.0
+ */
+public interface IPacketReader {
+
+ /**
+ * The value of a cpu if it is unknown to the packet reader
+ */
+ int UNKNOWN_CPU = -1;
+
+ /**
+ * Gets the CPU (core) number
+ *
+ * @return the CPU (core) number
+ */
+ int getCPU();
+
+ /**
+ * Returns whether it is possible to read any more events from this packet.
+ *
+ * @return True if it is possible to read any more events from this packet.
+ */
+ boolean hasMoreEvents();
+
+ /**
+ * Reads the next event of the packet into the right event definition.
+ *
+ * @return The event definition containing the event data that was just
+ * read.
+ * @throws CTFException
+ * If there was a problem reading the trace
+ */
+ EventDefinition readNextEvent() throws CTFException;
+
+ /**
+ * Get the packet being read
+ *
+ * @return the packet being read
+ */
+ ICTFPacketDescriptor getCurrentPacket();
+
+ /**
+ * Get the current event header definition
+ *
+ * @return the current event header definition
+ */
+ ICompositeDefinition getCurrentPacketEventHeader();
+
+}
\ No newline at end of file
import org.eclipse.tracecompass.ctf.core.trace.CTFIOException;
import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
+import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
import org.eclipse.tracecompass.internal.ctf.core.event.types.composite.EventHeaderDefinition;
/**
/**
* Creates an instance of EventDefinition corresponding to this declaration.
*
- * @param streamInputReader
- * The StreamInputReader for which this definition is created.
+ * @param streamEventContextDecl
+ * event context
+ * @param packetDescriptor
+ * current packet
+ * @param packetContext
+ * packet context
* @param eventHeaderDef
* The event header definition
* @param input
* As a bitbuffer is used to read, it could have wrapped
* IOExceptions.
*/
- public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, ICompositeDefinition eventHeaderDef, @NonNull BitBuffer input, long prevTimestamp) throws CTFException {
- StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
+ public EventDefinition createDefinition(StructDeclaration streamEventContextDecl, ICTFPacketDescriptor packetDescriptor, ICompositeDefinition packetContext, ICompositeDefinition eventHeaderDef, @NonNull BitBuffer input, long prevTimestamp)
+ throws CTFException {
StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), ILexicalScope.STREAM_EVENT_CONTEXT, input) : null;
- ICompositeDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
StructDefinition eventContext = fContext != null ? fContext.createFieldDefinition(eventHeaderDef, fStream.getTrace(), ILexicalScope.CONTEXT, input) : null;
StructDefinition eventPayload = fFields != null ? fFields.createFieldDefinition(eventHeaderDef, fStream.getTrace(), ILexicalScope.FIELDS, input) : null;
long timestamp = calculateTimestamp(eventHeaderDef, prevTimestamp, eventPayload, eventContext);
+ int cpu = (int) packetDescriptor.getTargetId();
return new EventDefinition(
this,
- streamInputReader.getCPU(),
+ cpu,
timestamp,
eventHeaderDef,
streamEventContext,
public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFException {
StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), ILexicalScope.STREAM_EVENT_CONTEXT, input) : null;
- ICompositeDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
+ ICompositeDefinition packetContext = streamInputReader.getCurrentPacketReader().getCurrentPacketEventHeader();
StructDefinition eventContext = fContext != null ? fContext.createDefinition(fStream.getTrace(), ILexicalScope.CONTEXT, input) : null;
StructDefinition eventPayload = fFields != null ? fFields.createDefinition(fStream.getTrace(), ILexicalScope.FIELDS, input) : null;
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.ctf.core.trace;
+
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.ctf.core.CTFException;
+import org.eclipse.tracecompass.ctf.core.CTFStrings;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
+import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
+import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.IEventHeaderDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.SimpleDatatypeDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
+import org.eclipse.tracecompass.ctf.core.trace.CTFIOException;
+import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
+import org.eclipse.tracecompass.ctf.core.trace.IPacketReader;
+import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
+import org.eclipse.tracecompass.internal.ctf.core.event.types.composite.EventHeaderDefinition;
+
+/**
+ * Packet reader with a fixed bit buffer, should be the fast and easily
+ * parallelizable one.
+ */
+@NonNullByDefault
+public final class CTFPacketReader implements IPacketReader, IDefinitionScope {
+
+ private static final IDefinitionScope EVENT_HEADER_SCOPE = new IDefinitionScope() {
+
+ @Override
+ public @Nullable IDefinition lookupDefinition(@Nullable String lookupPath) {
+ return null;
+ }
+
+ @Override
+ public @Nullable ILexicalScope getScopePath() {
+ return null;
+ }
+ };
+
+ private final BitBuffer fInput;
+ private final ICTFPacketDescriptor fPacketContext;
+ private final List<IEventDeclaration> fDeclarations;
+ private boolean fHasLost;
+ private long fLastTimestamp;
+ private @Nullable final IDeclaration fStreamEventHeaderDecl;
+
+ private @Nullable final StructDeclaration fStreamContext;
+
+ private @Nullable final ICompositeDefinition fTracePacketHeader;
+
+ private @Nullable final IDefinitionScope fPacketScope;
+
+ private @Nullable ICompositeDefinition fEventHeader;
+
+ /**
+ * Constructor
+ *
+ * @param input
+ * input {@link BitBuffer}
+ * @param packetContext
+ * packet_context where we get info like lost events and cpu_id
+ * @param declarations
+ * event declarations for this packet reader
+ * @param eventHeaderDeclaration
+ * event header declaration, what to read before any given event,
+ * to find it's id
+ * @param streamContext
+ * the context declaration
+ * @param packetHeader
+ * the header with the magic numbers and such
+ * @param packetScope
+ * the scope of the packetHeader
+ */
+ public CTFPacketReader(BitBuffer input, ICTFPacketDescriptor packetContext, List<IEventDeclaration> declarations, @Nullable IDeclaration eventHeaderDeclaration, @Nullable StructDeclaration streamContext, ICompositeDefinition packetHeader,
+ IDefinitionScope packetScope) {
+ fInput = input;
+ fPacketContext = packetContext;
+ fDeclarations = declarations;
+ fPacketScope = packetScope;
+ fHasLost = fPacketContext.getLostEvents() != 0;
+ fLastTimestamp = fPacketContext.getTimestampBegin();
+ fStreamEventHeaderDecl = eventHeaderDeclaration;
+ fStreamContext = streamContext;
+ fTracePacketHeader = packetHeader;
+ }
+
+ @Override
+ public int getCPU() {
+ return (int) fPacketContext.getTargetId();
+ }
+
+ @Override
+ public boolean hasMoreEvents() {
+ return fInput.position() < fPacketContext.getContentSizeBits();
+ }
+
+ @Override
+ public EventDefinition readNextEvent() throws CTFException {
+ int eventID = (int) IEventDeclaration.UNSET_EVENT_ID;
+ final long posStart = fInput.position();
+ /*
+ * Return the Lost Event after all other events in this packet. We need
+ * to check if the bytebuffer is at the beginning too.
+ */
+ if (fHasLost && (posStart == fPacketContext.getPayloadStartBits())) {
+ fHasLost = false;
+ return createLostEvent(fPacketContext);
+ }
+
+ fEventHeader = null;
+ /* Read the stream event header. */
+ final IDeclaration streamEventHeaderDecl = fStreamEventHeaderDecl;
+ if (streamEventHeaderDecl instanceof IEventHeaderDeclaration) {
+ IEventHeaderDeclaration eventHeaderDeclaration = (IEventHeaderDeclaration) streamEventHeaderDecl;
+ EventHeaderDefinition ehd = (EventHeaderDefinition) eventHeaderDeclaration.createDefinition(EVENT_HEADER_SCOPE, "", fInput); //$NON-NLS-1$
+ fEventHeader = ehd;
+ eventID = ehd.getId();
+ } else if (streamEventHeaderDecl instanceof StructDeclaration) {
+ StructDefinition structEventHeaderDef = ((StructDeclaration) streamEventHeaderDecl).createDefinition(EVENT_HEADER_SCOPE, ILexicalScope.EVENT_HEADER, fInput);
+ fEventHeader = structEventHeaderDef;
+ /* Check for the event id. */
+ IDefinition idDef = structEventHeaderDef.lookupDefinition("id"); //$NON-NLS-1$
+ SimpleDatatypeDefinition simpleIdDef = null;
+ if (idDef instanceof SimpleDatatypeDefinition) {
+ simpleIdDef = ((SimpleDatatypeDefinition) idDef);
+ } else if (idDef != null) {
+ throw new CTFIOException("Id defintion not an integer, enum or float definiton in event header."); //$NON-NLS-1$
+ }
+ /* Check for the variant v. */
+ IDefinition variantDef = structEventHeaderDef.lookupDefinition("v"); //$NON-NLS-1$
+ if (variantDef instanceof VariantDefinition) {
+
+ /* Get the variant current field */
+ StructDefinition variantCurrentField = (StructDefinition) ((VariantDefinition) 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.
+ */
+ IDefinition vIdDef = variantCurrentField.lookupDefinition("id"); //$NON-NLS-1$
+ if (vIdDef instanceof IntegerDefinition) {
+ simpleIdDef = (SimpleDatatypeDefinition) vIdDef;
+ }
+
+ }
+ if (simpleIdDef != null) {
+ eventID = simpleIdDef.getIntegerValue().intValue();
+ }
+ }
+ /* Single event type in a trace */
+ if (eventID == IEventDeclaration.UNSET_EVENT_ID && fDeclarations.size() == 1) {
+ eventID = 0;
+ }
+ /* Get the right event definition using the event id. */
+ IEventDeclaration eventDeclaration = fDeclarations.get(eventID);
+ if (!(eventDeclaration instanceof EventDeclaration)) {
+ throw new CTFIOException("Incorrect event id : " + eventID); //$NON-NLS-1$
+ }
+ EventDeclaration declaration = (EventDeclaration) eventDeclaration;
+ EventDefinition eventDef = declaration.createDefinition(fStreamContext, fPacketContext, fTracePacketHeader, fEventHeader, fInput, fLastTimestamp);
+ fLastTimestamp = eventDef.getTimestamp();
+ /*
+ * Set the event timestamp using the timestamp calculated by
+ * updateTimestamp.
+ */
+
+ if (posStart == fInput.position()) {
+ throw new CTFIOException("Empty event not allowed, event: " + eventDef.getDeclaration().getName()); //$NON-NLS-1$
+ }
+
+ return eventDef;
+ }
+
+ private EventDefinition createLostEvent(final ICTFPacketDescriptor currentPacket) {
+ IEventDeclaration lostEventDeclaration = LostEventDeclaration.INSTANCE;
+ StructDeclaration lostFields = lostEventDeclaration.getFields();
+ // this is a hard coded map, we know it's not null
+ IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_FIELD);
+ if (lostFieldsDecl == null) {
+ throw new IllegalStateException("Lost events count not declared!"); //$NON-NLS-1$
+ }
+ IntegerDeclaration lostEventsDurationDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_DURATION);
+ if (lostEventsDurationDecl == null) {
+ throw new IllegalStateException("Lost events duration not declared!"); //$NON-NLS-1$
+ }
+ long lostEventsTimestamp = fLastTimestamp;
+ long lostEventsDuration = currentPacket.getTimestampEnd() - lostEventsTimestamp;
+ IntegerDefinition lostDurationDef = new IntegerDefinition(lostFieldsDecl, null, CTFStrings.LOST_EVENTS_DURATION, lostEventsDuration);
+ IntegerDefinition lostCountDef = new IntegerDefinition(lostEventsDurationDecl, null, CTFStrings.LOST_EVENTS_FIELD, fPacketContext.getLostEvents());
+ IntegerDefinition[] fields = new IntegerDefinition[] { lostCountDef, lostDurationDef };
+ int cpu = (int) fPacketContext.getTargetId();
+ return new EventDefinition(
+ lostEventDeclaration,
+ cpu,
+ lostEventsTimestamp,
+ null,
+ null,
+ null,
+ null,
+ new StructDefinition(
+ lostFields,
+ this, "fields", //$NON-NLS-1$
+ fields));
+ }
+
+ @Override
+ public ILexicalScope getScopePath() {
+ return ILexicalScope.PACKET;
+ }
+
+ @Override
+ public @Nullable IDefinition lookupDefinition(@Nullable String lookupPath) {
+ if (ILexicalScope.TRACE_PACKET_HEADER.getPath().equals(lookupPath)) {
+ return fTracePacketHeader;
+ } else if (ILexicalScope.STREAM_PACKET_CONTEXT.getPath().equals(lookupPath) && fPacketScope != null) {
+ return fPacketScope.lookupDefinition(lookupPath);
+ }
+ return null;
+ }
+
+ @Override
+ public ICTFPacketDescriptor getCurrentPacket() {
+ return fPacketContext;
+ }
+
+ /**
+ * TODO: remove when API is reworked a bit.
+ */
+ @Override
+ public @Nullable ICompositeDefinition getCurrentPacketEventHeader() {
+ return fEventHeader;
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2015 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.ctf.core.trace;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.ctf.core.CTFException;
+import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
+import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
+import org.eclipse.tracecompass.ctf.core.trace.IPacketReader;
+
+/**
+ * Null packet reader, used for unset packets
+ */
+@NonNullByDefault
+public final class NullPacketReader implements IPacketReader {
+
+ /**
+ * Instance of a null packet reader
+ */
+ public static final NullPacketReader INSTANCE = new NullPacketReader();
+
+ private NullPacketReader() { }
+
+ @Override
+ public int getCPU() {
+ return UNKNOWN_CPU;
+ }
+
+ @Override
+ public boolean hasMoreEvents() {
+ return false;
+ }
+
+ @Override
+ public @Nullable EventDefinition readNextEvent() throws CTFException {
+ return null;
+ }
+
+ @Override
+ public @Nullable ICTFPacketDescriptor getCurrentPacket() {
+ return null;
+ }
+
+ @Override
+ public @Nullable ICompositeDefinition getCurrentPacketEventHeader() {
+ return null;
+ }
+}
import org.eclipse.tracecompass.ctf.core.event.types.StringDefinition;
import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
import org.eclipse.tracecompass.ctf.core.trace.ICTFPacketDescriptor;
+import org.eclipse.tracecompass.ctf.core.trace.IPacketReader;
/**
* <b><u>StreamInputPacketIndexEntry</u></b>
private static final Pattern NUMBER_PATTERN = Pattern.compile("\\D*(\\d+)"); //$NON-NLS-1$
- private static final int UNKNOWN = -1;
-
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
*/
private final Map<String, Object> fAttributes = new HashMap<>();
+ private final long fEndPacketHeaderBits;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
* offset in the file for the start of data in bits
* @param fileSizeBytes
* number of bytes in a file
+ *
+ * TODO: Remove
*/
public StreamInputPacketIndexEntry(long dataOffsetBits, long fileSizeBytes) {
fTargetID = 0;
fTimestampBegin = 0;
fTimestampEnd = Long.MAX_VALUE;
+ fEndPacketHeaderBits = dataOffsetBits;
}
/**
* number of bytes in a file
* @param lostSoFar
* number of lost events so far
+ *
+ * TODO: Remove
*/
public StreamInputPacketIndexEntry(long dataOffsetBits, StructDefinition streamPacketContextDef, long fileSizeBytes, long lostSoFar) {
+ this(dataOffsetBits, streamPacketContextDef, fileSizeBytes, lostSoFar, dataOffsetBits);
+ }
+
+ /**
+ * full Constructor
+ *
+ * @param dataOffsetBits
+ * offset in the file for the start of data in bits
+ * @param streamPacketContextDef
+ * packet context
+ * @param fileSizeBytes
+ * number of bytes in a file
+ * @param lostSoFar
+ * number of lost events so far
+ * @param endPacketHeaderBits
+ * end of packet headers
+ */
+ public StreamInputPacketIndexEntry(long dataOffsetBits, StructDefinition streamPacketContextDef, long fileSizeBytes, long lostSoFar, long endPacketHeaderBits) {
+ fEndPacketHeaderBits = endPacketHeaderBits;
for (String field : streamPacketContextDef.getDeclaration().getFieldsList()) {
IDefinition id = streamPacketContextDef.lookupDefinition(field);
if (id instanceof IntegerDefinition) {
public Target() {
string = null;
- number = UNKNOWN;
+ number = IPacketReader.UNKNOWN_CPU;
}
}
public long getOffsetBytes() {
return fOffsetBytes;
}
+
+ @Override
+ public long getPayloadStartBits() {
+ return fEndPacketHeaderBits;
+ }
}
/**
* @throws NullPointerException
- * If any {@link CTFStreamInputReader} parameter is null, of if any
- * of them does not contain a current event.
+ * If any {@link CTFStreamInputReader} parameter is null, of if
+ * any of them does not contain a current event.
*/
@Override
public int compare(CTFStreamInputReader a, CTFStreamInputReader b) {
*/
public class CtfTmfEventTest {
+ private static final String VALID_FIELD = "ret";
+
private static final @NonNull CtfTestTrace testTrace = CtfTestTrace.KERNEL;
+ /**
+ * <pre>
+ * babeltrace output :
+ * [11:24:42.440133097] (+?.?????????) sys_socketcall: { cpu_id = 1 }, { call = 17, args = 0xB7555F30 }
+ * [11:24:42.440137077] (+0.000003980) exit_syscall: { cpu_id = 1 }, { ret = 4132 }
+ * </pre>
+ */
+
private static CtfTmfEvent nullEvent;
private CtfTmfEvent fixture;
*/
@Test
public void testGetFieldValue() {
- String fieldName = "pid";
- ITmfEventField result = fixture.getContent().getField(fieldName);
+ ITmfEventField result = fixture.getContent().getField(VALID_FIELD);
assertNotNull(result);
assertNotNull(result.getValue());
@Test
public void testGetSubFieldValue() {
/* Field exists */
- String[] names = { "pid" };
+ String[] names = { VALID_FIELD };
assertNotNull(fixture.getContent().getField(names));
/* First field exists, not the second */
- String[] names2 = { "pid", "abcd" };
+ String[] names2 = { VALID_FIELD, "abcd" };
assertNull(fixture.getContent().getField(names2));
/* Both field do not exist */
assertEquals("channel0_1", reference);
assertEquals(1, cpu);
- assertEquals("lttng_statedump_vm_map", type.toString());
+ assertEquals("exit_syscall", type.toString());
}
/**
@Test
public void testToString() {
String s = fixture.getContent().toString();
- assertEquals("pid=1922, start=0xb73ea000, end=0xb73ec000, flags=0x8000075, inode=917738, pgoff=0", s);
+ assertEquals("ret=4132", s);
}
/**
Map<String, Long> eventsInRange = fStats.getEventTypesInRange(rangeStart, rangeEnd);
Long lostEventsInRange = eventsInRange.get(CTFStrings.LOST_EVENT_NAME);
assertNotNull(lostEventsInRange);
- assertEquals(365752L, lostEventsInRange.longValue());
+ assertEquals(363494L, lostEventsInRange.longValue());
}
}
*/
@Test
public void testFirstLostEvent() {
- final long rank = 190;
- final ITmfTimestamp start = new TmfNanoTimestamp(1376592664828900165L);
- final ITmfTimestamp end = new TmfNanoTimestamp(1376592664829403076L);
+ final long rank = 152;
+ final long startTime = 1376592664828848222L;
+ final ITmfTimestamp start = new TmfNanoTimestamp(startTime);
+ final ITmfTimestamp end = new TmfNanoTimestamp(startTime + 554854L);
final long nbLost = 859;
- final CtfTmfEvent ev = getOneEventTime(start);
- /* Make sure seeking by rank yields the same event */
- final CtfTmfEvent ev2 = getOneEventRank(rank);
- assertEquals(ev, ev2);
-
- assertTrue(ev instanceof ITmfLostEvent);
- ITmfLostEvent event = (ITmfLostEvent) ev;
-
- assertEquals(start, event.getTimestamp());
- assertEquals(start, event.getTimeRange().getStartTime());
- assertEquals(end, event.getTimeRange().getEndTime());
- assertEquals(nbLost, event.getNbLostEvents());
+ validateLostEvent(rank, start, end, nbLost);
}
/**
*/
@Test
public void testSecondLostEvent() {
- final long rank = 229;
- final ITmfTimestamp start = new TmfNanoTimestamp(1376592664829477058L);
- final ITmfTimestamp end = new TmfNanoTimestamp(1376592664829824514L);
+ final long rank = 191;
+ final long startTime = 1376592664829402521L;
+ final ITmfTimestamp start = new TmfNanoTimestamp(startTime);
+ final ITmfTimestamp end = new TmfNanoTimestamp(startTime + 421993L);
final long nbLost = 488;
+ validateLostEvent(rank, start, end, nbLost);
+ }
+
+ private void validateLostEvent(final long rank, final @NonNull ITmfTimestamp start, final ITmfTimestamp end, final long nbLost) {
final CtfTmfEvent ev = getOneEventTime(start);
/* Make sure seeking by rank yields the same event */
final CtfTmfEvent ev2 = getOneEventRank(rank);
*/
@Test
public void testNormalEvent() {
- final long rank = 200;
- final ITmfTimestamp ts = new TmfNanoTimestamp(1376592664829425780L);
+ final long rank = 193;
+ final ITmfTimestamp ts = new TmfNanoTimestamp(1376592664829411423L);
final CtfTmfEvent event = getOneEventTime(ts);
/* Make sure seeking by rank yields the same event */
trace.setTimestampTransform(TimestampTransformFactory.createWithOffset(offset));
trace.indexTrace(true);
- final long rank = 190;
- final ITmfTimestamp start = new TmfNanoTimestamp(1376592664828900165L + offset);
- final ITmfTimestamp end = new TmfNanoTimestamp(1376592664829403076L + offset);
+ final long rank = 152;
+ final ITmfTimestamp start = new TmfNanoTimestamp(1376592664828848222L + offset);
+ final ITmfTimestamp end = new TmfNanoTimestamp(1376592664828848222L + 554854L + offset);
final long nbLost = 859;
ITmfContext context = trace.seekEvent(rank);
public OneEventRequestPerTs(@NonNull ITmfTimestamp ts) {
super(CtfTmfEvent.class,
new TmfTimeRange(ts, ts),
- 0, ITmfEventRequest.ALL_DATA, ExecutionType.FOREGROUND);
+ 0, 1, ExecutionType.FOREGROUND);
}
@Override
* Called by this class' constructor. Constructs the basic viewer containing
* the charts, as well as their listeners
*/
- private void initContent() {
+ private synchronized void initContent() {
setLayout(new FillLayout());
fGlobalPC = null;