X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.ctf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Fctf%2Fcore%2Ftrace%2FCTFTrace.java;h=4bb35847b7eb804f33a9a698b2460dc1b7ed7f38;hb=ede59fc8b6e42a13e95961bcecdd8167053d680d;hp=51af54d73d2fc4d0c5a959aeb8c6246e190dc2e8;hpb=962fb72f41941a75350f3ab090136d562842586c;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java index 51af54d73d..4bb35847b7 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java @@ -28,8 +28,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; @@ -42,13 +40,14 @@ import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration; 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. @@ -103,7 +102,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { /** * The clock of the trace */ - private CTFClock fSingleClock; + private CTFClock fSingleClock = null; /** * Packet header structure definition @@ -128,9 +127,6 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { */ private final Map fClocks = new HashMap<>(); - /** FileInputStreams to the streams */ - private final List fFileInputStreams = new LinkedList<>(); - /** Handlers for the metadata files */ private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter(); private static final Comparator METADATA_COMPARATOR = new MetadataComparator(); @@ -221,19 +217,12 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { /** * Dispose the trace * + * FIXME Not needed anymore, class doesn't need to be AutoCloseable. + * * @since 3.0 */ @Override public void close() { - for (FileInputStream fis : fFileInputStreams) { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - // do nothing it's ok, we tried to close it. - } - } - } } // ------------------------------------------------------------------------ @@ -458,13 +447,6 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { return (fPath != null) ? fPath.getPath() : ""; //$NON-NLS-1$ } - /** - * @since 3.0 - */ - @Override - public LexicalScope getScopePath() { - return LexicalScope.TRACE; - } // ------------------------------------------------------------------------ // Operations @@ -506,26 +488,20 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { MappedByteBuffer byteBuffer; BitBuffer streamBitBuffer; CTFStream stream; - FileChannel fc; if (!streamFile.canRead()) { throw new CTFReaderException("Unreadable file : " //$NON-NLS-1$ + streamFile.getPath()); } - FileInputStream fis = null; - try { - /* Open the file and get the FileChannel */ - fis = new FileInputStream(streamFile); - fFileInputStreams.add(fis); - fc = fis.getChannel(); - + try (FileInputStream fis = new FileInputStream(streamFile); + FileChannel fc = fis.getChannel()) { /* Map one memory page of 4 kiB */ byteBuffer = fc.map(MapMode.READ_ONLY, 0, (int) Math.min(fc.size(), 4096L)); - } catch (IOException e) { - if (fis != null) { - fFileInputStreams.remove(fis); + 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); } @@ -535,7 +511,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { 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$ @@ -545,7 +521,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { } /* 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); @@ -556,7 +532,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { } /* 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 @@ -585,6 +561,18 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { return stream; } + // ------------------------------------------------------------------------ + // IDefinitionScope + // ------------------------------------------------------------------------ + + /** + * @since 3.0 + */ + @Override + public LexicalScope getScopePath() { + return LexicalScope.TRACE; + } + /** * Looks up a definition from packet * @@ -595,12 +583,16 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { */ @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. @@ -706,6 +698,9 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { * @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; @@ -915,6 +910,9 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable { */ public CTFCallsite getCallsite(String eventName, long ip) { final TreeSet candidates = fCallsitesByName.get(eventName); + if (candidates == null) { + return null; + } final CTFCallsite dummyCs = new CTFCallsite(null, null, ip, null, -1); final CTFCallsite callsite = candidates.ceiling(dummyCs); if (callsite == null) {