Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [linuxtools-dev] CTF timestamps in big endian

This is a preliminary proof of concept... that bug ran deep.
On 12-08-30 12:27 PM, Gerlando Falauto wrote:
> Hi everyone,
>
> I am trying to use the stock LTTng plugin that came with the Eclipse IDE 
> for C/C++ Developers, Juno (version number looks like 
> 1.0.0.201206130106) in order to view Kernel CTF traces generated by 
> LTTng 2.0 on two different embedded targets (ARM and PowerPC).
>
> While on ARM (little endian) everything seems to work fine, on PowerPC 
> (big endian) I get absolutely meaningless timestamps, ranging to years 
> 2050, 2145, and so on...
> I get huge gaps (as I see only the time of day part, it looks like 
> hours, but it might be as well be years!) between consecutive events.
>
> Groups of adjacent events do sometimes get displayed with reasonably 
> close timestamps though (I guess for those events which got dumped with 
> a compact representation of the timestamp and/or header).
>
> The output of babeltrace for the same trace looks OK.
>
> Any other fields (pids, tids, task names, etc..) which would be affected 
> by a global endianness problem still look OK, so it's definitely 
> something related to timestamps.
>
> Any ideas? Shall I send the affected trace?
>
> Thank you,
> Gerlando
> _______________________________________________
> linuxtools-dev mailing list
> linuxtools-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/linuxtools-dev

>From 9a37eea545b53c1dd48fefb6dafa550e98c58ba2 Mon Sep 17 00:00:00 2001
From: Matthew Khouzam <matthew.khouzam@xxxxxxxxxxxx>
Date: Thu, 6 Sep 2012 18:30:27 -0400
Subject: [PATCH] Temporary fix for arm... breaks everything else.

---
 .../ctf/core/tests/headless/ReadTrace.java         |    6 +-
 .../ctf/core/event/types/IntegerDefinition.java    |   10 +-
 .../ctf/core/event/metadata/DeclarationScope.java  |   25 +++
 .../ctf/core/event/metadata/IOStructGen.java       |  166 +++++++++++---------
 4 files changed, 132 insertions(+), 75 deletions(-)

diff --git a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
index 0eb31f4..193d6a8 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
@@ -32,10 +32,10 @@ public class ReadTrace {
      */
     @SuppressWarnings("nls")
     public static void main(String[] args) {
-        final String TRACE_PATH = "traces/kernel";
+        final String TRACE_PATH = "/home/ematkho/lttng-traces/trace-arm/kernel";
 
         // Change this to enable text output
-        final boolean USE_TEXT = false;
+        final boolean USE_TEXT = true;
 
         final int LOOP_COUNT = 1;
 
@@ -49,7 +49,7 @@ public class ReadTrace {
                 nbEvent = 0L;
                 trace = new CTFTrace(TRACE_PATH);
             } catch (CTFReaderException e) {
-                // do nothing
+                e.printStackTrace();
             }
             @SuppressWarnings("unused")
             long prev = -1;
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java
index e72d6ac..a00b517 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDefinition.java
@@ -12,6 +12,8 @@
 
 package org.eclipse.linuxtools.ctf.core.event.types;
 
+import java.nio.ByteOrder;
+
 import org.eclipse.linuxtools.internal.ctf.core.event.io.BitBuffer;
 
 /**
@@ -116,8 +118,12 @@ public class IntegerDefinition extends SimpleDatatypeDefinition {
             low = low & 0x00000000FFFFFFFFL;
             long high = input.getInt(32, false);
             high = high & 0x00000000FFFFFFFFL;
-
-            bits = (high << 32) | low;
+            if( this.declaration.getByteOrder() == ByteOrder.LITTLE_ENDIAN){
+                bits = (high << 32) | low;
+            }
+            else{
+                bits = (low << 32 ) | high;
+            }
         } else {
             bits = input.getInt(length, signed);
             bits = bits & 0x00000000FFFFFFFFL;
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java
index 82ed90b..59bd1cd 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/DeclarationScope.java
@@ -308,4 +308,29 @@ public class DeclarationScope {
         }
     }
 
+
+    /**
+     * Get all the type names of this scope
+     * @return the type names
+     */
+    public String[] getTypeNames(){
+        String[] keys = new String[types.keySet().size()];
+        return types.keySet().toArray(keys);
+    }
+
+    /**
+     * replaces a type with a new one.
+     * @param name The name of the type
+     * @param newType the type
+     * @throws ParseException if the type does not exist.
+     */
+    public void replaceType(String name, IDeclaration newType) throws ParseException{
+        if(types.containsKey(name) ){
+            types.put(name, newType);
+        }else
+        {
+            throw new ParseException("Trace does not contain type: " +name);
+        }
+    }
+
 }
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
index a84a467..d596fc4 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java
@@ -170,19 +170,6 @@ public class IOStructGen {
                     childTypeError(child);
                 }
             }
