ctf: accelerate n-grams for ctf scopes
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Fri, 2 May 2014 04:05:29 +0000 (00:05 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 9 Jul 2014 17:21:17 +0000 (13:21 -0400)
CTF-based LTTng traces have 30-40% of their requests directed to the
same fields, this makes looking up these field _names_ faster.

Change-Id: I3cf32b10d22de04a1bd94ecadde37afa8e50b0a1
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/25861
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Tested-by: Hudson CI
18 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/StructDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/LexicalScope.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java [new file with mode: 0644]
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/Definition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ScopedDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInput.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFStreamInputReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/CTFTrace.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/EventDeclaration.java
org.eclipse.linuxtools.tmf.ctf.core.tests/src/org/eclipse/linuxtools/tmf/ctf/core/tests/CtfTmfEventFieldTest.java

index bf18deec98d993427ee77082af048c4b0ee35caf..4c2fedf6587b6ccd8f052babcfd84b4937fd10ba 100644 (file)
@@ -134,7 +134,7 @@ public class StructDefinitionTest {
     @Test
     public void testLookupArray() {
         String name = INT_ID;
-        AbstractArrayDefinition result = fixture.lookupArray2(name);
+        AbstractArrayDefinition result = fixture.lookupArrayDefinition(name);
         assertNull(result);
     }
 
@@ -185,7 +185,7 @@ public class StructDefinitionTest {
     @Test
     public void testLookupFixedStringDefinition() {
         String name = SEQUENCE_ID;
-        AbstractArrayDefinition result = fixture.lookupArray2(name);
+        AbstractArrayDefinition result = fixture.lookupArrayDefinition(name);
         assertNotNull(result);
     }
 
index ca2c2a954928f190202934f14534236bbe35c234..5f8650f738c989d1bdd7377cf076167e5396fba1 100644 (file)
@@ -219,7 +219,7 @@ public class VariantDefinitionTest {
      */
     @Test
     public void testLookupArray() {
-        AbstractArrayDefinition result = fixture.lookupArray2(ENUM_3);
+        AbstractArrayDefinition result = fixture.lookupArrayDefinition(ENUM_3);
         assertNull(result);
     }
 
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderScope.java
new file mode 100644 (file)
index 0000000..e5d3d89
--- /dev/null
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * A lttng specific speedup node (the packet header with ID and V) of a lexical
+ * scope
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public class EventHeaderScope extends LexicalScope {
+
+    /**
+     * Event header id string
+     */
+    public static final LexicalScope EVENT_HEADER_ID = new LexicalScope(EVENT_HEADER, "id"); //$NON-NLS-1$
+
+    /**
+     * Event header v as in variant string
+     */
+    public static final LexicalScope EVENT_HEADER_V = new EventHeaderVScope(EVENT_HEADER, "v"); //$NON-NLS-1$
+
+    /**
+     * The scope constructor
+     *
+     * @param parent
+     *            The parent node, can be null, but shouldn't
+     * @param name
+     *            the name of the field
+     */
+    public EventHeaderScope(LexicalScope parent, String name) {
+        super(parent, name);
+    }
+
+    @Override
+    @Nullable
+    public LexicalScope getChild(String name) {
+        if (name.equals(EVENT_HEADER_ID.getName())) {
+            return EVENT_HEADER_ID;
+        }
+        if (name.equals(EVENT_HEADER_V.getName())) {
+            return EVENT_HEADER_V;
+        }
+        return super.getChild(name);
+    }
+
+    @Override
+    public String toString() {
+        return "event.header"; //$NON-NLS-1$
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/EventHeaderVScope.java
new file mode 100644 (file)
index 0000000..7b213c2
--- /dev/null
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * A lttng specific speedup node (v variant for event headers) of a lexical
+ * scope they normally contain a timestamp
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public class EventHeaderVScope extends LexicalScope {
+
+    /**
+     * Packet header v id string
+     */
+    public static final LexicalScope PACKET_HEADER_V_ID = new LexicalScope(PACKET_HEADER, "id"); //$NON-NLS-1$
+    /**
+     * Packet header v timestamp string
+     */
+    public static final LexicalScope PACKET_HEADER_V_TIMESTAMP = new LexicalScope(PACKET_HEADER, "timestamp"); //$NON-NLS-1$
+
+    /**
+     * The scope constructor
+     *
+     * @param parent
+     *            The parent node, can be null, but shouldn't
+     * @param name
+     *            the name of the field
+     */
+    public EventHeaderVScope(LexicalScope parent, String name) {
+        super(parent, name);
+    }
+
+    @Override
+    @Nullable
+    public LexicalScope getChild(String name) {
+        if (name.equals(PACKET_HEADER_V_TIMESTAMP.getName())) {
+            return PACKET_HEADER_V_TIMESTAMP;
+        }
+        if (name.equals(PACKET_HEADER_V_ID.getName())) {
+            return PACKET_HEADER_V_ID;
+        }
+        return super.getChild(name);
+    }
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/FieldsScope.java
new file mode 100644 (file)
index 0000000..1740cd7
--- /dev/null
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * A lttng specific speedup node field scope of a lexical scope
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public class FieldsScope extends LexicalScope {
+
+    /**
+     * ret field
+     */
+    public static final LexicalScope FIELDS_RET = new LexicalScope(FIELDS, "_ret"); //$NON-NLS-1$
+
+    /**
+     * tid field
+     */
+    public static final LexicalScope FIELDS_TID = new LexicalScope(FIELDS, "_tid"); //$NON-NLS-1$
+
+    /**
+     * The scope constructor
+     *
+     * @param parent
+     *            The parent node, can be null, but shouldn't
+     * @param name
+     *            the name of the field
+     */
+    public FieldsScope(LexicalScope parent, String name) {
+        super(parent, name);
+    }
+
+    @Override
+    @Nullable
+    public LexicalScope getChild(String name) {
+        if (name.equals(FIELDS_RET.getName())) {
+            return FIELDS_RET;
+        }
+        if (name.equals(FIELDS_TID.getName())) {
+            return FIELDS_TID;
+        }
+        return super.getChild(name);
+    }
+
+}
index daa6215d3a125ecf3d4500d6c3f611169e833c34..f219d9f79fb537a3ac364e31e4cba8e465df0f46 100644 (file)
@@ -34,7 +34,7 @@ public class LexicalScope implements Comparable<LexicalScope> {
      *
      * @since 3.0
      */
-    public static final LexicalScope ROOT = new LexicalScope(null, ""); //$NON-NLS-1$
+    public static final LexicalScope ROOT = new RootScope();
 
     /**
      * Trace string
@@ -84,7 +84,7 @@ public class LexicalScope implements Comparable<LexicalScope> {
      * @since 3.0
      *
      */
-    public static final LexicalScope PACKET_HEADER = new LexicalScope(PACKET, "header"); //$NON-NLS-1$
+    public static final LexicalScope PACKET_HEADER = new PacketHeaderScope();
 
     /**
      * Stream packet scope
@@ -135,12 +135,19 @@ public class LexicalScope implements Comparable<LexicalScope> {
      */
     public static final LexicalScope STREAM_EVENT_HEADER = new LexicalScope(STREAM_EVENT, "header"); //$NON-NLS-1$
 
+    /**
+     * Event header
+     *
+     * @since 3.1
+     */
+    public static final LexicalScope EVENT_HEADER = new EventHeaderScope(EVENT, "header"); //$NON-NLS-1$
+
     /**
      * Fields in an event
      *
      * @since 3.0
      */
-    public static final LexicalScope FIELDS = new LexicalScope(ROOT, "fields"); //$NON-NLS-1$
+    public static final LexicalScope FIELDS = new FieldsScope(ROOT, "fields"); //$NON-NLS-1$
 
     /**
      * Context of an event
@@ -170,7 +177,6 @@ public class LexicalScope implements Comparable<LexicalScope> {
     private final String fPath;
     private final Map<String, LexicalScope> fChildren;
 
-
     /**
      * The scope constructor
      *
@@ -187,7 +193,8 @@ public class LexicalScope implements Comparable<LexicalScope> {
                 pathString = pathString.substring(1);
             }
             if (pathString == null) {
-                // we should get an NPE on pathString.startsWith before getting this
+                // we should get an NPE on pathString.startsWith before getting
+                // this
                 throw new IllegalStateException(
                         "Lexical scope constructor had null pathstring for " + //$NON-NLS-1$
                                 parent.toString() + " and " + name); //$NON-NLS-1$
@@ -240,7 +247,7 @@ public class LexicalScope implements Comparable<LexicalScope> {
 
     @Override
     public String toString() {
-        return fPath + '.' + fName;
+        return (fPath.isEmpty() ? fName : fPath + '.' + fName);
     }
 
     @Override
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/PacketHeaderScope.java
new file mode 100644 (file)
index 0000000..a47101c
--- /dev/null
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * A lttng specific speedup node (the packet header with magic, uuid and stream
+ * id ) of a lexical scope the sole reason to have this is to accelerate tostring()
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public class PacketHeaderScope extends LexicalScope {
+
+    /**
+     * Constructor
+     */
+    public PacketHeaderScope() {
+        super(PACKET, "header"); //$NON-NLS-1$
+    }
+
+    @Override
+    public String toString() {
+        return "packet.header"; //$NON-NLS-1$
+    }
+
+}
diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/scope/RootScope.java
new file mode 100644 (file)
index 0000000..ab187df
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.ctf.core.event.scope;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.eclipse.jdt.annotation.Nullable;
+
+/**
+ * A lttng specific speedup node a root with accelerated returns for some scopes
+ * of a lexical scope
+ *
+ * @author Matthew Khouzam
+ * @since 3.1
+ */
+@NonNullByDefault
+public class RootScope extends LexicalScope {
+
+    /**
+     * The scope constructor
+     */
+    public RootScope() {
+        super(null, ""); //$NON-NLS-1$
+    }
+
+    @Override
+    @Nullable
+    public LexicalScope getChild(String name) {
+        /*
+         * This happens ~40 % of the time
+         */
+        if (name.equals(EVENT_HEADER.toString())) {
+            return EVENT_HEADER;
+        }
+        /*
+         * This happens ~30 % of the time
+         */
+        if (name.equals(FIELDS.toString())) {
+            return FIELDS;
+        }
+        /*
+         * This happens ~30 % of the time
+         */
+        if (name.equals(CONTEXT.toString())) {
+            return CONTEXT;
+        }
+        /*
+         * This happens ~1 % of the time
+         */
+        if (name.equals(PACKET_HEADER.toString())) {
+            return PACKET_HEADER;
+        }
+        return super.getChild(name);
+    }
+
+}
index a690b46b87741b8ea92eca4df9d739a60939e1d1..683b68d45527611fffdde338f2b5058269e66613 100644 (file)
@@ -65,10 +65,31 @@ public abstract class Definition {
      * @since 3.0
      */
     public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName) {
+        this(declaration, definitionScope, fieldName, declaration.getPath(definitionScope, fieldName));
+    }
+
+    /**
+     * Constructor This one takes the scope and thus speeds up definition creation
+     *
+     *
+     * @param declaration
+     *            the event declaration
+     *
+     * @param definitionScope
+     *            the definition is in a scope, (normally a struct) what is it?
+     *
+     * @param fieldName
+     *            the name of the defintions. it is a field in the parent scope.
+     *
+     * @param scope
+     *            the scope
+     * @since 3.1
+     */
+    public Definition(@NonNull IDeclaration declaration, IDefinitionScope definitionScope, @NonNull String fieldName, LexicalScope scope) {
         fDeclaration = declaration;
         fDefinitionScope = definitionScope;
         fFieldName = fieldName;
-        fPath = fDeclaration.getPath(definitionScope, fieldName);
+        fPath = scope;
     }
 
     // ------------------------------------------------------------------------
index f8b7158b87e253264c2445c7c62f86edbdc2bd60..451983146344e330d145dc0ca28caf0debd76846 100644 (file)
@@ -15,6 +15,7 @@ package org.eclipse.linuxtools.ctf.core.event.types;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
 
 /**
  * Scoped defintion. a defintion where you can lookup various datatypes
@@ -42,6 +43,24 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
         super(declaration, definitionScope, fieldName);
     }
 
+    /**
+     * Constructor This one takes the scope and thus speeds up definition
+     * creation
+     *
+     * @param declaration
+     *            the parent declaration
+     * @param definitionScope
+     *            the parent scope
+     * @param fieldName
+     *            the field name
+     * @param scope
+     *            the lexical scope
+     * @since 3.1
+     */
+    public ScopedDefinition(StructDeclaration declaration, @Nullable IDefinitionScope definitionScope, String fieldName, LexicalScope scope) {
+        super(declaration, definitionScope, fieldName, scope);
+    }
+
     /**
      * Lookup an array in a struct. If the name returns a non-array (like an
      * int) then the method returns null
@@ -50,8 +69,7 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
      *            the name of the array
      * @return the array or null.
      */
-    @Nullable
-    public AbstractArrayDefinition lookupArray2(String name){
+    public @Nullable AbstractArrayDefinition lookupArrayDefinition(String name) {
         Definition def = lookupDefinition(name);
         return (AbstractArrayDefinition) ((def instanceof AbstractArrayDefinition) ? def : null);
     }
@@ -63,6 +81,7 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
      * @param name
      *            the name of the array
      * @return the array or null.
+     * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
      */
     @Deprecated
     @Nullable
@@ -110,6 +129,7 @@ public abstract class ScopedDefinition extends Definition implements IDefinition
      * @return the sequence or null if a definition is not found or it does not
      *         match the desired datatype.
      * @since 3.0
+     * @deprecated use {@link ScopedDefinition#lookupArrayDefinition(String)}
      */
     @Deprecated
     @Nullable
index fa18581ddb9e1053d1df1bf479c9dcaa74868194..c6779bfc2bf208b08dd2af8ea23c39fbde1185c5 100644 (file)
 
 package org.eclipse.linuxtools.ctf.core.event.types;
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
 
 /**
@@ -179,6 +182,44 @@ public class StructDeclaration extends Declaration {
         return structDefinition;
     }
 
+    /**
+     * Accelerated create definition
+     *
+     * @param definitionScope
+     *            the definition scope
+     * @param fieldScope
+     *            the lexical scope of this element
+     * @param input
+     *            the {@Link BitBuffer} to read
+     * @return the Struct definition
+     * @throws CTFReaderException
+     *             read error and such
+     * @since 3.1
+     */
+    public StructDefinition createDefinition(IDefinitionScope definitionScope,
+            LexicalScope fieldScope, @NonNull BitBuffer input) throws CTFReaderException {
+        alignRead(input);
+        final Definition[] myFields = new Definition[fFieldMap.size()];
+        Set<String> keySet = fFieldMap.keySet();
+        if (keySet == null) {
+            keySet = Collections.EMPTY_SET;
+            if( keySet == null ) {
+                throw new IllegalStateException();
+            }
+        }
+        StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldScope, fieldScope.getName(), keySet, myFields);
+        Iterator<Map.Entry<String, IDeclaration>> iter = fFieldMap.entrySet().iterator();
+        for (int i = 0; i < fFieldMap.size(); i++) {
+            Map.Entry<String, IDeclaration> entry = iter.next();
+            String fieldName = entry.getKey();
+            if (fieldName == null) {
+                throw new IllegalStateException();
+            }
+            myFields[i] = entry.getValue().createDefinition(structDefinition, fieldName, input);
+        }
+        return structDefinition;
+    }
+
     /**
      * Add a field to the struct
      *
index 664087654fa148962617c693cc1648b4bf98ff7a..fde0ef4431ddfeca24a8ebdb321e1b1e17660517 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.scope.IDefinitionScope;
+import org.eclipse.linuxtools.ctf.core.event.scope.LexicalScope;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -100,6 +101,35 @@ public final class StructDefinition extends ScopedDefinition {
         super(declaration, definitionScope, structFieldName);
         fFieldNames = ImmutableList.copyOf(fieldNames);
         fDefinitions = definitions;
+        if (fFieldNames.isEmpty()) {
+            fDefinitionsMap = Collections.EMPTY_MAP;
+        }
+    }
+
+    /**
+     * Constructor This one takes the scope and thus speeds up definition
+     * creation
+     *
+     * @param declaration
+     *            the parent declaration
+     * @param definitionScope
+     *            the parent scope
+     * @param scope
+     *            the scope of this variable
+     * @param structFieldName
+     *            the field name
+     * @param fieldNames
+     *            the list of fields
+     * @param definitions
+     *            the definitions
+     * @since 3.1
+     */
+    public StructDefinition(@NonNull StructDeclaration declaration,
+            IDefinitionScope definitionScope, @NonNull LexicalScope scope,
+            @NonNull String structFieldName, @NonNull Iterable<String> fieldNames, Definition[] definitions) {
+        super(declaration, definitionScope, structFieldName, scope);
+        fFieldNames = ImmutableList.copyOf(fieldNames);
+        fDefinitions = definitions;
         if (fFieldNames == null) {
             fDefinitionsMap = Collections.EMPTY_MAP;
         }
index 62b3e3377efe23c4a059fe86fdf55b077a6bd5b5..bff42f1316a0140306c5b320d82d6faff6af74b7 100644 (file)
@@ -350,7 +350,7 @@ public class CTFStreamInput implements IDefinitionScope, AutoCloseable {
 
     private void parseTracePacketHeader(StructDeclaration tracePacketHeaderDecl,
             @NonNull BitBuffer bitBuffer) throws CTFReaderException {
-        StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER.getName(), bitBuffer);
+        StructDefinition tracePacketHeaderDef = tracePacketHeaderDecl.createDefinition(fStream.getTrace(), LexicalScope.TRACE_PACKET_HEADER, bitBuffer);
 
         /*
          * Check the CTF magic number
@@ -405,7 +405,7 @@ public class CTFStreamInput implements IDefinitionScope, AutoCloseable {
     private void parsePacketContext(long fileSizeBytes,
             StructDeclaration streamPacketContextDecl, @NonNull BitBuffer bitBuffer,
             StreamInputPacketIndexEntry packetIndex) throws CTFReaderException {
-        StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(null, LexicalScope.STREAM_PACKET_CONTEXT.getName(), bitBuffer);
+        StructDefinition streamPacketContextDef = streamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT, bitBuffer);
 
         for (String field : streamPacketContextDef.getDeclaration()
                 .getFieldsList()) {
index 3a88ac31a40913818f50923aac40176d765c8f46..97c5a641e65a25c76a292b7e9d877dd585552489 100644 (file)
@@ -123,7 +123,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
      *             out of bounds exception or such
      */
     public StructDefinition getEventContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamEventContextDecl.createDefinition(this, LexicalScope.STREAM_EVENT_CONTEXT.getName(), input);
+        return fStreamEventContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_EVENT_CONTEXT, input);
     }
 
     /**
@@ -136,7 +136,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
      *             out of bounds exception or such
      */
     public StructDefinition getStreamEventHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamEventHeaderDecl.createDefinition(this, LexicalScope.STREAM_EVENT_HEADER.getName(), input);
+        return fStreamEventHeaderDecl.createDefinition(this, LexicalScope.EVENT_HEADER, input);
     }
 
     /**
@@ -149,7 +149,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
      *             out of bounds exception or such
      */
     public StructDefinition getStreamPacketContextDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fStreamPacketContextDecl.createDefinition(this, LexicalScope.STREAM_PACKET_CONTEXT.getName(), input);
+        return fStreamPacketContextDecl.createDefinition(fStreamInputReader.getStreamInput(), LexicalScope.STREAM_PACKET_CONTEXT, input);
     }
 
     /**
@@ -162,7 +162,7 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
      *             out of bounds exception or such
      */
     public StructDefinition getTracePacketHeaderDefinition(@NonNull BitBuffer input) throws CTFReaderException {
-        return fTracePacketHeaderDecl.createDefinition(this, LexicalScope.TRACE_PACKET_HEADER.getName(), input);
+        return fTracePacketHeaderDecl.createDefinition(fStreamInputReader.getStreamInput().getStream().getTrace(), LexicalScope.TRACE_PACKET_HEADER, input);
     }
 
     /**
index df445750e1347f38fd8615e97bb9b7820eaeabc7..1a91b1bcb90b431c85617ad648199bec37bb8f44 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.nio.ByteOrder;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.ctf.core.event.EventDefinition;
 import org.eclipse.linuxtools.ctf.core.event.IEventDeclaration;
 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
@@ -37,7 +38,7 @@ public class CTFStreamInputReader implements AutoCloseable {
     /**
      * The StreamInput we are reading.
      */
-    private final CTFStreamInput fStreamInput;
+    private final @NonNull CTFStreamInput fStreamInput;
 
     /**
      * The packet reader used to read packets from this trace file.
@@ -77,6 +78,9 @@ public class CTFStreamInputReader implements AutoCloseable {
      *             if an error occurs
      */
     public CTFStreamInputReader(CTFStreamInput streamInput) throws CTFReaderException {
+        if (streamInput == null) {
+            throw new IllegalArgumentException("streamInput cannot be null"); //$NON-NLS-1$
+        }
         fStreamInput = streamInput;
         fPacketReader = new CTFStreamInputPacketReader(this);
         /*
@@ -431,7 +435,7 @@ public class CTFStreamInputReader implements AutoCloseable {
         int result = 1;
         result = (prime * result) + fId;
         result = (prime * result)
-                + ((fStreamInput == null) ? 0 : fStreamInput.hashCode());
+                + fStreamInput.hashCode();
         return result;
     }
 
@@ -450,14 +454,7 @@ public class CTFStreamInputReader implements AutoCloseable {
         if (fId != other.fId) {
             return false;
         }
-        if (fStreamInput == null) {
-            if (other.fStreamInput != null) {
-                return false;
-            }
-        } else if (!fStreamInput.equals(other.fStreamInput)) {
-            return false;
-        }
-        return true;
+        return fStreamInput.equals(other.fStreamInput);
     }
 
     @Override
index 5704755347b26a7e2d07a8caf5c3458d0500ff60..6ab6af2344968aaf0bb52e2299069a7db9161f0f 100644 (file)
@@ -510,7 +510,7 @@ public class CTFTrace implements IDefinitionScope, AutoCloseable {
 
         if (fPacketHeaderDecl != null) {
             /* Read the packet header */
-            fPacketHeaderDef = fPacketHeaderDecl.createDefinition(null, LexicalScope.PACKET_HEADER.toString(), streamBitBuffer);
+            fPacketHeaderDef = fPacketHeaderDecl.createDefinition(this, LexicalScope.PACKET_HEADER, streamBitBuffer);
 
             /* Check the magic number */
             IntegerDefinition magicDef = (IntegerDefinition) fPacketHeaderDef.lookupDefinition("magic"); //$NON-NLS-1$
index f76330fbb68b8b030da38ed966eebc8386f92534..5e40f57458d8d55798806fe58d5d12de4732d8dd 100644 (file)
@@ -36,10 +36,6 @@ import org.eclipse.linuxtools.ctf.core.trace.CTFStreamInputReader;
  */
 public class EventDeclaration implements IEventDeclaration {
 
-    @NonNull private static final String FIELDS = "fields"; //$NON-NLS-1$
-
-    @NonNull private static final String CONTEXT = "context"; //$NON-NLS-1$
-
     /** Id of lost events */
     public static final long LOST_EVENT_ID = -1L;
 
@@ -97,10 +93,10 @@ public class EventDeclaration implements IEventDeclaration {
     @Override
     public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, @NonNull BitBuffer input, long timestamp) throws CTFReaderException {
         StructDeclaration streamEventContextDecl = streamInputReader.getStreamEventContextDecl();
-        StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(null, LexicalScope.STREAM_EVENT_CONTEXT.toString(), input) : null;
+        StructDefinition streamEventContext = streamEventContextDecl != null ? streamEventContextDecl.createDefinition(fStream.getTrace(), LexicalScope.STREAM_EVENT_CONTEXT, input) : null;
         StructDefinition packetContext = streamInputReader.getPacketReader().getCurrentPacketEventHeader();
-        StructDefinition eventContext = fContext != null ? fContext.createDefinition(null, CONTEXT, input) : null;
-        StructDefinition eventPayload = fFields != null ? fFields.createDefinition(null, FIELDS, input) : null;
+        StructDefinition eventContext = fContext != null ? fContext.createDefinition(fStream.getTrace(), LexicalScope.CONTEXT, input) : null;
+        StructDefinition eventPayload = fFields != null ? fFields.createDefinition(fStream.getTrace(), LexicalScope.FIELDS, input) : null;
 
         // a bit lttng specific
         // CTF doesn't require a timestamp,
index 2ae1c5384c91c5167df84a9eb713f0aa61efaf4a..2d0455629ec2ef9cdb8558c1a98fbae11b58317d 100644 (file)
@@ -190,7 +190,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_float() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_FLOAT);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_FLOAT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[2.0, 2.0]", result.toString());
     }
@@ -211,7 +211,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_int() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_INT);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_INT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[2, 2]", result.toString());
     }
@@ -254,7 +254,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_string() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_STR);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_STR);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[two, two]", result.toString());
     }
@@ -275,7 +275,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_struct() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_STRUCT);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_STRUCT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[[str=two, int=2], [str=two, int=2]]", result.toString());
     }
@@ -296,7 +296,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_enum() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_ENUM);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_ENUM);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[float, float]", result.toString());
     }
@@ -317,7 +317,7 @@ public class CtfTmfEventFieldTest {
      */
     @Test
     public void testParseField_array_variant() {
-        Definition fieldDef = fixture.lookupArray2(ARRAY_VARIANT);
+        Definition fieldDef = fixture.lookupArrayDefinition(ARRAY_VARIANT);
         CtfTmfEventField result = CtfTmfEventField.parseField(fieldDef, NAME);
         assertEquals("test=[float=2.0, float=2.0]", result.toString());
     }
This page took 0.049827 seconds and 5 git commands to generate.