import java.util.UUID;
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ListIterator;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
import org.junit.After;
import org.junit.Before;
+++ /dev/null
-package org.eclipse.linuxtools.ctf.core.tests.trace;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.nio.channels.FileChannel;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.Definition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.tests.TestParams;
-import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * The class <code>StreamInputPacketReaderTest</code> contains tests for the
- * class <code>{@link StreamInputPacketReader}</code>.
- *
- * @author ematkho
- * @version $Revision: 1.0 $
- */
-public class StreamInputPacketReaderTest {
-
- private StreamInputPacketReader fixture;
-
- /**
- * Launch the test.
- *
- * @param args
- * the command line arguments
- */
- public static void main(String[] args) {
- new org.junit.runner.JUnitCore().run(StreamInputPacketReaderTest.class);
- }
-
- /**
- * Perform pre-test initialization.
- *
- * @throws CTFReaderException
- */
- @Before
- public void setUp() throws CTFReaderException {
- // FIXME The test is broken here. "FileChannel" can't be null because we
- // need it further in. Heck this whole thing shouldn't be public in the
- // first place, perhaps fixing that is the best way to go.
- fixture = new StreamInputPacketReader(new StreamInputReader(
- new StreamInput(new Stream(TestParams.createTrace()),
- (FileChannel) null, TestParams.getEmptyFile())));
- }
-
- /**
- * Perform post-test clean-up.
- */
- @After
- public void tearDown() {
- // Add additional tear down code here
- }
-
- /**
- * Run the StreamInputPacketReader(StreamInputReader) constructor test.
- *
- * @throws CTFReaderException
- */
- @Test
- public void testStreamInputPacketReader() throws CTFReaderException {
- StreamInputReader streamInputReader;
- StreamInputPacketReader result;
-
- streamInputReader = new StreamInputReader(new StreamInput(new Stream(
- TestParams.createTrace()), (FileChannel) null,
- TestParams.getEmptyFile()));
-
- result = new StreamInputPacketReader(streamInputReader);
-
- assertNotNull(result);
- }
-
- /**
- * Run the int getCPU() method test.
- */
- @Test
- public void testGetCPU() {
- int result = fixture.getCPU();
- assertEquals(0, result);
- }
-
- /**
- * Run the StreamInputPacketIndexEntry getCurrentPacket() method test.
- */
- @Test
- public void testGetCurrentPacket() {
- StreamInputPacketIndexEntry sipie = new StreamInputPacketIndexEntry(1L);
- fixture.setCurrentPacket(sipie);
- StreamInputPacketIndexEntry result = fixture.getCurrentPacket();
- assertNotNull(result);
- }
-
- /**
- * Run the String getPath() method test.
- */
- @Test
- public void testGetPath() {
- String result = fixture.getPath();
- assertNotNull(result);
- }
-
- /**
- * Run the StructDefinition getStreamPacketContextDef() method test.
- */
- @Test
- public void testGetStreamPacketContextDef() {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- StructDefinition result = fixture.getStreamPacketContextDef();
- assertNotNull(result);
- }
-
- /**
- * Run the boolean hasMoreEvents() method test.
- */
- @Test
- public void testHasMoreEvents() {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- boolean result = fixture.hasMoreEvents();
- assertTrue(result);
- }
-
- /**
- * Run the Definition lookupDefinition(String) method test.
- */
- @Test
- public void testLookupDefinition() {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- String lookupPath = ""; //$NON-NLS-1$
- Definition result = fixture.lookupDefinition(lookupPath);
- assertNotNull(result);
- }
-
- /**
- * Run the EventDefinition readNextEvent() method test.
- *
- * @throws CTFReaderException
- */
- @Test
- public void testReadNextEvent() throws CTFReaderException {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- EventDefinition result = fixture.readNextEvent();
- assertNotNull(result);
- }
-
- /**
- * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
- */
- @Test
- public void testSetCurrentPacket() {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
- 1L);
- currentPacket.setPacketSizeBits(1);
- fixture.setCurrentPacket(currentPacket);
- }
-
- /**
- * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
- */
- @Test
- public void testSetCurrentPacket_2() throws Exception {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- StreamInputPacketIndexEntry currentPacket = null;
- fixture.setCurrentPacket(currentPacket);
-
- }
-
- /**
- * Run the void setCurrentPacket(StreamInputPacketIndexEntry) method test.
- */
- @Test
- public void testSetCurrentPacket_3() {
- fixture.setCurrentPacket(new StreamInputPacketIndexEntry(1L));
- StreamInputPacketIndexEntry currentPacket = new StreamInputPacketIndexEntry(
- 1L);
- currentPacket.setTimestampBegin(1L);
- currentPacket.setPacketSizeBits(1);
-
- fixture.setCurrentPacket(currentPacket);
- }
-}
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderComparator;
import org.junit.*;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* The class <code>StreamInputReaderTest</code> contains tests for the class
* <code>{@link StreamInputReader}</code>.
- *
+ *
* @author ematkho
* @version $Revision: 1.0 $
*/
/**
* Launch the test.
- *
+ *
* @param args
* the command line arguments
*/
/**
* Perform pre-test initialization.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Before
public void setUp() throws CTFReaderException {
/**
* Run the StreamInputReader(StreamInput) constructor test, with an invalid
* trace.
- *
+ *
* @throws CTFReaderException
*/
@Test(expected = CTFReaderException.class)
assertEquals(1, result);
}
- /**
- * Run the StreamInput getStreamInput() method test.
- */
- @Test
- public void testGetStreamInput() {
- StreamInput result = fixture.getStreamInput();
- assertNotNull(result);
- }
-
/**
* Run the void goToLastEvent() method test.
- *
+ *
* @throws CTFReaderException
*/
@Test
/**
* Run the seek test. Seek by passing an EventDefinition to which we've
* given the timestamp we want.
- *
- * @throws CTFReaderException
+ *
+ * @throws CTFReaderException
*/
@Test
public void testSeek_eventDefinition() throws CTFReaderException {
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReaderTimestampComparator;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
import org.junit.*;
/**
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputPacketIndex;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndex;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.Set;
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.tests.TestParams;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
import org.eclipse.linuxtools.ctf.core.trace.CTFTraceReader;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
org.antlr.runtime;bundle-version="3.2.0",
org.eclipse.linuxtools.ctf.parser;bundle-version="0.1.0"
Export-Package: org.eclipse.linuxtools.ctf.core.event,
- org.eclipse.linuxtools.ctf.core.event.metadata,
- org.eclipse.linuxtools.ctf.core.event.metadata.exceptions,
org.eclipse.linuxtools.ctf.core.event.types,
org.eclipse.linuxtools.ctf.core.trace
package org.eclipse.linuxtools.ctf.core.event;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
/**
* <b><u>EventDeclaration</u></b>
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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 Design and Grammar
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.event.metadata;
-
-import java.util.HashMap;
-
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
-import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
-
-/**
- * <b><u>DeclarationScope</u></b>
- * <p>
- * A DeclarationScope keeps track of the various CTF declarations for a given
- * scope.
- */
-public class DeclarationScope {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private DeclarationScope parentScope = null;
-
- private final HashMap<String, StructDeclaration> structs = new HashMap<String, StructDeclaration>();
- private final HashMap<String, EnumDeclaration> enums = new HashMap<String, EnumDeclaration>();
- private final HashMap<String, VariantDeclaration> variants = new HashMap<String, VariantDeclaration>();
- private final HashMap<String, IDeclaration> types = new HashMap<String, IDeclaration>();
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Creates a declaration scope with no parent.
- */
- public DeclarationScope() {
- }
-
- /**
- * Creates a declaration scope with the specified parent.
- *
- * @param parentScope
- * The parent of the newly created scope.
- */
- public DeclarationScope(DeclarationScope parentScope) {
- this.parentScope = parentScope;
- }
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- /**
- * Returns the parent of the current scope.
- *
- * @return The parent scope.
- */
- public DeclarationScope getParentScope() {
- return parentScope;
- }
-
- // ------------------------------------------------------------------------
- // Registration operations
- // ------------------------------------------------------------------------
-
- /**
- * Registers a type declaration.
- *
- * @param name
- * The name of the type.
- * @param declaration
- * The type declaration.
- * @throws ParseException
- * if a type with the same name has already been defined.
- */
- public void registerType(String name, IDeclaration declaration)
- throws ParseException {
- /* Check if the type has been defined in the current scope */
- if (types.containsKey(name)) {
- throw new ParseException("Type " + name //$NON-NLS-1$
- + " has already been defined."); //$NON-NLS-1$
- }
-
- /* Add it to the register. */
- types.put(name, declaration);
- }
-
- /**
- * Registers a struct declaration.
- *
- * @param name
- * The name of the struct.
- * @param declaration
- * The declaration of the struct.
- * @throws ParseException
- * if a struct with the same name has already been registered.
- */
- public void registerStruct(String name, StructDeclaration declaration)
- throws ParseException {
- /* Check if the struct has been defined in the current scope. */
- if (structs.containsKey(name)) {
- throw new ParseException("struct " + name //$NON-NLS-1$
- + " has already been defined."); //$NON-NLS-1$
- }
-
- /* Add it to the register. */
- structs.put(name, declaration);
-
- /* It also defined a new type, so add it to the type declarations. */
- String struct_prefix = "struct "; //$NON-NLS-1$
- registerType(struct_prefix + name, declaration);
- }
-
- /**
- * Registers an enum declaration.
- *
- * @param name
- * The name of the enum.
- * @param declaration
- * The declaration of the enum.
- * @throws ParseException
- * if an enum with the same name has already been registered.
- */
- public void registerEnum(String name, EnumDeclaration declaration)
- throws ParseException {
- /* Check if the enum has been defined in the current scope. */
- if (lookupEnum(name) != null) {
- throw new ParseException("enum " + name //$NON-NLS-1$
- + " has already been defined."); //$NON-NLS-1$
- }
-
- /* Add it to the register. */
- enums.put(name, declaration);
-
- /* It also defined a new type, so add it to the type declarations. */
- String enum_prefix = "enum "; //$NON-NLS-1$
- registerType(enum_prefix + name, declaration);
- }
-
- /**
- * Registers a variant declaration.
- *
- * @param name
- * The name of the variant.
- * @param declaration
- * The declaration of the variant.
- * @throws ParseException
- * if a variant with the same name has already been registered.
- */
- public void registerVariant(String name, VariantDeclaration declaration)
- throws ParseException {
- /* Check if the variant has been defined in the current scope. */
- if (lookupVariant(name) != null) {
- throw new ParseException("variant " + name //$NON-NLS-1$
- + " has already been defined."); //$NON-NLS-1$
- }
-
- /* Add it to the register. */
- variants.put(name, declaration);
-
- /* It also defined a new type, so add it to the type declarations. */
- String variant_prefix = "variant "; //$NON-NLS-1$
- registerType(variant_prefix + name, declaration);
- }
-
- // ------------------------------------------------------------------------
- // Lookup operations
- // ------------------------------------------------------------------------
-
- /**
- * Looks up a type declaration in the current scope.
- *
- * @param name
- * The name of the type to search for.
- * @return The type declaration, or null if no type with that name has been
- * defined.
- */
- public IDeclaration lookupType(String name) {
- return types.get(name);
- }
-
- /**
- * Looks up a type declaration in the current scope and recursively in the
- * parent scopes.
- *
- * @param name
- * The name of the type to search for.
- * @return The type declaration, or null if no type with that name has been
- * defined.
- */
- public IDeclaration rlookupType(String name) {
- IDeclaration declaration = lookupType(name);
- if (declaration != null) {
- return declaration;
- } else if (parentScope != null) {
- return parentScope.rlookupType(name);
- } else {
- return null;
- }
- }
-
- /**
- * Looks up a struct declaration.
- *
- * @param name
- * The name of the struct to search for.
- * @return The struct declaration, or null if no struct with that name has
- * been defined.
- */
- public StructDeclaration lookupStruct(String name) {
- return structs.get(name);
- }
-
- /**
- * Looks up a struct declaration in the current scope and recursively in the
- * parent scopes.
- *
- * @param name
- * The name of the struct to search for.
- * @return The struct declaration, or null if no struct with that name has
- * been defined.
- */
- public StructDeclaration rlookupStruct(String name) {
- StructDeclaration declaration = lookupStruct(name);
- if (declaration != null) {
- return declaration;
- } else if (parentScope != null) {
- return parentScope.rlookupStruct(name);
- } else {
- return null;
- }
- }
-
- /**
- * Looks up a enum declaration.
- *
- * @param name
- * The name of the enum to search for.
- * @return The enum declaration, or null if no enum with that name has been
- * defined.
- */
- public EnumDeclaration lookupEnum(String name) {
- return enums.get(name);
- }
-
- /**
- * Looks up an enum declaration in the current scope and recursively in the
- * parent scopes.
- *
- * @param name
- * The name of the enum to search for.
- * @return The enum declaration, or null if no enum with that name has been
- * defined.
- */
- public EnumDeclaration rlookupEnum(String name) {
- EnumDeclaration declaration = lookupEnum(name);
- if (declaration != null) {
- return declaration;
- } else if (parentScope != null) {
- return parentScope.rlookupEnum(name);
- } else {
- return null;
- }
- }
-
- /**
- * Looks up a variant declaration.
- *
- * @param name
- * The name of the variant to search for.
- * @return The variant declaration, or null if no variant with that name has
- * been defined.
- */
- public VariantDeclaration lookupVariant(String name) {
- return variants.get(name);
- }
-
- /**
- * Looks up a variant declaration in the current scope and recursively in
- * the parent scopes.
- *
- * @param name
- * The name of the variant to search for.
- * @return The variant declaration, or null if no variant with that name has
- * been defined.
- */
- public VariantDeclaration rlookupVariant(String name) {
- VariantDeclaration declaration = lookupVariant(name);
- if (declaration != null) {
- return declaration;
- } else if (parentScope != null) {
- return parentScope.rlookupVariant(name);
- } else {
- return null;
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.event.metadata.exceptions;
-
-/**
- * <b><u>ParseException</u></b>
- */
-public class ParseException extends Exception {
-
- private static final long serialVersionUID = 7901917601459652080L;
-
- public ParseException() {
- super();
- }
-
- /**
- * Constructor
- *
- * @param message
- */
- public ParseException(String message) {
- super(message);
- }
-
-}
import java.util.UUID;
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
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.IDefinitionScope;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.internal.ctf.core.Activator;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
/**
* <b><u>CTFTrace</u></b>
{
return 0;
}
- return (Long) getClock().getProperty("offset");
+ return (Long) getClock().getProperty("offset"); //$NON-NLS-1$
}
}
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.internal.ctf.core.Activator;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputReaderTimestampComparator;
/**
* Reads the events of a trace.
int len = (width * this.eventCountPerTraceFile[se.getName()])
/ numEvents;
- StringBuilder sb = new StringBuilder(se.getStreamInput()
- .getFilename() + "\t["); //$NON-NLS-1$
+ StringBuilder sb = new StringBuilder(se.getFilename() + "\t["); //$NON-NLS-1$
for (int i = 0; i < len; i++) {
sb.append('+');
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.CommonTree;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.ctf.parser.CTFLexer;
import org.eclipse.linuxtools.ctf.parser.CTFParser;
import org.eclipse.linuxtools.ctf.parser.CTFParser.parse_return;
import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
/**
* <b><u>Metadata</u></b>
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
-
-/**
- * <b><u>Stream</u></b>
- * <p>
- * Represents a stream in a trace.
- */
-public class Stream {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
-
- /**
- * The numerical ID of the stream
- */
- private Long id = null;
-
- /**
- * Declarations of the stream-specific structures
- */
- private StructDeclaration packetContextDecl = null;
- private StructDeclaration eventHeaderDecl = null;
- private StructDeclaration eventContextDecl = null;
-
- /**
- * The trace to which the stream belongs
- */
- private CTFTrace trace = null;
-
- /**
- * Maps event ids to events
- */
- private final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
-
- /**
- * The inputs associated to this stream
- */
- private final Set<StreamInput> inputs = new HashSet<StreamInput>();
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Constructs a Stream that belongs to a Trace
- *
- * @param trace
- * The trace to which belongs this stream.
- */
- public Stream(CTFTrace trace) {
- this.trace = trace;
- }
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- public void setId(long id) {
- this.id = id;
- }
-
- public Long getId() {
- return id;
- }
-
- public boolean idIsSet() {
- return id != null;
- }
-
- public boolean eventHeaderIsSet() {
- return eventHeaderDecl != null;
- }
-
- public boolean eventContextIsSet() {
- return eventContextDecl != null;
- }
-
- public boolean packetContextIsSet() {
- return packetContextDecl != null;
- }
-
- public void setEventHeader(StructDeclaration eventHeader) {
- this.eventHeaderDecl = eventHeader;
- }
-
- public void setEventContext(StructDeclaration eventContext) {
- this.eventContextDecl = eventContext;
- }
-
- public void setPacketContext(StructDeclaration packetContext) {
- this.packetContextDecl = packetContext;
- }
-
- public StructDeclaration getEventHeaderDecl() {
- return eventHeaderDecl;
- }
-
- public StructDeclaration getEventContextDecl() {
- return eventContextDecl;
- }
-
- public StructDeclaration getPacketContextDecl() {
- return packetContextDecl;
- }
-
- public Set<StreamInput> getStreamInputs() {
- return inputs;
- }
-
- public CTFTrace getTrace() {
- return trace;
- }
-
- public HashMap<Long, EventDeclaration> getEvents() {
- return events;
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- /**
- * Adds an event to the event map.
- *
- * An event in a stream can omit its id if it is the only event in this
- * stream. An event for which no id has been specified has a null id. It is
- * thus not possible to add an event with the null key if the map is not
- * empty. It is also not possible to add an event to the map if the null key
- * is present in the map.
- *
- * @param event
- * The event to add.
- * @throws ParseException
- */
- public void addEvent(EventDeclaration event) throws ParseException {
- /*
- * If there is an event without id (the null key), it must be the only
- * one
- */
- if (events.get(null) != null) {
- throw new ParseException(
- "Event without id with multiple events in a stream"); //$NON-NLS-1$
- }
-
- /*
- * If there is an event without id (the null key), it must be the only
- * one
- */
- if ((event.getId() == null) && (events.size() != 0)) {
- throw new ParseException(
- "Event without id with multiple events in a stream"); //$NON-NLS-1$
- }
-
- /* Check if an event with the same ID already exists */
- if (events.get(event.getId()) != null) {
- throw new ParseException("Event id already exists"); //$NON-NLS-1$
- }
-
- /* Put the event in the map */
- events.put(event.getId(), event);
- }
-
- /**
- * Add an input to this Stream
- *
- * @param input
- * The StreamInput to add.
- */
- public void addInput(StreamInput input) {
- inputs.add(input);
- }
-
-
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$
- + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$
- + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$
- + ", events=" + events + ", inputs=" + inputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.channels.FileChannel.MapMode;
-import java.util.UUID;
-
-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.IDefinitionScope;
-import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
-import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-/**
- * <b><u>StreamInput</u></b>
- * <p>
- * Represents a trace file that belongs to a certain stream.
- */
-public class StreamInput implements IDefinitionScope {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /**
- * The associated Stream
- */
- private final Stream stream;
-
- /**
- * FileChannel to the trace file
- */
- private final FileChannel fileChannel;
-
- /**
- * Information on the file (used for debugging)
- */
- public final File file;
-
- /**
- * The packet index of this input
- */
- private final StreamInputPacketIndex index = new StreamInputPacketIndex();
-
- private long timestampEnd;
-
- // ------------------------------------------------------------------------
- // Constructors
- // ------------------------------------------------------------------------
-
- /**
- * Constructs a StreamInput.
- *
- * @param stream
- * The stream to which this StreamInput belongs to.
- * @param fileChannel
- * The FileChannel to the trace file.
- * @param file
- * Information about the trace file (for debugging purposes).
- */
- public StreamInput(Stream stream, FileChannel fileChannel, File file) {
- this.stream = stream;
- this.fileChannel = fileChannel;
- this.file = file;
- }
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- public Stream getStream() {
- return stream;
- }
-
- public StreamInputPacketIndex getIndex() {
- return index;
- }
-
- public FileChannel getFileChannel() {
- return fileChannel;
- }
-
- public String getFilename() {
- return file.getName();
- }
-
- public long getTimestampEnd() {
- return timestampEnd;
- }
-
- public void setTimestampEnd(long timestampEnd) {
- this.timestampEnd = timestampEnd;
- }
-
- @Override
- public String getPath() {
- return ""; //$NON-NLS-1$
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- @Override
- public Definition lookupDefinition(String lookupPath) {
- /* TODO: lookup in different dynamic scopes is not supported yet. */
- return null;
- }
-
- /**
- * Create the index for this trace file.
- *
- * @throws CTFReaderException
- */
- public void createIndex() throws CTFReaderException {
- /*
- * The size of the file in bytes
- */
- long fileSizeBytes = 0;
- try {
- fileSizeBytes = fileChannel.size();
- } catch (IOException e) {
- throw new CTFReaderException(e);
- }
-
- /*
- * Offset of the current packet in bytes
- */
- long packetOffsetBytes = 0;
-
- /*
- * Initial size, it should map at least the packet header + context
- * size.
- *
- * TODO: use a less arbitrary size.
- */
- long mapSize = 4096;
-
- /*
- * Definition of trace packet header
- */
- StructDefinition tracePacketHeaderDef = null;
-
- /*
- * Definition of trace stream packet context
- */
- StructDefinition streamPacketContextDef = null;
-
- /*
- * The BitBuffer to extract data from the StreamInput
- */
- BitBuffer bitBuffer = new BitBuffer();
- bitBuffer.order(this.getStream().getTrace().getByteOrder());
-
- /*
- * Create the definitions we need to read the packet headers + contexts
- */
- if (getStream().getTrace().getPacketHeader() != null) {
- tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
- .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
- }
-
- if (getStream().getPacketContextDecl() != null) {
- streamPacketContextDef = getStream().getPacketContextDecl()
- .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
- }
-
- /*
- * Scan through the packets of the file.
- */
- while (packetOffsetBytes < fileSizeBytes) {
- /*
- * If there is less data remaining than what we want to map, reduce
- * the map size.
- */
- if ((fileSizeBytes - packetOffsetBytes) < mapSize) {
- mapSize = fileSizeBytes - packetOffsetBytes;
- }
-
- /*
- * Map the packet.
- */
- MappedByteBuffer bb;
- try {
- bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes,
- mapSize);
- } catch (IOException e) {
- throw new CTFReaderException(e);
- }
- bitBuffer.setByteBuffer(bb);
-
- /*
- * Create the index entry
- */
- StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
- packetOffsetBytes);
-
- /*
- * Read the trace packet header if it exists.
- */
- if (tracePacketHeaderDef != null) {
- tracePacketHeaderDef.read(bitBuffer);
-
- /*
- * Check the CTF magic number
- */
- IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
- .lookupDefinition("magic"); //$NON-NLS-1$
- if (magicDef != null) {
- int magic = (int) magicDef.getValue();
- if (magic != Utils.CTF_MAGIC) {
- throw new CTFReaderException(
- "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
- }
-
- }
-
- /*
- * Check the trace UUID
- */
- ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef
- .lookupDefinition("uuid"); //$NON-NLS-1$
- if (uuidDef != null) {
- byte[] uuidArray = new byte[16];
-
- for (int i = 0; i < 16; i++) {
- IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
- .getElem(i);
- uuidArray[i] = (byte) uuidByteDef.getValue();
- }
-
- UUID uuid = Utils.makeUUID(uuidArray);
-
- if (!getStream().getTrace().getUUID().equals(uuid)) {
- throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
- }
- }
-
- /*
- * Check that the stream id did not change
- */
- IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
- .lookupDefinition("stream_id"); //$NON-NLS-1$
- if (streamIDDef != null) {
- long streamID = streamIDDef.getValue();
-
- if (streamID != getStream().getId()) {
- throw new CTFReaderException(
- "Stream ID changing within a StreamInput"); //$NON-NLS-1$
- }
- }
- }
-
- /*
- * Read the stream packet context if it exists.
- */
- if (streamPacketContextDef != null) {
- streamPacketContextDef.read(bitBuffer);
-
- /*
- * Read the content size in bits
- */
- IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("content_size"); //$NON-NLS-1$
- if (contentSizeDef != null) {
- packetIndex.setContentSizeBits((int) contentSizeDef
- .getValue());
- } else {
- packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
- }
-
- /*
- * Read the packet size in bits
- */
- IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("packet_size"); //$NON-NLS-1$
- if (packetSizeDef != null) {
- packetIndex.setPacketSizeBits((int) packetSizeDef
- .getValue());
- } else {
- if (packetIndex.getContentSizeBits() != 0) {
- packetIndex.setPacketSizeBits(packetIndex
- .getContentSizeBits());
- } else {
- packetIndex
- .setPacketSizeBits((int) (fileSizeBytes * 8));
- }
- }
-
- /*
- * Read the begin timestamp
- */
- IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
- if (timestampBeginDef != null) {
- packetIndex.setTimestampBegin( timestampBeginDef.getValue());
- }
-
- /*
- * Read the end timestamp
- */
- IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
- .lookupDefinition("timestamp_end"); //$NON-NLS-1$
- if (timestampEndDef != null) {
- packetIndex.setTimestampEnd(timestampEndDef
- .getValue());
- setTimestampEnd(packetIndex.getTimestampEnd());
- }
- } else {
- /*
- * If there is no packet context, infer the content and packet
- * size from the file size (assume that there is only one packet
- * and no padding)
- */
- packetIndex.setContentSizeBits( (int) (fileSizeBytes * 8));
- packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
- }
-
- /* Basic validation */
- if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
- throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
- }
-
- if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex.getOffsetBytes()) * 8)) {
- throw new CTFReaderException(
- "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
- }
-
- /*
- * Offset in the file, in bits
- */
- packetIndex.setDataOffsetBits( bitBuffer.position());
-
- /*
- * Add the packet index entry to the index
- */
- index.addEntry(packetIndex);
-
- /*
- * Update the counting packet offset
- */
- packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
-
- }
- index.getEntries().get(0).setIndexBegin(0L);
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.util.ListIterator;
-import java.util.Vector;
-
-import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
-
-/**
- * <b><u>StreamInputPacketIndex</u></b>
- * <p>
- * TODO Implement me. Please.
- */
-public class StreamInputPacketIndex {
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- /**
- * Entries of the index. They are sorted by increasing begin timestamp.
- * index builder.
- */
- private final Vector<StreamInputPacketIndexEntry> entries = new Vector<StreamInputPacketIndexEntry>();
-
- // ------------------------------------------------------------------------
- // Getters/Setters/Predicates
- // ------------------------------------------------------------------------
-
- public Vector<StreamInputPacketIndexEntry> getEntries() {
- return this.entries;
- }
-
- public ListIterator<StreamInputPacketIndexEntry> listIterator() {
- return this.entries.listIterator();
- }
-
- public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
- return this.entries.listIterator(n);
- }
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- /**
- * Adds an entry to the index.
- *
- * @param entry
- * The entry to add
- * @throws CTFReaderException
- */
- public void addEntry(StreamInputPacketIndexEntry entry)
- throws CTFReaderException {
- assert (entry.getContentSizeBits() != 0);
- assert (entry.getContentSizeBits() != 0);
-
- if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
- throw new CTFReaderException(
- "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
- }
-
- if (!this.entries.isEmpty()) {
- if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
- throw new CTFReaderException(
- "Packets begin timestamp decreasing"); //$NON-NLS-1$
- }
- }
-
- this.entries.add(entry);
- }
-
- /**
- * Given a timestamp, this methods returns the first PacketIndexEntry that
- * could include the timestamp, that is the last packet with a begin
- * timestamp smaller than the given timestamp.
- *
- * @param timestamp
- * The timestamp to look for.
- * @return The StreamInputPacketEntry that corresponds to the packet that
- * includes the given timestamp.
- */
- public ListIterator<StreamInputPacketIndexEntry> search(final long timestamp) {
- /*
- * Start with min and max covering all the elements.
- */
- int max = this.entries.size() - 1;
- int min = 0;
-
- int guessI;
- StreamInputPacketIndexEntry guessEntry = null;
-
- if (timestamp < 0) {
- throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$
- }
-
- for (;;) {
- /*
- * Guess in the middle of min and max. The +1 is so that in case
- * (min + 1 == max), we choose the packet at the subscript "max"
- * instead of the one at "min". Otherwise, it would give an infinite
- * loop.
- */
- guessI = (max + min + 1) / 2;
- guessEntry = this.entries.get(guessI);
-
- /*
- * If we reached the point where we focus on a single packet, our
- * search is done.
- */
- if (min == max) {
- break;
- }
-
- if (timestamp < guessEntry.getTimestampBegin()) {
- /*
- * If the timestamp if before the begin timestamp, we know that
- * the packet to return is before the guess.
- */
- max = guessI - 1;
- } else if (timestamp >= guessEntry.getTimestampBegin()) {
- /*
- * If the timestamp is after the begin timestamp, we know that
- * the packet to return is after the guess or is the guess.
- */
- min = guessI;
- }
- }
-
- return this.entries.listIterator(guessI);
- }
- /**
- * Given a rank, this methods returns the first PacketIndexEntry that
- * could include the rank, that is the last packet with a begin
- * rank smaller than the given rank.
- *
- * @param index
- * The rank to look for.
- * @return The StreamInputPacketEntry that corresponds to the packet that
- * includes the given timestamp.
- */
- public ListIterator<StreamInputPacketIndexEntry> searchIndex(final long index) {
- /*
- * Start with min and max covering all the elements.
- */
- int max = this.entries.size() - 1;
- int min = 0;
-
- int guessI;
- StreamInputPacketIndexEntry guessEntry = null;
-
- if (index < 0) {
- throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$
- }
-
- for (;;) {
- /*
- * Guess in the middle of min and max. The +1 is so that in case
- * (min + 1 == max), we choose the packet at the subscript "max"
- * instead of the one at "min". Otherwise, it would give an infinite
- * loop.
- */
- guessI = (max + min + 1) / 2;
- guessEntry = this.entries.get(guessI);
-
- /*
- * If we reached the point where we focus on a single packet, our
- * search is done.
- */
- if (min == max) {
- break;
- }
-
- if (index < guessEntry.getIndexBegin()) {
- /*
- * If the timestamp if before the begin timestamp, we know that
- * the packet to return is before the guess.
- */
- max = guessI - 1;
- } else if (index >= guessEntry.getIndexBegin()) {
- /*
- * If the timestamp is after the begin timestamp, we know that
- * the packet to return is after the guess or is the guess.
- */
- min = guessI;
- }
- }
-
- return this.entries.listIterator(guessI);
- }
-}
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDefinition;
import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
/**
* <p>
* Reads the events of a packet of a trace file.
*/
-public class StreamInputPacketReader implements IDefinitionScope {
+class StreamInputPacketReader implements IDefinitionScope {
// ------------------------------------------------------------------------
// Constants
/*
* Set the BitBuffer's byte order.
*/
- getBitBuffer().setByteOrder(streamInputReader.getStreamInput().getStream().getTrace().getByteOrder());
+ getBitBuffer().setByteOrder(streamInputReader.getByteOrder());
/*
* Create definitions needed to read the events.
package org.eclipse.linuxtools.ctf.core.trace;
+import java.nio.ByteOrder;
import java.util.ListIterator;
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInput;
import org.eclipse.linuxtools.internal.ctf.core.trace.StreamInputPacketIndexEntry;
/**
return this.packetReader.getStreamPacketContextDef();
}
- public StreamInput getStreamInput() {
- return this.streamInput;
+ public ByteOrder getByteOrder() {
+ return streamInput.getStream().getTrace().getByteOrder();
}
public int getName() {
return this.packetReader.getCPU();
}
+ public String getFilename() {
+ return streamInput.getFilename();
+ }
+
+ /*
+ * for internal use only
+ */
+ StreamInput getStreamInput() {
+ return streamInput;
+ }
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
return packetReader;
}
+
+
}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2011-2012 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
- * Contributors: Simon Marchi - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.linuxtools.ctf.core.trace;
-
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * <b><u>StreamInputReaderTimestampComparator</u></b>
- * <p>
- * Compares two StreamInputReader by their timestamp (smaller comes before).
- */
-public class StreamInputReaderTimestampComparator implements
- Comparator<StreamInputReader>, Serializable {
-
- // ------------------------------------------------------------------------
- // Constants
- // ------------------------------------------------------------------------
-
- private static final long serialVersionUID = 1066434959451875045L;
-
- // ------------------------------------------------------------------------
- // Operations
- // ------------------------------------------------------------------------
-
- @Override
- public int compare(StreamInputReader a, StreamInputReader b) {
- // TODO: use unsigned comparison to avoid sign errors if needed
- if (a.getCurrentEvent() == null) {
- return 0;
- }
- if (b.getCurrentEvent() == null) {
- return 0;
- }
- long ta = a.getCurrentEvent().timestamp;
- long tb = b.getCurrentEvent().timestamp;
-
- if (ta < tb) {
- return -1;
- } else if (ta > tb) {
- return 1;
- } else {
- return 0;
- }
- }
-
-}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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 Design and Grammar
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.metadata;
+
+import java.util.HashMap;
+
+import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.IDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+
+/**
+ * <b><u>DeclarationScope</u></b>
+ * <p>
+ * A DeclarationScope keeps track of the various CTF declarations for a given
+ * scope.
+ */
+public class DeclarationScope {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private DeclarationScope parentScope = null;
+
+ private final HashMap<String, StructDeclaration> structs = new HashMap<String, StructDeclaration>();
+ private final HashMap<String, EnumDeclaration> enums = new HashMap<String, EnumDeclaration>();
+ private final HashMap<String, VariantDeclaration> variants = new HashMap<String, VariantDeclaration>();
+ private final HashMap<String, IDeclaration> types = new HashMap<String, IDeclaration>();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Creates a declaration scope with no parent.
+ */
+ public DeclarationScope() {
+ }
+
+ /**
+ * Creates a declaration scope with the specified parent.
+ *
+ * @param parentScope
+ * The parent of the newly created scope.
+ */
+ public DeclarationScope(DeclarationScope parentScope) {
+ this.parentScope = parentScope;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ /**
+ * Returns the parent of the current scope.
+ *
+ * @return The parent scope.
+ */
+ public DeclarationScope getParentScope() {
+ return parentScope;
+ }
+
+ // ------------------------------------------------------------------------
+ // Registration operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Registers a type declaration.
+ *
+ * @param name
+ * The name of the type.
+ * @param declaration
+ * The type declaration.
+ * @throws ParseException
+ * if a type with the same name has already been defined.
+ */
+ public void registerType(String name, IDeclaration declaration)
+ throws ParseException {
+ /* Check if the type has been defined in the current scope */
+ if (types.containsKey(name)) {
+ throw new ParseException("Type " + name //$NON-NLS-1$
+ + " has already been defined."); //$NON-NLS-1$
+ }
+
+ /* Add it to the register. */
+ types.put(name, declaration);
+ }
+
+ /**
+ * Registers a struct declaration.
+ *
+ * @param name
+ * The name of the struct.
+ * @param declaration
+ * The declaration of the struct.
+ * @throws ParseException
+ * if a struct with the same name has already been registered.
+ */
+ public void registerStruct(String name, StructDeclaration declaration)
+ throws ParseException {
+ /* Check if the struct has been defined in the current scope. */
+ if (structs.containsKey(name)) {
+ throw new ParseException("struct " + name //$NON-NLS-1$
+ + " has already been defined."); //$NON-NLS-1$
+ }
+
+ /* Add it to the register. */
+ structs.put(name, declaration);
+
+ /* It also defined a new type, so add it to the type declarations. */
+ String struct_prefix = "struct "; //$NON-NLS-1$
+ registerType(struct_prefix + name, declaration);
+ }
+
+ /**
+ * Registers an enum declaration.
+ *
+ * @param name
+ * The name of the enum.
+ * @param declaration
+ * The declaration of the enum.
+ * @throws ParseException
+ * if an enum with the same name has already been registered.
+ */
+ public void registerEnum(String name, EnumDeclaration declaration)
+ throws ParseException {
+ /* Check if the enum has been defined in the current scope. */
+ if (lookupEnum(name) != null) {
+ throw new ParseException("enum " + name //$NON-NLS-1$
+ + " has already been defined."); //$NON-NLS-1$
+ }
+
+ /* Add it to the register. */
+ enums.put(name, declaration);
+
+ /* It also defined a new type, so add it to the type declarations. */
+ String enum_prefix = "enum "; //$NON-NLS-1$
+ registerType(enum_prefix + name, declaration);
+ }
+
+ /**
+ * Registers a variant declaration.
+ *
+ * @param name
+ * The name of the variant.
+ * @param declaration
+ * The declaration of the variant.
+ * @throws ParseException
+ * if a variant with the same name has already been registered.
+ */
+ public void registerVariant(String name, VariantDeclaration declaration)
+ throws ParseException {
+ /* Check if the variant has been defined in the current scope. */
+ if (lookupVariant(name) != null) {
+ throw new ParseException("variant " + name //$NON-NLS-1$
+ + " has already been defined."); //$NON-NLS-1$
+ }
+
+ /* Add it to the register. */
+ variants.put(name, declaration);
+
+ /* It also defined a new type, so add it to the type declarations. */
+ String variant_prefix = "variant "; //$NON-NLS-1$
+ registerType(variant_prefix + name, declaration);
+ }
+
+ // ------------------------------------------------------------------------
+ // Lookup operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Looks up a type declaration in the current scope.
+ *
+ * @param name
+ * The name of the type to search for.
+ * @return The type declaration, or null if no type with that name has been
+ * defined.
+ */
+ public IDeclaration lookupType(String name) {
+ return types.get(name);
+ }
+
+ /**
+ * Looks up a type declaration in the current scope and recursively in the
+ * parent scopes.
+ *
+ * @param name
+ * The name of the type to search for.
+ * @return The type declaration, or null if no type with that name has been
+ * defined.
+ */
+ public IDeclaration rlookupType(String name) {
+ IDeclaration declaration = lookupType(name);
+ if (declaration != null) {
+ return declaration;
+ } else if (parentScope != null) {
+ return parentScope.rlookupType(name);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Looks up a struct declaration.
+ *
+ * @param name
+ * The name of the struct to search for.
+ * @return The struct declaration, or null if no struct with that name has
+ * been defined.
+ */
+ public StructDeclaration lookupStruct(String name) {
+ return structs.get(name);
+ }
+
+ /**
+ * Looks up a struct declaration in the current scope and recursively in the
+ * parent scopes.
+ *
+ * @param name
+ * The name of the struct to search for.
+ * @return The struct declaration, or null if no struct with that name has
+ * been defined.
+ */
+ public StructDeclaration rlookupStruct(String name) {
+ StructDeclaration declaration = lookupStruct(name);
+ if (declaration != null) {
+ return declaration;
+ } else if (parentScope != null) {
+ return parentScope.rlookupStruct(name);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Looks up a enum declaration.
+ *
+ * @param name
+ * The name of the enum to search for.
+ * @return The enum declaration, or null if no enum with that name has been
+ * defined.
+ */
+ public EnumDeclaration lookupEnum(String name) {
+ return enums.get(name);
+ }
+
+ /**
+ * Looks up an enum declaration in the current scope and recursively in the
+ * parent scopes.
+ *
+ * @param name
+ * The name of the enum to search for.
+ * @return The enum declaration, or null if no enum with that name has been
+ * defined.
+ */
+ public EnumDeclaration rlookupEnum(String name) {
+ EnumDeclaration declaration = lookupEnum(name);
+ if (declaration != null) {
+ return declaration;
+ } else if (parentScope != null) {
+ return parentScope.rlookupEnum(name);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Looks up a variant declaration.
+ *
+ * @param name
+ * The name of the variant to search for.
+ * @return The variant declaration, or null if no variant with that name has
+ * been defined.
+ */
+ public VariantDeclaration lookupVariant(String name) {
+ return variants.get(name);
+ }
+
+ /**
+ * Looks up a variant declaration in the current scope and recursively in
+ * the parent scopes.
+ *
+ * @param name
+ * The name of the variant to search for.
+ * @return The variant declaration, or null if no variant with that name has
+ * been defined.
+ */
+ public VariantDeclaration rlookupVariant(String name) {
+ VariantDeclaration declaration = lookupVariant(name);
+ if (declaration != null) {
+ return declaration;
+ } else if (parentScope != null) {
+ return parentScope.rlookupVariant(name);
+ } else {
+ return null;
+ }
+ }
+
+}
import org.antlr.runtime.tree.CommonTree;
import org.eclipse.linuxtools.ctf.core.event.CTFClock;
import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
-import org.eclipse.linuxtools.ctf.core.event.metadata.DeclarationScope;
-import org.eclipse.linuxtools.ctf.core.event.metadata.exceptions.ParseException;
import org.eclipse.linuxtools.ctf.core.event.types.ArrayDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.Encoding;
import org.eclipse.linuxtools.ctf.core.event.types.EnumDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
import org.eclipse.linuxtools.ctf.core.event.types.VariantDeclaration;
import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
-import org.eclipse.linuxtools.ctf.core.trace.Stream;
import org.eclipse.linuxtools.ctf.parser.CTFParser;
import org.eclipse.linuxtools.internal.ctf.core.Activator;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+import org.eclipse.linuxtools.internal.ctf.core.trace.Stream;
/*
* Asserts throughout this class denote the assumptions we can make because of
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions;
+
+/**
+ * <b><u>ParseException</u></b>
+ */
+public class ParseException extends Exception {
+
+ private static final long serialVersionUID = 7901917601459652080L;
+
+ public ParseException() {
+ super();
+ }
+
+ /**
+ * Constructor
+ *
+ * @param message
+ */
+ public ParseException(String message) {
+ super(message);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
+import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
+import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
+
+/**
+ * <b><u>Stream</u></b>
+ * <p>
+ * Represents a stream in a trace.
+ */
+public class Stream {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+
+ /**
+ * The numerical ID of the stream
+ */
+ private Long id = null;
+
+ /**
+ * Declarations of the stream-specific structures
+ */
+ private StructDeclaration packetContextDecl = null;
+ private StructDeclaration eventHeaderDecl = null;
+ private StructDeclaration eventContextDecl = null;
+
+ /**
+ * The trace to which the stream belongs
+ */
+ private CTFTrace trace = null;
+
+ /**
+ * Maps event ids to events
+ */
+ private final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
+
+ /**
+ * The inputs associated to this stream
+ */
+ private final Set<StreamInput> inputs = new HashSet<StreamInput>();
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructs a Stream that belongs to a Trace
+ *
+ * @param trace
+ * The trace to which belongs this stream.
+ */
+ public Stream(CTFTrace trace) {
+ this.trace = trace;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public boolean idIsSet() {
+ return id != null;
+ }
+
+ public boolean eventHeaderIsSet() {
+ return eventHeaderDecl != null;
+ }
+
+ public boolean eventContextIsSet() {
+ return eventContextDecl != null;
+ }
+
+ public boolean packetContextIsSet() {
+ return packetContextDecl != null;
+ }
+
+ public void setEventHeader(StructDeclaration eventHeader) {
+ this.eventHeaderDecl = eventHeader;
+ }
+
+ public void setEventContext(StructDeclaration eventContext) {
+ this.eventContextDecl = eventContext;
+ }
+
+ public void setPacketContext(StructDeclaration packetContext) {
+ this.packetContextDecl = packetContext;
+ }
+
+ public StructDeclaration getEventHeaderDecl() {
+ return eventHeaderDecl;
+ }
+
+ public StructDeclaration getEventContextDecl() {
+ return eventContextDecl;
+ }
+
+ public StructDeclaration getPacketContextDecl() {
+ return packetContextDecl;
+ }
+
+ public Set<StreamInput> getStreamInputs() {
+ return inputs;
+ }
+
+ public CTFTrace getTrace() {
+ return trace;
+ }
+
+ public HashMap<Long, EventDeclaration> getEvents() {
+ return events;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Adds an event to the event map.
+ *
+ * An event in a stream can omit its id if it is the only event in this
+ * stream. An event for which no id has been specified has a null id. It is
+ * thus not possible to add an event with the null key if the map is not
+ * empty. It is also not possible to add an event to the map if the null key
+ * is present in the map.
+ *
+ * @param event
+ * The event to add.
+ * @throws ParseException
+ */
+ public void addEvent(EventDeclaration event) throws ParseException {
+ /*
+ * If there is an event without id (the null key), it must be the only
+ * one
+ */
+ if (events.get(null) != null) {
+ throw new ParseException(
+ "Event without id with multiple events in a stream"); //$NON-NLS-1$
+ }
+
+ /*
+ * If there is an event without id (the null key), it must be the only
+ * one
+ */
+ if ((event.getId() == null) && (events.size() != 0)) {
+ throw new ParseException(
+ "Event without id with multiple events in a stream"); //$NON-NLS-1$
+ }
+
+ /* Check if an event with the same ID already exists */
+ if (events.get(event.getId()) != null) {
+ throw new ParseException("Event id already exists"); //$NON-NLS-1$
+ }
+
+ /* Put the event in the map */
+ events.put(event.getId(), event);
+ }
+
+ /**
+ * Add an input to this Stream
+ *
+ * @param input
+ * The StreamInput to add.
+ */
+ public void addInput(StreamInput input) {
+ inputs.add(input);
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$
+ + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$
+ + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$
+ + ", events=" + events + ", inputs=" + inputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
+import java.util.UUID;
+
+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.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+import org.eclipse.linuxtools.ctf.core.trace.Utils;
+import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
+
+/**
+ * <b><u>StreamInput</u></b>
+ * <p>
+ * Represents a trace file that belongs to a certain stream.
+ */
+public class StreamInput implements IDefinitionScope {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /**
+ * The associated Stream
+ */
+ private final Stream stream;
+
+ /**
+ * FileChannel to the trace file
+ */
+ private final FileChannel fileChannel;
+
+ /**
+ * Information on the file (used for debugging)
+ */
+ public final File file;
+
+ /**
+ * The packet index of this input
+ */
+ private final StreamInputPacketIndex index = new StreamInputPacketIndex();
+
+ private long timestampEnd;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructs a StreamInput.
+ *
+ * @param stream
+ * The stream to which this StreamInput belongs to.
+ * @param fileChannel
+ * The FileChannel to the trace file.
+ * @param file
+ * Information about the trace file (for debugging purposes).
+ */
+ public StreamInput(Stream stream, FileChannel fileChannel, File file) {
+ this.stream = stream;
+ this.fileChannel = fileChannel;
+ this.file = file;
+ }
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ public Stream getStream() {
+ return stream;
+ }
+
+ public StreamInputPacketIndex getIndex() {
+ return index;
+ }
+
+ public FileChannel getFileChannel() {
+ return fileChannel;
+ }
+
+ public String getFilename() {
+ return file.getName();
+ }
+
+ public long getTimestampEnd() {
+ return timestampEnd;
+ }
+
+ public void setTimestampEnd(long timestampEnd) {
+ this.timestampEnd = timestampEnd;
+ }
+
+ @Override
+ public String getPath() {
+ return ""; //$NON-NLS-1$
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @SuppressWarnings("unused")
+ @Override
+ public Definition lookupDefinition(String lookupPath) {
+ /* TODO: lookup in different dynamic scopes is not supported yet. */
+ return null;
+ }
+
+ /**
+ * Create the index for this trace file.
+ *
+ * @throws CTFReaderException
+ */
+ public void createIndex() throws CTFReaderException {
+ /*
+ * The size of the file in bytes
+ */
+ long fileSizeBytes = 0;
+ try {
+ fileSizeBytes = fileChannel.size();
+ } catch (IOException e) {
+ throw new CTFReaderException(e);
+ }
+
+ /*
+ * Offset of the current packet in bytes
+ */
+ long packetOffsetBytes = 0;
+
+ /*
+ * Initial size, it should map at least the packet header + context
+ * size.
+ *
+ * TODO: use a less arbitrary size.
+ */
+ long mapSize = 4096;
+
+ /*
+ * Definition of trace packet header
+ */
+ StructDefinition tracePacketHeaderDef = null;
+
+ /*
+ * Definition of trace stream packet context
+ */
+ StructDefinition streamPacketContextDef = null;
+
+ /*
+ * The BitBuffer to extract data from the StreamInput
+ */
+ BitBuffer bitBuffer = new BitBuffer();
+ bitBuffer.order(this.getStream().getTrace().getByteOrder());
+
+ /*
+ * Create the definitions we need to read the packet headers + contexts
+ */
+ if (getStream().getTrace().getPacketHeader() != null) {
+ tracePacketHeaderDef = getStream().getTrace().getPacketHeader()
+ .createDefinition(this, "trace.packet.header"); //$NON-NLS-1$
+ }
+
+ if (getStream().getPacketContextDecl() != null) {
+ streamPacketContextDef = getStream().getPacketContextDecl()
+ .createDefinition(this, "stream.packet.context"); //$NON-NLS-1$
+ }
+
+ /*
+ * Scan through the packets of the file.
+ */
+ while (packetOffsetBytes < fileSizeBytes) {
+ /*
+ * If there is less data remaining than what we want to map, reduce
+ * the map size.
+ */
+ if ((fileSizeBytes - packetOffsetBytes) < mapSize) {
+ mapSize = fileSizeBytes - packetOffsetBytes;
+ }
+
+ /*
+ * Map the packet.
+ */
+ MappedByteBuffer bb;
+ try {
+ bb = fileChannel.map(MapMode.READ_ONLY, packetOffsetBytes,
+ mapSize);
+ } catch (IOException e) {
+ throw new CTFReaderException(e);
+ }
+ bitBuffer.setByteBuffer(bb);
+
+ /*
+ * Create the index entry
+ */
+ StreamInputPacketIndexEntry packetIndex = new StreamInputPacketIndexEntry(
+ packetOffsetBytes);
+
+ /*
+ * Read the trace packet header if it exists.
+ */
+ if (tracePacketHeaderDef != null) {
+ tracePacketHeaderDef.read(bitBuffer);
+
+ /*
+ * Check the CTF magic number
+ */
+ IntegerDefinition magicDef = (IntegerDefinition) tracePacketHeaderDef
+ .lookupDefinition("magic"); //$NON-NLS-1$
+ if (magicDef != null) {
+ int magic = (int) magicDef.getValue();
+ if (magic != Utils.CTF_MAGIC) {
+ throw new CTFReaderException(
+ "CTF magic mismatch " + Integer.toHexString(magic) + " vs " + Integer.toHexString(Utils.CTF_MAGIC)); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ }
+
+ /*
+ * Check the trace UUID
+ */
+ ArrayDefinition uuidDef = (ArrayDefinition) tracePacketHeaderDef
+ .lookupDefinition("uuid"); //$NON-NLS-1$
+ if (uuidDef != null) {
+ byte[] uuidArray = new byte[16];
+
+ for (int i = 0; i < 16; i++) {
+ IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef
+ .getElem(i);
+ uuidArray[i] = (byte) uuidByteDef.getValue();
+ }
+
+ UUID uuid = Utils.makeUUID(uuidArray);
+
+ if (!getStream().getTrace().getUUID().equals(uuid)) {
+ throw new CTFReaderException("UUID mismatch"); //$NON-NLS-1$
+ }
+ }
+
+ /*
+ * Check that the stream id did not change
+ */
+ IntegerDefinition streamIDDef = (IntegerDefinition) tracePacketHeaderDef
+ .lookupDefinition("stream_id"); //$NON-NLS-1$
+ if (streamIDDef != null) {
+ long streamID = streamIDDef.getValue();
+
+ if (streamID != getStream().getId()) {
+ throw new CTFReaderException(
+ "Stream ID changing within a StreamInput"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /*
+ * Read the stream packet context if it exists.
+ */
+ if (streamPacketContextDef != null) {
+ streamPacketContextDef.read(bitBuffer);
+
+ /*
+ * Read the content size in bits
+ */
+ IntegerDefinition contentSizeDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("content_size"); //$NON-NLS-1$
+ if (contentSizeDef != null) {
+ packetIndex.setContentSizeBits((int) contentSizeDef
+ .getValue());
+ } else {
+ packetIndex.setContentSizeBits((int) (fileSizeBytes * 8));
+ }
+
+ /*
+ * Read the packet size in bits
+ */
+ IntegerDefinition packetSizeDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("packet_size"); //$NON-NLS-1$
+ if (packetSizeDef != null) {
+ packetIndex.setPacketSizeBits((int) packetSizeDef
+ .getValue());
+ } else {
+ if (packetIndex.getContentSizeBits() != 0) {
+ packetIndex.setPacketSizeBits(packetIndex
+ .getContentSizeBits());
+ } else {
+ packetIndex
+ .setPacketSizeBits((int) (fileSizeBytes * 8));
+ }
+ }
+
+ /*
+ * Read the begin timestamp
+ */
+ IntegerDefinition timestampBeginDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("timestamp_begin"); //$NON-NLS-1$
+ if (timestampBeginDef != null) {
+ packetIndex.setTimestampBegin( timestampBeginDef.getValue());
+ }
+
+ /*
+ * Read the end timestamp
+ */
+ IntegerDefinition timestampEndDef = (IntegerDefinition) streamPacketContextDef
+ .lookupDefinition("timestamp_end"); //$NON-NLS-1$
+ if (timestampEndDef != null) {
+ packetIndex.setTimestampEnd(timestampEndDef
+ .getValue());
+ setTimestampEnd(packetIndex.getTimestampEnd());
+ }
+ } else {
+ /*
+ * If there is no packet context, infer the content and packet
+ * size from the file size (assume that there is only one packet
+ * and no padding)
+ */
+ packetIndex.setContentSizeBits( (int) (fileSizeBytes * 8));
+ packetIndex.setPacketSizeBits( (int) (fileSizeBytes * 8));
+ }
+
+ /* Basic validation */
+ if (packetIndex.getContentSizeBits() > packetIndex.getPacketSizeBits()) {
+ throw new CTFReaderException("Content size > packet size"); //$NON-NLS-1$
+ }
+
+ if (packetIndex.getPacketSizeBits() > ((fileSizeBytes - packetIndex.getOffsetBytes()) * 8)) {
+ throw new CTFReaderException(
+ "Not enough data remaining in the file for the size of this packet"); //$NON-NLS-1$
+ }
+
+ /*
+ * Offset in the file, in bits
+ */
+ packetIndex.setDataOffsetBits( bitBuffer.position());
+
+ /*
+ * Add the packet index entry to the index
+ */
+ index.addEntry(packetIndex);
+
+ /*
+ * Update the counting packet offset
+ */
+ packetOffsetBytes += (packetIndex.getPacketSizeBits() + 7) / 8;
+
+ }
+ index.getEntries().get(0).setIndexBegin(0L);
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.util.ListIterator;
+import java.util.Vector;
+
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
+/**
+ * <b><u>StreamInputPacketIndex</u></b>
+ * <p>
+ * TODO Implement me. Please.
+ */
+public class StreamInputPacketIndex {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ /**
+ * Entries of the index. They are sorted by increasing begin timestamp.
+ * index builder.
+ */
+ private final Vector<StreamInputPacketIndexEntry> entries = new Vector<StreamInputPacketIndexEntry>();
+
+ // ------------------------------------------------------------------------
+ // Getters/Setters/Predicates
+ // ------------------------------------------------------------------------
+
+ public Vector<StreamInputPacketIndexEntry> getEntries() {
+ return this.entries;
+ }
+
+ public ListIterator<StreamInputPacketIndexEntry> listIterator() {
+ return this.entries.listIterator();
+ }
+
+ public ListIterator<StreamInputPacketIndexEntry> listIterator(int n) {
+ return this.entries.listIterator(n);
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /**
+ * Adds an entry to the index.
+ *
+ * @param entry
+ * The entry to add
+ * @throws CTFReaderException
+ */
+ public void addEntry(StreamInputPacketIndexEntry entry)
+ throws CTFReaderException {
+ assert (entry.getContentSizeBits() != 0);
+ assert (entry.getContentSizeBits() != 0);
+
+ if (entry.getTimestampBegin() > entry.getTimestampEnd()) {
+ throw new CTFReaderException(
+ "Packet begin timestamp is after end timestamp"); //$NON-NLS-1$
+ }
+
+ if (!this.entries.isEmpty()) {
+ if (entry.getTimestampBegin() < this.entries.lastElement().getTimestampBegin()) {
+ throw new CTFReaderException(
+ "Packets begin timestamp decreasing"); //$NON-NLS-1$
+ }
+ }
+
+ this.entries.add(entry);
+ }
+
+ /**
+ * Given a timestamp, this methods returns the first PacketIndexEntry that
+ * could include the timestamp, that is the last packet with a begin
+ * timestamp smaller than the given timestamp.
+ *
+ * @param timestamp
+ * The timestamp to look for.
+ * @return The StreamInputPacketEntry that corresponds to the packet that
+ * includes the given timestamp.
+ */
+ public ListIterator<StreamInputPacketIndexEntry> search(final long timestamp) {
+ /*
+ * Start with min and max covering all the elements.
+ */
+ int max = this.entries.size() - 1;
+ int min = 0;
+
+ int guessI;
+ StreamInputPacketIndexEntry guessEntry = null;
+
+ if (timestamp < 0) {
+ throw new IllegalArgumentException("timestamp is negative"); //$NON-NLS-1$
+ }
+
+ for (;;) {
+ /*
+ * Guess in the middle of min and max. The +1 is so that in case
+ * (min + 1 == max), we choose the packet at the subscript "max"
+ * instead of the one at "min". Otherwise, it would give an infinite
+ * loop.
+ */
+ guessI = (max + min + 1) / 2;
+ guessEntry = this.entries.get(guessI);
+
+ /*
+ * If we reached the point where we focus on a single packet, our
+ * search is done.
+ */
+ if (min == max) {
+ break;
+ }
+
+ if (timestamp < guessEntry.getTimestampBegin()) {
+ /*
+ * If the timestamp if before the begin timestamp, we know that
+ * the packet to return is before the guess.
+ */
+ max = guessI - 1;
+ } else if (timestamp >= guessEntry.getTimestampBegin()) {
+ /*
+ * If the timestamp is after the begin timestamp, we know that
+ * the packet to return is after the guess or is the guess.
+ */
+ min = guessI;
+ }
+ }
+
+ return this.entries.listIterator(guessI);
+ }
+ /**
+ * Given a rank, this methods returns the first PacketIndexEntry that
+ * could include the rank, that is the last packet with a begin
+ * rank smaller than the given rank.
+ *
+ * @param index
+ * The rank to look for.
+ * @return The StreamInputPacketEntry that corresponds to the packet that
+ * includes the given timestamp.
+ */
+ public ListIterator<StreamInputPacketIndexEntry> searchIndex(final long index) {
+ /*
+ * Start with min and max covering all the elements.
+ */
+ int max = this.entries.size() - 1;
+ int min = 0;
+
+ int guessI;
+ StreamInputPacketIndexEntry guessEntry = null;
+
+ if (index < 0) {
+ throw new IllegalArgumentException("rank is negative"); //$NON-NLS-1$
+ }
+
+ for (;;) {
+ /*
+ * Guess in the middle of min and max. The +1 is so that in case
+ * (min + 1 == max), we choose the packet at the subscript "max"
+ * instead of the one at "min". Otherwise, it would give an infinite
+ * loop.
+ */
+ guessI = (max + min + 1) / 2;
+ guessEntry = this.entries.get(guessI);
+
+ /*
+ * If we reached the point where we focus on a single packet, our
+ * search is done.
+ */
+ if (min == max) {
+ break;
+ }
+
+ if (index < guessEntry.getIndexBegin()) {
+ /*
+ * If the timestamp if before the begin timestamp, we know that
+ * the packet to return is before the guess.
+ */
+ max = guessI - 1;
+ } else if (index >= guessEntry.getIndexBegin()) {
+ /*
+ * If the timestamp is after the begin timestamp, we know that
+ * the packet to return is after the guess or is the guess.
+ */
+ min = guessI;
+ }
+ }
+
+ return this.entries.listIterator(guessI);
+ }
+}
import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+
/**
* <b><u>StreamInputReaderComparator</u></b>
* <p>
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2011-2012 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
+ * Contributors: Simon Marchi - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.ctf.core.trace;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
+
+
+/**
+ * <b><u>StreamInputReaderTimestampComparator</u></b>
+ * <p>
+ * Compares two StreamInputReader by their timestamp (smaller comes before).
+ */
+public class StreamInputReaderTimestampComparator implements
+ Comparator<StreamInputReader>, Serializable {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+
+ private static final long serialVersionUID = 1066434959451875045L;
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ @Override
+ public int compare(StreamInputReader a, StreamInputReader b) {
+ // TODO: use unsigned comparison to avoid sign errors if needed
+ if (a.getCurrentEvent() == null) {
+ return 0;
+ }
+ if (b.getCurrentEvent() == null) {
+ return 0;
+ }
+ long ta = a.getCurrentEvent().timestamp;
+ long tb = b.getCurrentEvent().timestamp;
+
+ if (ta < tb) {
+ return -1;
+ } else if (ta > tb) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+
+}
public CtfTmfEvent getCurrentEvent() {
StreamInputReader top = super.prio.peek();
if (top != null) {
- return new CtfTmfEvent(top.getCurrentEvent(), top, ctfTmfTrace);
+ return new CtfTmfEvent(top.getCurrentEvent(), top.getFilename(), ctfTmfTrace);
}
return null;
}
import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
import org.eclipse.linuxtools.ctf.core.event.types.Definition;
import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
-import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventField;
import org.eclipse.linuxtools.tmf.core.event.ITmfEventType;
* @param eventDef
* @param top
*/
- public CtfTmfEvent(EventDefinition eventDef, StreamInputReader top,
+ public CtfTmfEvent(EventDefinition eventDef, String fileName,
CtfTmfTrace originTrace) {
this.fTrace = originTrace;
this.sourceCPU = eventDef.getCPU();
this.typeId = eventDef.getDeclaration().getId();
this.eventName = eventDef.getDeclaration().getName();
- this.fileName = top.getStreamInput().getFilename();
+ this.fileName = fileName;
/* Read the fields */
this.fContent = new CtfTmfContent(ITmfEventField.ROOT_FIELD_ID,