-
-            if (DEBUG_) {
-                out.write("Environments\n"); //$NON-NLS-1$
-            }
-            for (CommonTree environment : environments) {
-                parseEnvironment(environment);
-            }
-            if (DEBUG_) {
-                out.write("Clocks\n"); //$NON-NLS-1$
-            }
-            for (CommonTree clock : clocks) {
-                parseClock(clock);
-            }
             if (DEBUG_) {
                 out.write("Declarations\n"); //$NON-NLS-1$
             }
@@ -192,7 +179,6 @@ public class IOStructGen {
                 }
                 parseRootDeclaration(decl);
             }
-
             if (traceNode == null) {
                 throw new ParseException("Missing trace block"); //$NON-NLS-1$
             }
@@ -200,6 +186,19 @@ public class IOStructGen {
             parseTrace(traceNode);
 
             if (DEBUG_) {
+                out.write("Environments\n"); //$NON-NLS-1$
+            }
+            for (CommonTree environment : environments) {
+                parseEnvironment(environment);
+            }
+            if (DEBUG_) {
+                out.write("Clocks\n"); //$NON-NLS-1$
+            }
+            for (CommonTree clock : clocks) {
+                parseClock(clock);
+            }
+
+            if (DEBUG_) {
                 out.write("Streams\n"); //$NON-NLS-1$
             }
             if (streams.size() > 0) {
@@ -224,8 +223,10 @@ public class IOStructGen {
             for (CommonTree event : events) {
                 parseEvent(event);
                 if (DEBUG_) {
-                    CommonTree name = (CommonTree) event.getChild(0).getChild(1).getChild(0).getChild(0);
-                    CommonTree id = (CommonTree) event.getChild(1).getChild(1).getChild(0).getChild(0);
+                    CommonTree name = (CommonTree) event.getChild(0).getChild(1).getChild(
+                            0).getChild(0);
+                    CommonTree id = (CommonTree) event.getChild(1).getChild(1).getChild(
+                            0).getChild(0);
                     out.write("Name = " + name + " Id = " + id + '\n'); //$NON-NLS-1$ //$NON-NLS-2$
                 }
             }
@@ -255,9 +256,9 @@ public class IOStructGen {
         List<CommonTree> children = clock.getChildren();
         CTFClock ctfClock = new CTFClock();
         for (CommonTree child : children) {
-            final String key = child.getChild(0).getChild(0).getChild(0)
-                    .getText();
-            final CommonTree value = (CommonTree) child.getChild(1).getChild(0).getChild(0);
+            final String key = child.getChild(0).getChild(0).getChild(0).getText();
+            final CommonTree value = (CommonTree) child.getChild(1).getChild(0).getChild(
+                    0);
             final int type = value.getType();
             switch (type) {
             case CTFParser.INTEGER:
@@ -330,8 +331,7 @@ public class IOStructGen {
 
     private void parseTraceDeclaration(CommonTree traceDecl)
             throws ParseException {
-        assert ((traceDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (traceDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
+        assert ((traceDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (traceDecl.getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
         assert (traceDecl.getChildCount() == 2);
@@ -395,6 +395,19 @@ public class IOStructGen {
                 }
             } else {
                 trace.setByteOrder(byteOrder);
+                final DeclarationScope parentScope = scope.getParentScope();
+                String types[] = parentScope.getTypeNames();
+
+                for (String type : types) {
+                    IDeclaration d = parentScope.lookupType(type);
+                    if (d instanceof IntegerDeclaration) {
+                        addByteOrder(byteOrder, parentScope, type, (IntegerDeclaration) d);
+                    }
+                    if (d instanceof StructDeclaration) {
+                        setAlign(parentScope, (StructDeclaration) d, byteOrder);
+
+                    }
+                }
             }
         } else if (left.equals(CTFStrings.PACKET_HEADER)) {
             if (trace.packetHeaderIsSet()) {
@@ -421,6 +434,42 @@ public class IOStructGen {
         }
     }
 
+    /**
+     * @param byteOrder
+     * @param parentScope
+     * @param name
+     * @param decl
+     * @throws ParseException
+     */
+    private static void addByteOrder(ByteOrder byteOrder,
+            final DeclarationScope parentScope, String name, IntegerDeclaration decl)
+            throws ParseException {
+        if (decl.getByteOrder() == null) {
+            IntegerDeclaration newI = new IntegerDeclaration(
+                    decl.getLength(), decl.isSigned(), decl.getBase(),
+                    byteOrder, decl.getEncoding(), decl.getClock(),
+                    decl.getAlignment());
+            parentScope.replaceType(name, newI);
+        }
+    }
+
+    private void setAlign(DeclarationScope parentScope, StructDeclaration sd, ByteOrder byteOrder) throws ParseException {
+        for( String s : sd.getFieldsList()){
+            IDeclaration d = sd.getFields().get(s);
+            if( d instanceof StructDeclaration ){
+                setAlign(parentScope, (StructDeclaration) d, byteOrder);
+            }
+            else if( d instanceof IntegerDeclaration ){
+                IntegerDeclaration decl = (IntegerDeclaration)d;
+                sd.getFields().put(s,  new IntegerDeclaration(
+                    decl.getLength(), decl.isSigned(), decl.getBase(),
+                    byteOrder, decl.getEncoding(), decl.getClock(),
+                    decl.getAlignment()));
+            }
+        }
+
+    }
+
     private void parseStream(CommonTree streamNode) throws ParseException {
         assert (streamNode.getType() == CTFParser.STREAM);
 
@@ -466,8 +515,7 @@ public class IOStructGen {
 
     private void parseStreamDeclaration(CommonTree streamDecl, Stream stream)
             throws ParseException {
-        assert ((streamDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (streamDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
+        assert ((streamDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (streamDecl.getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
         assert (streamDecl.getChildCount() == 2);
@@ -630,8 +678,7 @@ public class IOStructGen {
 
     private void parseEventDeclaration(CommonTree eventDecl,
             EventDeclaration event) throws ParseException {
-        assert ((eventDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (eventDecl
-                .getType() == CTFParser.CTF_EXPRESSION_VAL));
+        assert ((eventDecl.getType() == CTFParser.CTF_EXPRESSION_TYPE) || (eventDecl.getType() == CTFParser.CTF_EXPRESSION_VAL));
 
         /* There should be a left and right */
         assert (eventDecl.getChildCount() == 2);
@@ -937,8 +984,7 @@ public class IOStructGen {
 
             typeDeclarator = (CommonTree) typeDeclaratorList.getChild(0);
 
-            List<CommonTree> typeDeclaratorChildren = typeDeclarator
-                    .getChildren();
+            List<CommonTree> typeDeclaratorChildren = typeDeclarator.getChildren();
             assert (typeDeclaratorChildren != null);
 
             for (CommonTree child : typeDeclaratorChildren) {
@@ -972,16 +1018,13 @@ public class IOStructGen {
     private void parseTypedef(CommonTree typedef) throws ParseException {
         assert (typedef.getType() == CTFParser.TYPEDEF);
 
-        CommonTree typeDeclaratorListNode = (CommonTree) typedef
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
+        CommonTree typeDeclaratorListNode = (CommonTree) typedef.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
         assert (typeDeclaratorListNode != null);
 
-        CommonTree typeSpecifierListNode = (CommonTree) typedef
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
+        CommonTree typeSpecifierListNode = (CommonTree) typedef.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
         assert (typeSpecifierListNode != null);
 
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
         assert (typeDeclaratorList != null);
 
         for (CommonTree typeDeclaratorNode : typeDeclaratorList) {
@@ -1246,7 +1289,8 @@ public class IOStructGen {
             }
         }
 
-        floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, alignment);
+        floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder,
+                alignment);
 
         assert (floatDeclaration != null);
         return floatDeclaration;
@@ -1478,8 +1522,7 @@ public class IOStructGen {
                 hasName = true;
 
                 assert (child.getChildCount() == 1);
-                CommonTree structNameIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree structNameIdentifier = (CommonTree) child.getChild(0);
 
                 assert (structNameIdentifier.getType() == CTFParser.IDENTIFIER);
                 structName = structNameIdentifier.getText();
@@ -1495,8 +1538,7 @@ public class IOStructGen {
             }
             case CTFParser.ALIGN: {
                 assert (child.getChildCount() == 1);
-                CommonTree structAlignExpression = (CommonTree) child
-                        .getChild(0);
+                CommonTree structAlignExpression = (CommonTree) child.getChild(0);
 
                 structAlign = getAlignment(structAlignExpression);
 
@@ -1633,18 +1675,15 @@ public class IOStructGen {
         assert (children != null);
 
         /* Get the type specifier list node */
-        CommonTree typeSpecifierListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
+        CommonTree typeSpecifierListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
         assert (typeSpecifierListNode != null);
 
         /* Get the type declarator list node */
-        CommonTree typeDeclaratorListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
+        CommonTree typeDeclaratorListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
         assert (typeDeclaratorListNode != null);
 
         /* Get the type declarator list */
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
         assert (typeDeclaratorList != null);
 
         /*
@@ -1933,8 +1972,7 @@ public class IOStructGen {
 
         /* Get the child, which should be a type specifier list */
         assert (enumContainerType.getChildCount() == 1);
-        CommonTree typeSpecifierList = (CommonTree) enumContainerType
-                .getChild(0);
+        CommonTree typeSpecifierList = (CommonTree) enumContainerType.getChild(0);
 
         /* Parse it and get the corresponding declaration */
         IDeclaration decl = parseTypeSpecifierList(typeSpecifierList, null);
@@ -1970,8 +2008,7 @@ public class IOStructGen {
                 hasName = true;
 
                 assert (child.getChildCount() == 1);
-                CommonTree variantNameIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree variantNameIdentifier = (CommonTree) child.getChild(0);
 
                 assert (variantNameIdentifier.getType() == CTFParser.IDENTIFIER);
                 variantName = variantNameIdentifier.getText();
@@ -1983,8 +2020,7 @@ public class IOStructGen {
                 hasTag = true;
 
                 assert (child.getChildCount() == 1);
-                CommonTree variantTagIdentifier = (CommonTree) child
-                        .getChild(0);
+                CommonTree variantTagIdentifier = (CommonTree) child.getChild(0);
 
                 assert (variantTagIdentifier.getType() == CTFParser.IDENTIFIER);
                 variantTag = variantTagIdentifier.getText();
@@ -2095,18 +2131,15 @@ public class IOStructGen {
         assert (children != null);
 
         /* Get the type specifier list node */
-        CommonTree typeSpecifierListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
+        CommonTree typeSpecifierListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_SPECIFIER_LIST);
         assert (typeSpecifierListNode != null);
 
         /* Get the type declarator list node */
-        CommonTree typeDeclaratorListNode = (CommonTree) declaration
-                .getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
+        CommonTree typeDeclaratorListNode = (CommonTree) declaration.getFirstChildWithType(CTFParser.TYPE_DECLARATOR_LIST);
         assert (typeDeclaratorListNode != null);
 
         /* Get the type declarator list */
-        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode
-                .getChildren();
+        List<CommonTree> typeDeclaratorList = typeDeclaratorListNode.getChildren();
         assert (typeDeclaratorList != null);
 
         /*
@@ -2213,40 +2246,35 @@ public class IOStructGen {
             sb.append(typeSpecifier.getText());
             break;
         case CTFParser.STRUCT: {
-            CommonTree structName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.STRUCT_NAME);
+            CommonTree structName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.STRUCT_NAME);
             if (structName == null) {
                 throw new ParseException(
                         "nameless struct found in createTypeSpecifierString"); //$NON-NLS-1$
             }
             assert (structName.getChildCount() == 1);
 
-            CommonTree structNameIdentifier = (CommonTree) structName
-                    .getChild(0);
+            CommonTree structNameIdentifier = (CommonTree) structName.getChild(0);
             assert (structNameIdentifier.getType() == CTFParser.IDENTIFIER);
 
             sb.append(structNameIdentifier.getText());
             break;
         }
         case CTFParser.VARIANT: {
-            CommonTree variantName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.VARIANT_NAME);
+            CommonTree variantName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.VARIANT_NAME);
             if (variantName == null) {
                 throw new ParseException(
                         "nameless variant found in createTypeSpecifierString"); //$NON-NLS-1$
             }
             assert (variantName.getChildCount() == 1);
 
-            CommonTree variantNameIdentifier = (CommonTree) variantName
-                    .getChild(0);
+            CommonTree variantNameIdentifier = (CommonTree) variantName.getChild(0);
             assert (variantNameIdentifier.getType() == CTFParser.IDENTIFIER);
 
             sb.append(variantNameIdentifier.getText());
             break;
         }
         case CTFParser.ENUM: {
-            CommonTree enumName = (CommonTree) typeSpecifier
-                    .getFirstChildWithType(CTFParser.ENUM_NAME);
+            CommonTree enumName = (CommonTree) typeSpecifier.getFirstChildWithType(CTFParser.ENUM_NAME);
             if (enumName == null) {
                 throw new ParseException(
                         "nameless enum found in createTypeSpecifierString"); //$NON-NLS-1$
@@ -2315,8 +2343,7 @@ public class IOStructGen {
      * @return True if the given node is an unary string.
      */
     private static boolean isUnaryString(CommonTree node) {
-        return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING) || (node
-                .getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES));
+        return ((node.getType() == CTFParser.UNARY_EXPRESSION_STRING) || (node.getType() == CTFParser.UNARY_EXPRESSION_STRING_QUOTES));
     }
 
     /**
@@ -2326,8 +2353,7 @@ public class IOStructGen {
      */
     private static boolean isUnaryInteger(CommonTree node) {
         return ((node.getType() == CTFParser.UNARY_EXPRESSION_DEC)
-                || (node.getType() == CTFParser.UNARY_EXPRESSION_HEX) || (node
-                    .getType() == CTFParser.UNARY_EXPRESSION_OCT));
+                || (node.getType() == CTFParser.UNARY_EXPRESSION_HEX) || (node.getType() == CTFParser.UNARY_EXPRESSION_OCT));
     }
 
     /**
-- 
1.7.9.5


Back to the top