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;
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;
* (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 $
*/
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
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));
}
/* 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);
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
*
}
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 {