ctf: Remove the callsite support
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / ctf / core / trace / CTFTrace.java
index eff931373ffd8a9d4348891ae12a0bc2bfcaa3d6..cac02c3e65af02cdacb20c02631164c55ff8a7c8 100644 (file)
@@ -30,15 +30,14 @@ import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeSet;
 import java.util.UUID;
 
 import org.eclipse.tracecompass.ctf.core.CTFException;
 import org.eclipse.tracecompass.ctf.core.CTFStrings;
-import org.eclipse.tracecompass.ctf.core.event.CTFCallsite;
 import org.eclipse.tracecompass.ctf.core.event.CTFClock;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
+import org.eclipse.tracecompass.ctf.core.event.metadata.DeclarationScope;
 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.AbstractArrayDefinition;
@@ -48,7 +47,7 @@ import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
 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.SafeMappedByteBuffer;
-import org.eclipse.tracecompass.internal.ctf.core.event.CTFCallsiteComparator;
+import org.eclipse.tracecompass.internal.ctf.core.event.metadata.MetadataStrings;
 import org.eclipse.tracecompass.internal.ctf.core.event.metadata.exceptions.ParseException;
 import org.eclipse.tracecompass.internal.ctf.core.trace.Utils;
 
@@ -60,6 +59,8 @@ import org.eclipse.tracecompass.internal.ctf.core.trace.Utils;
  * (in other words, all the work that can be shared between readers), but the
  * actual reading of events is left to TraceReader.
  *
+ * TODO: internalize CTFTrace and DeclarationScope
+ *
  * @author Matthew Khouzam
  * @version $Revision: 1.0 $
  */
@@ -134,13 +135,7 @@ public class CTFTrace implements IDefinitionScope {
     private static final FileFilter METADATA_FILE_FILTER = new MetadataFileFilter();
     private static final Comparator<File> METADATA_COMPARATOR = new MetadataComparator();
 
-    /** Callsite helpers */
-    private CTFCallsiteComparator fCtfCallsiteComparator = new CTFCallsiteComparator();
-
-    private Map<String, TreeSet<CTFCallsite>> fCallsitesByName = new HashMap<>();
-
-    /** Callsite helpers */
-    private TreeSet<CTFCallsite> fCallsitesByIP = new TreeSet<>();
+    private final DeclarationScope fScope = new DeclarationScope(null, MetadataStrings.TRACE);
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -459,7 +454,9 @@ public class CTFTrace implements IDefinitionScope {
             throw new CTFException("Unreadable file : " //$NON-NLS-1$
                     + streamFile.getPath());
         }
-
+        if (streamFile.length() == 0) {
+            return null;
+        }
         try (FileChannel fc = FileChannel.open(streamFile.toPath(), StandardOpenOption.READ)) {
             /* Map one memory page of 4 kiB */
             byteBuffer = SafeMappedByteBuffer.map(fc, MapMode.READ_ONLY, 0, (int) Math.min(fc.size(), 4096L));
@@ -468,7 +465,6 @@ public class CTFTrace implements IDefinitionScope {
             }
             /* Create a BitBuffer with this mapping and the trace byte order */
             streamBitBuffer = new BitBuffer(byteBuffer, this.getByteOrder());
-
             if (fPacketHeaderDecl != null) {
                 /* Read the packet header */
                 fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, ILexicalScope.PACKET_HEADER, streamBitBuffer);
@@ -791,100 +787,6 @@ public class CTFTrace implements IDefinitionScope {
         return retVal - getOffset();
     }
 
-    /**
-     * Adds a callsite
-     *
-     * @param eventName
-     *            the event name of the callsite
-     * @param funcName
-     *            the name of the callsite function
-     * @param ip
-     *            the ip of the callsite
-     * @param fileName
-     *            the filename of the callsite
-     * @param lineNumber
-     *            the line number of the callsite
-     */
-    public void addCallsite(String eventName, String funcName, long ip,
-            String fileName, long lineNumber) {
-        final CTFCallsite cs = new CTFCallsite(eventName, funcName, ip,
-                fileName, lineNumber);
-        TreeSet<CTFCallsite> csl = fCallsitesByName.get(eventName);
-        if (csl == null) {
-            csl = new TreeSet<>(fCtfCallsiteComparator);
-            fCallsitesByName.put(eventName, csl);
-        }
-
-        csl.add(cs);
-
-        fCallsitesByIP.add(cs);
-    }
-
-    /**
-     * Gets the set of callsites associated to an event name. O(1)
-     *
-     * @param eventName
-     *            the event name
-     * @return the callsite set can be empty
-     */
-    public TreeSet<CTFCallsite> getCallsiteCandidates(String eventName) {
-        TreeSet<CTFCallsite> retVal = fCallsitesByName.get(eventName);
-        if (retVal == null) {
-            retVal = new TreeSet<>(fCtfCallsiteComparator);
-        }
-        return retVal;
-    }
-
-    /**
-     * The I'm feeling lucky of getCallsiteCandidates O(1)
-     *
-     * @param eventName
-     *            the event name
-     * @return the first callsite that has that event name, can be null
-     */
-    public CTFCallsite getCallsite(String eventName) {
-        TreeSet<CTFCallsite> callsites = fCallsitesByName.get(eventName);
-        if (callsites != null) {
-            return callsites.first();
-        }
-        return null;
-    }
-
-    /**
-     * Gets a callsite from the instruction pointer O(log(n))
-     *
-     * @param ip
-     *            the instruction pointer to lookup
-     * @return the callsite just before that IP in the list remember the IP is
-     *         backwards on X86, can be null if no callsite is before the IP.
-     */
-    public CTFCallsite getCallsite(long ip) {
-        CTFCallsite cs = new CTFCallsite(null, null, ip, null, 0L);
-        return fCallsitesByIP.ceiling(cs);
-    }
-
-    /**
-     * Gets a callsite using the event name and instruction pointer O(log(n))
-     *
-     * @param eventName
-     *            the name of the event
-     * @param ip
-     *            the instruction pointer
-     * @return the closest matching callsite, can be null
-     */
-    public CTFCallsite getCallsite(String eventName, long ip) {
-        final TreeSet<CTFCallsite> 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) {
-            return candidates.floor(dummyCs);
-        }
-        return callsite;
-    }
-
     /**
      * Add a new stream
      *
@@ -909,6 +811,17 @@ public class CTFTrace implements IDefinitionScope {
         }
         stream.addInput(new CTFStreamInput(stream, file));
     }
+
+    /**
+     * Gets the current trace scope
+     *
+     * @return the current declaration scope
+     *
+     * @since 2.0
+     */
+    public DeclarationScope getScope() {
+        return fScope;
+    }
 }
 
 class MetadataFileFilter implements FileFilter {
This page took 0.028414 seconds and 5 git commands to generate.