diff options
author | Guillaume Champagne | 2018-03-20 01:32:42 +0000 |
---|---|---|
committer | Genevieve Bastien | 2018-04-09 12:23:33 +0000 |
commit | 3f021f20ea5e00c0aa4fbda11e1e0fc5b2c6e85e (patch) | |
tree | f5ba43af55cf35578dcb0ad91bdd229c653ffcaf | |
parent | d50b7d4deb579b251a231777519faa64339d761c (diff) | |
download | org.eclipse.tracecompass.incubator-3f021f20ea5e00c0aa4fbda11e1e0fc5b2c6e85e.tar.gz org.eclipse.tracecompass.incubator-3f021f20ea5e00c0aa4fbda11e1e0fc5b2c6e85e.tar.xz org.eclipse.tracecompass.incubator-3f021f20ea5e00c0aa4fbda11e1e0fc5b2c6e85e.zip |
analysis: Add a ProccessName and ThreadName aspect for host
Thoses aspects will gather the name of a process or a thread for a
given host if one trace contains a LinuxTidAspect or LinuxPidAspect
instance.
Change-Id: I9c936f52370f1058cc5e5eac1c470ce46639d4db
Signed-off-by: Alexis-Maurer Fortin <alexis-maurer.fortin@polymtl.ca>
Signed-off-by: Guillaume Champagne <guillaume.champagne@polymtl.ca>
Signed-off-by: Hugo Genesse <hugo.genesse@polymtl.ca>
Signed-off-by: Pierre-Yves Lajoie<pierre-yves.lajoie@polymtl.ca>
Signed-off-by: Eva Terriault <eva.terriault@polymtl.ca>
Reviewed-on: https://git.eclipse.org/r/119704
Reviewed-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: Genevieve Bastien <gbastien+lttng@versatic.net>
Tested-by: CI Bot
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
6 files changed, 438 insertions, 0 deletions
diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisProcessNameAspectTest.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisProcessNameAspectTest.java new file mode 100644 index 000000000..204f44013 --- /dev/null +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisProcessNameAspectTest.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2018 É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.incubator.analysis.core.tests.aspects; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Collection; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxPidAspect; +import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; +import org.eclipse.tracecompass.incubator.analysis.core.aspects.AnalysisProcessNameAspect; +import org.eclipse.tracecompass.incubator.analysis.core.model.IHostModel; +import org.eclipse.tracecompass.incubator.analysis.core.model.ModelManager; +import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace; +import org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared.LttngKernelTestTraceUtils; +import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; +import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; +import org.eclipse.tracecompass.tmf.core.event.TmfEvent; +import org.eclipse.tracecompass.tmf.core.event.TmfEventType; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; +import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; +import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; +import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Test the model and process name Aspect with a KernelAnalysisModule from a kernel trace + * + * @author Guillaume Champagne + * @author Alexis-Maurer Fortin + * @author Hugo Genesse + * @author Pierre-Yves Lajoie + * @author Eva Terriault + */ +public class AnalysisProcessNameAspectTest { + + /* + * For this trace, process 4111 was on CPU between 1332170688674418133 and + * 1332170688674530927 and on CPU 1 was process 1344jjj + */ + private static final CtfTestTrace TRACE = CtfTestTrace.KERNEL; + private static final long startTs = 1332170682529781163L; + private static final int threadCpu1 = 1169; + private static final int parentProcessCpu1 = 1163; + private static final String execNameProcessCpu1 = "rsyslogd"; + + private @Nullable LttngKernelTrace fTrace; + + /** + * Set-up the test + */ + @Before + public void setUp() { + LttngKernelTrace trace = LttngKernelTestTraceUtils.getTrace(TRACE); + trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null)); + IAnalysisModule kernelModule = trace.getAnalysisModule(KernelAnalysisModule.ID); + assertNotNull(kernelModule); + kernelModule.schedule(); + assertTrue(kernelModule.waitForCompletion()); + fTrace = trace; + } + + /** + * Dispose test objects + */ + @After + public void tearDown() { + LttngKernelTestTraceUtils.dispose(CtfTestTrace.KERNEL); + fTrace = null; + } + + /** + * Test that the {@link KernelAnalysisModule} is added to the model of the + * trace + */ + @Test + public void testModelExecName() { + LttngKernelTrace trace = fTrace; + assertNotNull(trace); + + IHostModel model = ModelManager.getModelFor(trace.getHostId()); + int threadOnCpu = model.getThreadOnCpu(1, startTs + 1); + assertEquals(threadCpu1, threadOnCpu); + + int pid = model.getProcessId(threadOnCpu, startTs + 1); + assertEquals(parentProcessCpu1, pid); + String processExecName = model.getExecName(pid, startTs + 1); + assertEquals(execNameProcessCpu1, processExecName); + } + + /** + * Test that resolving the aspect for another trace with the same host ID + * gets the result from the Kernel analysis module + */ + @Test + public void testAspectFromOtherTrace() { + LttngKernelTrace trace = fTrace; + assertNotNull(trace); + + ITmfTrace otherTrace = new TmfTraceStub() { + + @Override + public @NonNull String getHostId() { + return trace.getHostId(); + } + + private final Collection<ITmfEventAspect<?>> fEventAspects = ImmutableList.of(new LinuxPidAspect() { + @Override + public @Nullable Integer resolve(ITmfEvent event) { + return parentProcessCpu1; + } + }); + + @Override + public Iterable<ITmfEventAspect<?>> getEventAspects() { + return fEventAspects; + } + + }; + + try { + ITmfEvent event = new TmfEvent(otherTrace, 1, TmfTimestamp.fromNanos(startTs), new TmfEventType(ITmfEventType.DEFAULT_TYPE_ID, null), null); + Object execName = TmfTraceUtils.resolveEventAspectOfClassForEvent(otherTrace, AnalysisProcessNameAspect.class, event); + assertTrue(execName instanceof String); + assertEquals(execNameProcessCpu1, execName); + } finally { + otherTrace.dispose(); + } + } + +} diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisThreadNameAspectTest.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisThreadNameAspectTest.java new file mode 100644 index 000000000..29c4133f3 --- /dev/null +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core.tests/src/org/eclipse/tracecompass/incubator/analysis/core/tests/aspects/AnalysisThreadNameAspectTest.java @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2018 É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.incubator.analysis.core.tests.aspects; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Collection; + +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.analysis.os.linux.core.kernel.KernelAnalysisModule; +import org.eclipse.tracecompass.incubator.analysis.core.aspects.AnalysisThreadNameAspect; +import org.eclipse.tracecompass.incubator.analysis.core.model.IHostModel; +import org.eclipse.tracecompass.incubator.analysis.core.model.ModelManager; +import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace; +import org.eclipse.tracecompass.lttng2.lttng.kernel.core.tests.shared.LttngKernelTestTraceUtils; +import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; +import org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.event.ITmfEventType; +import org.eclipse.tracecompass.tmf.core.event.TmfEvent; +import org.eclipse.tracecompass.tmf.core.event.TmfEventType; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; +import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal; +import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp; +import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; +import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +/** + * Test the model and thread name Aspect with a KernelAnalysisModule from a kernel trace + * + * @author Guillaume Champagne + * @author Alexis-Maurer Fortin + * @author Hugo Genesse + * @author Pierre-Yves Lajoie + * @author Eva Terriault + */ +public class AnalysisThreadNameAspectTest { + + /* + * For this trace, process 4111 was on CPU between 1332170688674418133 and + * 1332170688674530927 and on CPU 1 was process 1344 + */ + private static final CtfTestTrace TRACE = CtfTestTrace.KERNEL; + private static final long startTs = 1332170688674418133L; + private static final int processCpu0 = 4111; + private static final String execNameCpu0 = "threaded-ml"; + + private @Nullable LttngKernelTrace fTrace; + + /** + * Set-up the test + */ + @Before + public void setUp() { + LttngKernelTrace trace = LttngKernelTestTraceUtils.getTrace(TRACE); + trace.traceOpened(new TmfTraceOpenedSignal(this, trace, null)); + IAnalysisModule kernelModule = trace.getAnalysisModule(KernelAnalysisModule.ID); + assertNotNull(kernelModule); + kernelModule.schedule(); + assertTrue(kernelModule.waitForCompletion()); + fTrace = trace; + } + + /** + * Dispose test objects + */ + @After + public void tearDown() { + LttngKernelTestTraceUtils.dispose(CtfTestTrace.KERNEL); + fTrace = null; + } + + /** + * Test that the {@link KernelAnalysisModule} is added to the model of the + * trace + */ + @Test + public void testModelExecName() { + LttngKernelTrace trace = fTrace; + assertNotNull(trace); + + IHostModel model = ModelManager.getModelFor(trace.getHostId()); + int threadOnCpu = model.getThreadOnCpu(0, startTs + 1); + assertEquals(processCpu0, threadOnCpu); + String execName = model.getExecName(threadOnCpu, startTs + 1); + assertEquals(execNameCpu0, execName); + } + + /** + * Test that resolving the aspect for another trace with the same host ID + * gets the result from the Kernel analysis module + */ + @Test + public void testAspectFromOtherTrace() { + LttngKernelTrace trace = fTrace; + assertNotNull(trace); + + ITmfTrace otherTrace = new TmfTraceStub() { + + @Override + public @NonNull String getHostId() { + return trace.getHostId(); + } + + private final Collection<ITmfEventAspect<?>> fEventAspects = ImmutableList.of(new LinuxTidAspect() { + @Override + public @Nullable Integer resolve(ITmfEvent event) { + return processCpu0; + } + }); + + @Override + public Iterable<ITmfEventAspect<?>> getEventAspects() { + return fEventAspects; + } + + }; + + try { + ITmfEvent event = new TmfEvent(otherTrace, 1, TmfTimestamp.fromNanos(startTs), new TmfEventType(ITmfEventType.DEFAULT_TYPE_ID, null), null); + Object execName = TmfTraceUtils.resolveEventAspectOfClassForEvent(otherTrace, AnalysisThreadNameAspect.class, event); + assertTrue(execName instanceof String); + assertEquals(execNameCpu0, execName); + } finally { + otherTrace.dispose(); + } + } + +} diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisProcessNameAspect.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisProcessNameAspect.java new file mode 100644 index 000000000..e2307da0a --- /dev/null +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisProcessNameAspect.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2018 Ecole Polytechnique de Montreal + * + * 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.incubator.analysis.core.aspects; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxPidAspect; +import org.eclipse.tracecompass.incubator.analysis.core.aspects.ProcessNameAspect; +import org.eclipse.tracecompass.incubator.analysis.core.model.IHostModel; +import org.eclipse.tracecompass.incubator.analysis.core.model.ModelManager; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; + +/** + * Event aspect to resolve the process name of an event. It finds the model for + * the host the aspect is from and returns the process name at the time of the + * event. + * + * @author Guillaume Champagne + * @author Alexis-Maurer Fortin + * @author Hugo Genesse + * @author Pierre-Yves Lajoie + * @author Eva Terriault + */ +public final class AnalysisProcessNameAspect extends ProcessNameAspect { + + private static final AnalysisProcessNameAspect INSTANCE = new AnalysisProcessNameAspect(); + + private AnalysisProcessNameAspect() { + // Nothing to do + } + + /** + * Get the instance of this aspect + * + * @return The instance of this aspect + */ + public static AnalysisProcessNameAspect getInstance() { + return INSTANCE; + } + + @Override + public @Nullable String resolve(@NonNull ITmfEvent event) { + Object pidObj = TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), LinuxPidAspect.class, event); + if (pidObj == null) { + return null; + } + + String hostId = event.getTrace().getHostId(); + IHostModel model = ModelManager.getModelFor(hostId); + Integer pid = (Integer) pidObj; + ITmfTimestamp timestamp = event.getTimestamp(); + String pname = model.getExecName(pid, timestamp.getValue()); + return pname; + } +} diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisThreadNameAspect.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisThreadNameAspect.java new file mode 100644 index 000000000..22f3d3f8d --- /dev/null +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/analysis/core/aspects/AnalysisThreadNameAspect.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2018 Ecole Polytechnique de Montreal + * + * 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.incubator.analysis.core.aspects; + +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.incubator.analysis.core.aspects.ThreadNameAspect; +import org.eclipse.tracecompass.incubator.analysis.core.model.IHostModel; +import org.eclipse.tracecompass.incubator.analysis.core.model.ModelManager; +import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; +import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; + +/** + * Event aspect to resolve the process name of an event. It finds the model for + * the host the aspect is from and returns the process name at the time of the + * event. + * + * @author Guillaume Champagne + * @author Alexis-Maurer Fortin + * @author Hugo Genesse + * @author Pierre-Yves Lajoie + * @author Eva Terriault + */ +public final class AnalysisThreadNameAspect extends ThreadNameAspect { + + private static final AnalysisThreadNameAspect INSTANCE = new AnalysisThreadNameAspect(); + + private AnalysisThreadNameAspect() { + // Nothing to do + } + + /** + * Get the instance of this aspect + * + * @return The instance of this aspect + */ + public static AnalysisThreadNameAspect getInstance() { + return INSTANCE; + } + + @Override + public @Nullable String resolve(@NonNull ITmfEvent event) { + Object pidObj = TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), LinuxTidAspect.class, event); + if (pidObj == null) { + return null; + } + + String hostId = event.getTrace().getHostId(); + IHostModel model = ModelManager.getModelFor(hostId); + Integer tid = (Integer) pidObj; + ITmfTimestamp timestamp = event.getTimestamp(); + String tname = model.getExecName(tid, timestamp.getValue()); + return tname; + } +} diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/Activator.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/Activator.java index 079b1db10..d4077ef8b 100644 --- a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/Activator.java +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/Activator.java @@ -10,6 +10,8 @@ package org.eclipse.tracecompass.incubator.internal.analysis.core; import org.eclipse.tracecompass.common.core.TraceCompassActivator; +import org.eclipse.tracecompass.incubator.analysis.core.aspects.AnalysisProcessNameAspect; +import org.eclipse.tracecompass.incubator.analysis.core.aspects.AnalysisThreadNameAspect; import org.eclipse.tracecompass.incubator.analysis.core.aspects.AnalysisTidAspect; import org.eclipse.tracecompass.incubator.analysis.core.model.ModelManager; import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils; @@ -41,6 +43,8 @@ public class Activator extends TraceCompassActivator { @Override protected void startActions() { TmfTraceUtils.registerEventAspect(AnalysisTidAspect.getInstance()); + TmfTraceUtils.registerEventAspect(AnalysisProcessNameAspect.getInstance()); + TmfTraceUtils.registerEventAspect(AnalysisThreadNameAspect.getInstance()); } @Override diff --git a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/model/ModelListener.java b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/model/ModelListener.java index c5ce8906a..3eb45653e 100644 --- a/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/model/ModelListener.java +++ b/callstack/org.eclipse.tracecompass.incubator.analysis.core/src/org/eclipse/tracecompass/incubator/internal/analysis/core/model/ModelListener.java @@ -19,6 +19,7 @@ import java.util.WeakHashMap; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule; import org.eclipse.tracecompass.analysis.os.linux.core.tid.TidAnalysisModule; import org.eclipse.tracecompass.incubator.analysis.core.concepts.ICpuTimeProvider; import org.eclipse.tracecompass.incubator.analysis.core.concepts.ISamplingDataProvider; @@ -100,6 +101,15 @@ public class ModelListener implements ITmfNewAnalysisModuleListener { } } } + + if (module instanceof KernelAnalysisModule) { + KernelAnalysisModule provider = (KernelAnalysisModule) module; + ITmfTrace trace = provider.getTrace(); + if (trace != null) { + IHostModel model = ModelManager.getModelFor(trace.getHostId()); + ((CompositeHostModel) model).setKernelModule(trace, provider); + } + } } private static class TidAnalysisWrapper implements IThreadOnCpuProvider, ICpuTimeProvider { |