lttng: Add a ILttngUstEventLayout
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Fri, 21 Aug 2015 01:17:01 +0000 (21:17 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 24 Sep 2015 19:16:01 +0000 (15:16 -0400)
The event names exposed by LTTng-UST for the memory analysis have
changed in LTTng 2.7. They are now prefixed by "lttng_ust_*",
instead of the previous "ust_*".

To support various versions in parallel, we can use a "event
layout" interface, similarly to what was done for kernel traces
with IKernelEventLayout.

This patch adds a new ILttngUstEventLayout interface, and
implementations for 2.6- and 2.7+ versions. The memory
analysis itself will be moved to use this layout in the
following patch.

Change-Id: Id1f4bde4f5fc56bb3f6d003e51716944ce2c3f93
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/50684
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.core/META-INF/MANIFEST.MF
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst27EventLayout.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/package-info.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/package-info.java [new file with mode: 0644]

index 74c78f67640f4ea51d90c8b530b40f3b7b088043..475b43e73f71d0e4fc97ec60468da86d3c3badcf 100644 (file)
@@ -11,8 +11,10 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Export-Package: org.eclipse.tracecompass.internal.lttng2.ust.core;x-friends:="org.eclipse.tracecompass.lttng2.ust.core.tests,org.eclipse.tracecompass.lttng2.ust.ui",
  org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory;x-friends:="org.eclipse.tracecompass.lttng2.ust.ui,org.eclipse.tracecompass.lttng2.ust.core.tests",
  org.eclipse.tracecompass.internal.lttng2.ust.core.callstack;x-friends:="org.eclipse.tracecompass.lttng2.ust.ui,org.eclipse.tracecompass.lttng2.ust.core.tests",
+ org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout;x-internal:=true,
  org.eclipse.tracecompass.lttng2.ust.core.analysis.memory,
- org.eclipse.tracecompass.lttng2.ust.core.trace
+ org.eclipse.tracecompass.lttng2.ust.core.trace,
+ org.eclipse.tracecompass.lttng2.ust.core.trace.layout
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.core.resources,
  org.eclipse.tracecompass.common.core,
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst20EventLayout.java
new file mode 100644 (file)
index 0000000..711dd3b
--- /dev/null
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout;
+
+import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
+
+/**
+ * Definitions used in LTTng-UST for versions 2.0 up to 2.6.
+ *
+ * @author Alexandre Montplaisir
+ */
+@SuppressWarnings("nls")
+public class LttngUst20EventLayout implements ILttngUstEventLayout {
+
+    /**
+     * Constructor
+     */
+    protected LttngUst20EventLayout() {}
+
+    private static final LttngUst20EventLayout INSTANCE = new LttngUst20EventLayout();
+
+    /**
+     * Get a singleton instance.
+     *
+     * @return The instance
+     */
+    public static LttngUst20EventLayout getInstance() {
+        return INSTANCE;
+    }
+
+    // ------------------------------------------------------------------------
+    // Event names used in liblttng-ust-libc-wrapper
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String eventLibcMalloc() {
+        return "ust_libc:malloc";
+    }
+
+    @Override
+    public String eventLibcCalloc() {
+        return "ust_libc:calloc";
+    }
+
+    @Override
+    public String eventLibcRealloc() {
+        return "ust_libc:realloc";
+    }
+
+    @Override
+    public String eventLibcFree() {
+        return "ust_libc:free";
+    }
+
+    @Override
+    public String eventLibcMemalign() {
+        return "ust_libc:memalign";
+    }
+
+    @Override
+    public String eventLibcPosixMemalign() {
+        return "ust_libc:posix_memalign";
+    }
+
+    // ------------------------------------------------------------------------
+    // Field names
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String fieldPtr() {
+        return "ptr";
+    }
+
+    @Override
+    public String fieldNmemb() {
+        return "nmemb";
+    }
+
+    @Override
+    public String fieldSize() {
+        return "size";
+    }
+
+    @Override
+    public String fieldOutPtr() {
+        return "out_ptr";
+    }
+
+    @Override
+    public String fieldInPtr() {
+        return "in_ptr";
+    }
+
+    // ------------------------------------------------------------------------
+    // Context field names
+    // Note: The CTF parser exposes contexts as fields called "context._<name>"
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String contextVtid() {
+        return "context._vtid";
+    }
+
+    @Override
+    public String contextProcname() {
+        return "context._procname";
+    }
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst27EventLayout.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/LttngUst27EventLayout.java
new file mode 100644 (file)
index 0000000..ad8c65b
--- /dev/null
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout;
+
+/**
+ * Updated event definitions for LTTng-UST 2.7.
+ *
+ * @author Alexandre Montplaisir
+ */
+@SuppressWarnings("nls")
+public class LttngUst27EventLayout extends LttngUst20EventLayout {
+
+    /**
+     * Constructor
+     */
+    protected LttngUst27EventLayout() {}
+
+    private static final LttngUst27EventLayout INSTANCE = new LttngUst27EventLayout();
+
+    /**
+     * Get a singleton instance.
+     *
+     * @return The instance
+     */
+    public static LttngUst27EventLayout getInstance() {
+        return INSTANCE;
+    }
+
+    // ------------------------------------------------------------------------
+    // Event names used in liblttng-ust-libc-wrapper
+    // They are now prefixed with "lttng_*"
+    // ------------------------------------------------------------------------
+
+    @Override
+    public String eventLibcMalloc() {
+        return "lttng_ust_libc:malloc";
+    }
+
+    @Override
+    public String eventLibcCalloc() {
+        return "lttng_ust_libc:calloc";
+    }
+
+    @Override
+    public String eventLibcRealloc() {
+        return "lttng_ust_libc:realloc";
+    }
+
+    @Override
+    public String eventLibcFree() {
+        return "lttng_ust_libc:free";
+    }
+
+    @Override
+    public String eventLibcMemalign() {
+        return "lttng_ust_libc:memalign";
+    }
+
+    @Override
+    public String eventLibcPosixMemalign() {
+        return "lttng_ust_libc:posix_memalign";
+    }
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/package-info.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/layout/package-info.java
new file mode 100644 (file)
index 0000000..d4202bd
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout;
index fd56bf0ea41d3a2b733059e2c576b86bb3e477fc..dd437a8eee36a02e617c38eb03056e9c4ac345ca 100644 (file)
@@ -17,9 +17,17 @@ package org.eclipse.tracecompass.lttng2.ust.core.trace;
 import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.Activator;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTraceValidationStatus;
@@ -33,6 +41,8 @@ public class LttngUstTrace extends CtfTmfTrace {
 
     private static final int CONFIDENCE = 100;
 
+    private @Nullable ILttngUstEventLayout fLayout = null;
+
     /**
      * Default constructor
      */
@@ -40,6 +50,48 @@ public class LttngUstTrace extends CtfTmfTrace {
         super();
     }
 
+    /**
+     * Get the event layout to use with this trace. This normally depends on the
+     * tracer's version.
+     *
+     * @return The event layout
+     * @since 2.0
+     */
+    public @NonNull ILttngUstEventLayout getEventLayout() {
+        ILttngUstEventLayout layout = fLayout;
+        if (layout == null) {
+            throw new IllegalStateException("Cannot get the layout of a non-initialized trace!"); //$NON-NLS-1$
+        }
+        return layout;
+    }
+
+    @Override
+    public void initTrace(IResource resource, String path,
+            Class<? extends ITmfEvent> eventType) throws TmfTraceException {
+        super.initTrace(resource, path, eventType);
+
+        /* Determine the event layout to use from the tracer's version */
+        fLayout = getLayoutFromEnv(this.getEnvironment());
+    }
+
+    private static @NonNull ILttngUstEventLayout getLayoutFromEnv(Map<String, String> traceEnv) {
+        String tracerName = traceEnv.get("tracer_name"); //$NON-NLS-1$
+        String tracerMajor = traceEnv.get("tracer_major"); //$NON-NLS-1$
+        String tracerMinor = traceEnv.get("tracer_minor"); //$NON-NLS-1$
+
+        if ("\"lttng-ust\"".equals(tracerName) && tracerMajor != null && tracerMinor != null) { //$NON-NLS-1$
+            if (Integer.valueOf(tracerMajor) >= 2) {
+                if (Integer.valueOf(tracerMinor) >= 7) {
+                    return LttngUst27EventLayout.getInstance();
+                }
+                return LttngUst20EventLayout.getInstance();
+            }
+        }
+
+        /* Fallback to the UST 2.0 layout and hope for the best */
+        return LttngUst20EventLayout.getInstance();
+    }
+
     /**
      * {@inheritDoc}
      * <p>
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/ILttngUstEventLayout.java
new file mode 100644 (file)
index 0000000..eabe2b6
--- /dev/null
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.trace.layout;
+
+/**
+ * This interface defines concepts exposed by liblttng-ust libraries and traces.
+ * Actual implementations can differ between different versions of the tracer.
+ *
+ * @author Alexandre Montplaisir
+ * @since 2.0
+ */
+@SuppressWarnings("javadoc")
+public interface ILttngUstEventLayout {
+
+    // ------------------------------------------------------------------------
+    // Event names used in liblttng-ust-libc-wrapper
+    // ------------------------------------------------------------------------
+
+    String eventLibcMalloc();
+    String eventLibcCalloc();
+    String eventLibcRealloc();
+    String eventLibcFree();
+    String eventLibcMemalign();
+    String eventLibcPosixMemalign();
+
+    // ------------------------------------------------------------------------
+    // Field names
+    // ------------------------------------------------------------------------
+
+    String fieldPtr();
+    String fieldNmemb();
+    String fieldSize();
+    String fieldOutPtr();
+    String fieldInPtr();
+
+    // ------------------------------------------------------------------------
+    // Context field names
+    // ------------------------------------------------------------------------
+
+    String contextVtid();
+    String contextProcname();
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/package-info.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/layout/package-info.java
new file mode 100644 (file)
index 0000000..1fc4abf
--- /dev/null
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EfficiOS Inc., Alexandre Montplaisir
+ *
+ * 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
+ *******************************************************************************/
+
+@org.eclipse.jdt.annotation.NonNullByDefault
+package org.eclipse.tracecompass.lttng2.ust.core.trace.layout;
This page took 0.029189 seconds and 5 git commands to generate.