From: Geneviève Bastien Date: Tue, 30 May 2017 18:22:42 +0000 (-0400) Subject: ust: Add a LinuxTidAspect using the context._vtid X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;ds=sidebyside;h=d6e6f5d524490824d3fae2530287d5c453d455ab;p=deliverable%2Ftracecompass.git ust: Add a LinuxTidAspect using the context._vtid 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 Reviewed-on: https://git.eclipse.org/r/98250 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam Tested-by: Matthew Khouzam --- diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/META-INF/MANIFEST.MF b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/META-INF/MANIFEST.MF index 55464261a9..b12a0d97d5 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/META-INF/MANIFEST.MF +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/META-INF/MANIFEST.MF @@ -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, diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/callstack/AbstractProviderTest.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/callstack/AbstractProviderTest.java index a50dcea7c8..281cd3bf83 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/callstack/AbstractProviderTest.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/callstack/AbstractProviderTest.java @@ -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 index 0000000000..72adc2b522 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core.tests/src/org/eclipse/tracecompass/lttng2/ust/core/tests/trace/LttngUstTraceTest.java @@ -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()); + } +} diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/META-INF/MANIFEST.MF b/lttng/org.eclipse.tracecompass.lttng2.ust.core/META-INF/MANIFEST.MF index f91d4984dc..cff820e0bb 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/META-INF/MANIFEST.MF +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/META-INF/MANIFEST.MF @@ -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, diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java index 47dc1dd294..bd366aba99 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/analysis/memory/UstMemoryStateProvider.java @@ -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) { diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java index ead41c602b..fe6c60c16d 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/callstack/LttngUstCallStackProvider.java @@ -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 index 0000000000..e9270e90e7 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/internal/lttng2/ust/core/trace/ContextVtidAspect.java @@ -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(); + } + +} diff --git a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java index 8160ba0638..42d63fcfd2 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java +++ b/lttng/org.eclipse.tracecompass.lttng2.ust.core/src/org/eclipse/tracecompass/lttng2/ust/core/trace/LttngUstTrace.java @@ -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> 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> 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> getEventAspects() { - return LTTNG_UST_ASPECTS; + return fUstTraceAspects; } /**