ust: Add a LinuxTidAspect using the context._vtid
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Tue, 30 May 2017 18:22:42 +0000 (14:22 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Wed, 31 May 2017 18:29:30 +0000 (14:29 -0400)
And have the callstack analysis use the aspect instead. This will allow
the callstack analysis to work when an aspect discovering the TID from a
kernel trace is added (in the incubator).

The callstack analysis requirement will need to be updated for it to
work without the context vtid field.

Change-Id: I8b31acfd0c6b03685403c57c650fdb3474e50c26
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/98250
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/META-INF/MANIFEST.MF
lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/callstack/AbstractProviderTest.java
lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/trace/LttngUstTraceTest.java [new file with mode: 0644]
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/analysis/memory/UstMemoryStateProvider.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/ContextVtidAspect.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java

index 55464261a9bcb3adc7d448865c7f47b9018ab6c0..b12a0d97d51ed74d6104f670131b5d72916ce0f3 100644 (file)
@@ -16,7 +16,8 @@ Require-Bundle: org.junit;bundle-version="4.0.0",
  org.eclipse.tracecompass.tmf.ctf.core,
  org.eclipse.tracecompass.tmf.ctf.core.tests,
  org.eclipse.tracecompass.lttng2.ust.core,
- org.eclipse.tracecompass.lttng2.control.core
+ org.eclipse.tracecompass.lttng2.control.core,
+ org.eclipse.tracecompass.analysis.os.linux.core
 Export-Package: org.eclipse.tracecompass.lttng2.ust.core.tests,
  org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.debuginfo,
  org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.memory,
index a50dcea7c8f5de55d113b818d3bb01f32fbc6045..281cd3bf837e8eb36a4e0944aa63011497563a78 100644 (file)
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackProvider;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
@@ -33,7 +34,9 @@ import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.core.callstack.CallStackStateProvider;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
 import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
@@ -102,12 +105,17 @@ public abstract class AbstractProviderTest {
 
     /**
      * Perform pre-class initialization.
+     *
+     * @throws TmfTraceException
+     *             Exception initiating the trace
      */
     @Before
-    public void setUp() {
+    public void setUp() throws TmfTraceException {
         CtfTestTrace testTrace = getTestTrace();
 
-        CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(testTrace);
+        CtfTmfTrace ctftrace = CtfTmfTestTraceUtils.getTrace(testTrace);
+        LttngUstTrace trace = new LttngUstTrace();
+        trace.initTrace(null, ctftrace.getPath(), ITmfEvent.class);
         fTrace = trace;
         fModule = new TestLttngCallStackModule();
         try {
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/trace/LttngUstTraceTest.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/trace/LttngUstTraceTest.java
new file mode 100644 (file)
index 0000000..72adc2b
--- /dev/null
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * 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.tests.trace;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.io.File;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.tracecompass.tmf.core.request.TmfEventRequest;
+import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
+import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test the {@link LttngUstTrace} class
+ *
+ * @author Geneviève Bastien
+ */
+public class LttngUstTraceTest {
+
+    private static final @NonNull CtfTestTrace TEST_TRACE = CtfTestTrace.CYG_PROFILE;
+
+    private ITmfTrace fTrace;
+
+    /**
+     * Perform pre-class initialization.
+     *
+     * @throws TmfTraceException
+     *             Exceptions in trace initialization
+     */
+    @Before
+    public void setUp() throws TmfTraceException {
+        CtfTmfTrace ctftrace = CtfTmfTestTraceUtils.getTrace(TEST_TRACE);
+
+        LttngUstTrace trace = new LttngUstTrace();
+        trace.initTrace(null, ctftrace.getPath(), ITmfEvent.class);
+        fTrace = trace;
+
+    }
+
+    /** Empty and delete a directory */
+    private static void deleteDirectory(File dir) {
+        /* Assuming the dir only contains file or empty directories */
+        for (File file : dir.listFiles()) {
+            file.delete();
+        }
+        dir.delete();
+    }
+
+    /**
+     * Perform post-class clean-up.
+     */
+    @After
+    public void tearDown() {
+        ITmfTrace trace = fTrace;
+        if (trace != null) {
+            trace.dispose();
+            File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(trace));
+            deleteDirectory(suppDir);
+        }
+    }
+
+    private static class TestEventRequest extends TmfEventRequest {
+
+        private String errString = null;
+
+        public TestEventRequest() {
+            super(ITmfEvent.class, TmfTimeRange.ETERNITY, 0, 2, ExecutionType.FOREGROUND);
+        }
+
+        @Override
+        public void handleData(@NonNull ITmfEvent event) {
+            super.handleData(event);
+            Integer tid = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event);
+            if (tid == null) {
+                errString = "No TID for event " + event;
+                cancel();
+                return;
+            }
+            if (tid.intValue() != 16073) {
+                errString = "Wrong tid: " + tid + " for event";
+                cancel();
+                return;
+            }
+        }
+
+        public String getErrString() {
+            return errString;
+        }
+
+    }
+
+    /**
+     * Test the LinuxTidAspect for this trace
+     *
+     * @throws InterruptedException
+     *             exception thrown in the request
+     */
+    @Test
+    public void testTidAspect() throws InterruptedException {
+        ITmfTrace trace = fTrace;
+        assertNotNull(trace);
+
+        TestEventRequest request = new TestEventRequest();
+        trace.sendRequest(request);
+        request.waitForCompletion();
+        assertNull(request.getErrString());
+    }
+}
index f91d4984dc727fbfe01eda4d929d26cb15f5ac80..cff820e0bb8b0b992c7959c79c6cd82b695b070b 100644 (file)
@@ -12,6 +12,7 @@ Export-Package: org.eclipse.tracecompass.internal.lttng2.ust.core;x-friends:="or
  org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo;x-friends:="org.eclipse.tracecompass.lttng2.ust.core.tests",
  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.lttng2.ust.ui.swtbot.tests",
+ org.eclipse.tracecompass.internal.lttng2.ust.core.trace;x-internal:=true,
  org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout;x-internal:=true,
  org.eclipse.tracecompass.lttng2.ust.core.analysis.debuginfo,
  org.eclipse.tracecompass.lttng2.ust.core.analysis.memory,
@@ -23,7 +24,8 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tracecompass.tmf.core,
  org.eclipse.tracecompass.tmf.ctf.core,
  org.eclipse.tracecompass.lttng2.control.core,
- org.eclipse.tracecompass.ctf.core
+ org.eclipse.tracecompass.ctf.core,
+ org.eclipse.tracecompass.analysis.os.linux.core
 Import-Package: com.google.common.annotations;version="15.0.0",
  com.google.common.cache,
  com.google.common.collect,
index 47dc1dd29479b176a4f5a0a4b628a85a5827f47e..bd366aba996a81715d8c809741b27e2b4464ecc1 100644 (file)
@@ -19,6 +19,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
@@ -30,6 +31,7 @@ import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
 import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 
 import com.google.common.collect.ImmutableMap;
 
@@ -178,12 +180,13 @@ public class UstMemoryStateProvider extends AbstractTmfStateProvider {
         return VERSION;
     }
 
-    private Long getVtid(ITmfEvent event) {
-        ITmfEventField field = event.getContent().getField(fLayout.contextVtid());
-        if (field == null) {
+    private static Long getVtid(ITmfEvent event) {
+        /* We checked earlier that the "vtid" context is present */
+        Integer tid = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event);
+        if (tid == null) {
             return MINUS_ONE;
         }
-        return (Long) field.getValue();
+        return tid.longValue();
     }
 
     private String getProcname(ITmfEvent event) {
index ead41c602bb0b6923176b6b8c5f02df757a562db..fe6c60c16d416d5866e133df0388b877d6dcb2e1 100644 (file)
@@ -19,6 +19,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
 import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
@@ -28,6 +29,7 @@ import org.eclipse.tracecompass.tmf.core.callstack.CallStackStateProvider;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
 
 import com.google.common.collect.ImmutableSet;
@@ -121,8 +123,8 @@ public class LttngUstCallStackProvider extends CallStackStateProvider {
         if (!(event instanceof CtfTmfEvent)) {
             return false;
         }
-        ITmfEventField content = ((CtfTmfEvent) event).getContent();
-        if (content.getField(fLayout.contextVtid()) == null) {
+        Object tid = TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event);
+        if (!(tid instanceof Integer)) {
             return false;
         }
         return true;
@@ -170,8 +172,11 @@ public class LttngUstCallStackProvider extends CallStackStateProvider {
     @Override
     protected long getThreadId(ITmfEvent event) {
         /* We checked earlier that the "vtid" context is present */
-        ITmfEventField content = event.getContent();
-        return ((Long) content.getField(fLayout.contextVtid()).getValue()).longValue();
+        Integer tid = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event);
+        if (tid == null) {
+            return UNKNOWN_PID;
+        }
+        return tid.longValue();
     }
 
     @Override
diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/ContextVtidAspect.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/ContextVtidAspect.java
new file mode 100644 (file)
index 0000000..e9270e9
--- /dev/null
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * 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;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.layout.ILttngUstEventLayout;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
+
+/**
+ * A Linux TID event aspect that retrieves the VTID from the context of a
+ * userspace event.
+ *
+ * @since 3.0
+ */
+public class ContextVtidAspect extends LinuxTidAspect {
+
+    private final ILttngUstEventLayout fLayout;
+
+    /**
+     * Constructor with a layout
+     *
+     * @param layout
+     *            The event layout used by the trace this aspect is for
+     */
+    public ContextVtidAspect(ILttngUstEventLayout layout) {
+        fLayout = layout;
+    }
+
+    @Override
+    public @Nullable Integer resolve(@NonNull ITmfEvent event) {
+        ITmfEventField content = event.getContent();
+        Long tid = content.getFieldValue(Long.class, fLayout.contextVtid());
+        return tid == null ? null : tid.intValue();
+    }
+
+}
index 8160ba0638bdc7d188f30a41a8fd797de93ce4ab..42d63fcfd2b0e57ce6fac1e91f0cdf215b890577 100644 (file)
@@ -15,6 +15,7 @@
 package org.eclipse.tracecompass.lttng2.ust.core.trace;
 
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
@@ -24,6 +25,7 @@ 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.ContextVtidAspect;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.DefaultUstEventLayout;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst20EventLayout;
 import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.layout.LttngUst27EventLayout;
@@ -72,6 +74,8 @@ public class LttngUstTrace extends CtfTmfTrace {
         LTTNG_UST_ASPECTS = builder.build();
     }
 
+    private @NonNull Collection<ITmfEventAspect<?>> fUstTraceAspects = new HashSet<>(LTTNG_UST_ASPECTS);
+
     private @Nullable ILttngUstEventLayout fLayout = null;
 
     /**
@@ -116,6 +120,11 @@ public class LttngUstTrace extends CtfTmfTrace {
 
         /* Determine the event layout to use from the tracer's version */
         fLayout = getLayoutFromEnv();
+
+        ImmutableSet.Builder<ITmfEventAspect<?>> builder = ImmutableSet.builder();
+        builder.addAll(LTTNG_UST_ASPECTS);
+        builder.add(new ContextVtidAspect(fLayout));
+        fUstTraceAspects = builder.build();
     }
 
     private @NonNull ILttngUstEventLayout getLayoutFromEnv() {
@@ -142,7 +151,7 @@ public class LttngUstTrace extends CtfTmfTrace {
 
     @Override
     public Iterable<ITmfEventAspect<?>> getEventAspects() {
-        return LTTNG_UST_ASPECTS;
+        return fUstTraceAspects;
     }
 
     /**
This page took 0.032622 seconds and 5 git commands to generate.