import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
-import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
+import org.eclipse.linuxtools.ctf.core.event.types.IDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.internal.ctf.core.event.CTFCallsiteComparator;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.event.types.ArrayDefinition;
/**
* A CTF trace on the file system.
/**
* The clock of the trace
*/
- private CTFClock fSingleClock;
+ private CTFClock fSingleClock = null;
/**
* Packet header structure definition
return (fPath != null) ? fPath.getPath() : ""; //$NON-NLS-1$
}
- /**
- * @since 3.0
- */
- @Override
- public LexicalScope getScopePath() {
- return LexicalScope.TRACE;
- }
// ------------------------------------------------------------------------
// Operations
FileChannel fc = fis.getChannel()) {
/* Map one memory page of 4 kiB */
byteBuffer = fc.map(MapMode.READ_ONLY, 0, (int) Math.min(fc.size(), 4096L));
+ if( byteBuffer == null){
+ throw new IllegalStateException("Failed to allocate memory"); //$NON-NLS-1$
+ }
} catch (IOException e) {
/* Shouldn't happen at this stage if every other check passed */
throw new CTFReaderException(e);
if (fPacketHeaderDecl != null) {
/* Read the packet header */
- fPacketHeaderDef = fPacketHeaderDecl.createDefinition(null, LexicalScope.PACKET_HEADER.getName(), streamBitBuffer);
+ fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, LexicalScope.PACKET_HEADER, streamBitBuffer);
/* Check the magic number */
IntegerDefinition magicDef = (IntegerDefinition) fPacketHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$
}
/* Check UUID */
- Definition lookupDefinition = fPacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
+ IDefinition lookupDefinition = fPacketHeaderDef.lookupDefinition("uuid"); //$NON-NLS-1$
ArrayDefinition uuidDef = (ArrayDefinition) lookupDefinition;
if (uuidDef != null) {
UUID otheruuid = Utils.getUUIDfromDefinition(uuidDef);
}
/* Read the stream ID */
- Definition streamIDDef = fPacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
+ IDefinition streamIDDef = fPacketHeaderDef.lookupDefinition("stream_id"); //$NON-NLS-1$
if (streamIDDef instanceof IntegerDefinition) { // this doubles as a
// null check
return stream;
}
+ // ------------------------------------------------------------------------
+ // IDefinitionScope
+ // ------------------------------------------------------------------------
+
+ /**
+ * @since 3.0
+ */
+ @Override
+ public LexicalScope getScopePath() {
+ return LexicalScope.TRACE;
+ }
+
/**
* Looks up a definition from packet
*
*/
@Override
public Definition lookupDefinition(String lookupPath) {
- if (lookupPath.equals("trace.packet.header")) { //$NON-NLS-1$
+ if (lookupPath.equals(LexicalScope.TRACE_PACKET_HEADER.toString())) {
return fPacketHeaderDef;
}
return null;
}
+ // ------------------------------------------------------------------------
+ // Live trace reading
+ // ------------------------------------------------------------------------
+
/**
* Add a new stream file to support new streams while the trace is being
* read.
* @return the clock
*/
public final CTFClock getClock() {
+ if (fSingleClock != null && fClocks.size() == 1) {
+ return fSingleClock;
+ }
if (fClocks.size() == 1) {
fSingleClock = fClocks.get(fClocks.keySet().iterator().next());
return fSingleClock;