From 53e5d2d3059fd04c45b09404c7e09f9cbee1358f Mon Sep 17 00:00:00 2001 From: Guilliano Molaire Date: Wed, 23 Apr 2014 13:15:23 -0400 Subject: [PATCH] TMF: Implementation of UstMemoryAnalysisModule requirements The events needed by the analysis are added as requirements. We also add the information that the libc with probes should be loaded prior to starting the trace session. Change-Id: Idcfb13d7ae43bb73f6631c12f4eeb52fe74976d5 Signed-off-by: Guilliano Molaire Reviewed-on: https://git.eclipse.org/r/23424 Tested-by: Hudson CI Reviewed-by: Alexandre Montplaisir Reviewed-by: Genevieve Bastien --- .../META-INF/MANIFEST.MF | 4 +- .../lttng2/ust/core/tests/AllTests.java | 1 + .../core/tests/analysis/memory/AllTests.java | 27 +++++ .../memory/UstMemoryAnalysisModuleTest.java | 101 ++++++++++++++++++ .../META-INF/MANIFEST.MF | 6 +- .../ust/core/analysis/memory/Messages.java | 38 +++++++ .../memory/UstMemoryAnalysisModule.java | 43 +++++++- .../core/analysis/memory/messages.properties | 2 + 8 files changed, 217 insertions(+), 5 deletions(-) create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/AllTests.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/UstMemoryAnalysisModuleTest.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/Messages.java create mode 100644 org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/messages.properties diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF index 599a4fae1f..c848fed088 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/META-INF/MANIFEST.MF @@ -14,6 +14,8 @@ Require-Bundle: org.junit;bundle-version="4.0.0", org.eclipse.linuxtools.tmf.core.tests;bundle-version="3.0.0", org.eclipse.linuxtools.tmf.ctf.core, org.eclipse.linuxtools.tmf.ctf.core.tests, - org.eclipse.linuxtools.lttng2.ust.core + org.eclipse.linuxtools.lttng2.ust.core, + org.eclipse.linuxtools.lttng2.control.core Export-Package: org.eclipse.linuxtools.lttng2.ust.core.tests, org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack +Import-Package: com.google.common.collect diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java index cd1cb1cae7..62e904d9f3 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/AllTests.java @@ -21,6 +21,7 @@ import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({ ActivatorTest.class, + org.eclipse.linuxtools.lttng2.ust.core.tests.analysis.memory.AllTests.class, org.eclipse.linuxtools.lttng2.ust.core.tests.trace.callstack.AllTests.class }) public class AllTests { } diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/AllTests.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/AllTests.java new file mode 100644 index 0000000000..98924bc4d6 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/AllTests.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2014 É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 + * + * Contributors: + * Guilliano Molaire - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.lttng2.ust.core.tests.analysis.memory; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * Test suite. + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + UstMemoryAnalysisModuleTest.class +}) +public class AllTests { + +} diff --git a/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/UstMemoryAnalysisModuleTest.java b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/UstMemoryAnalysisModuleTest.java new file mode 100644 index 0000000000..cbf456347a --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core.tests/src/org/eclipse/linuxtools/lttng2/ust/core/tests/analysis/memory/UstMemoryAnalysisModuleTest.java @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2014 É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 + * + * Contributors: + * Guilliano Molaire - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.lttng2.ust.core.tests.analysis.memory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Set; + +import org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage.UstMemoryStrings; +import org.eclipse.linuxtools.lttng2.control.core.session.SessionConfigStrings; +import org.eclipse.linuxtools.lttng2.ust.core.analysis.memory.UstMemoryAnalysisModule; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests for the {@link UstMemoryAnalysisModule} + * + * @author Guilliano Molaire + */ +public class UstMemoryAnalysisModuleTest { + + /** The analysis module */ + private UstMemoryAnalysisModule fUstAnalysisModule; + + /** + * Set-up the test + */ + @Before + public void setup() { + fUstAnalysisModule = new UstMemoryAnalysisModule(); + } + + /** + * Test for {@link UstMemoryAnalysisModule#getAnalysisRequirements()} + */ + @Test + public void testGetAnalysisRequirements() { + Iterable requirements = fUstAnalysisModule.getAnalysisRequirements(); + assertNotNull(requirements); + assertTrue(requirements.iterator().hasNext()); + + /* There should be the event and domain type */ + TmfAnalysisRequirement eventReq = null; + TmfAnalysisRequirement domainReq = null; + int numberOfRequirement = 0; + for (TmfAnalysisRequirement requirement : requirements) { + ++numberOfRequirement; + if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_EVENT)) { + eventReq = requirement; + } else if (requirement.getType().equals(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN)) { + domainReq = requirement; + } + } + assertNotNull(eventReq); + assertNotNull(domainReq); + + /* There should be two requirements */ + assertEquals(2, numberOfRequirement); + + /* Verify the content of the requirements themselves */ + /* Domain should be kernel */ + assertEquals(1, domainReq.getValues().size()); + for (String domain : domainReq.getValues()) { + assertEquals(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST, domain); + } + + /* Events */ + Set expectedEvents = ImmutableSet.of( + UstMemoryStrings.MALLOC, + UstMemoryStrings.FREE, + UstMemoryStrings.CALLOC, + UstMemoryStrings.REALLOC, + UstMemoryStrings.MEMALIGN, + UstMemoryStrings.POSIX_MEMALIGN + ); + + assertEquals(6, eventReq.getValues().size()); + for (String event : eventReq.getValues()) { + assertTrue("Unexpected event " + event, expectedEvents.contains(event)); + } + + Set infos = eventReq.getInformation(); + assertEquals(2, infos.size()); + } + +} diff --git a/org.eclipse.linuxtools.lttng2.ust.core/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.lttng2.ust.core/META-INF/MANIFEST.MF index a07c7671ba..1d29d34308 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.lttng2.ust.core/META-INF/MANIFEST.MF @@ -9,7 +9,7 @@ Bundle-Activator: org.eclipse.linuxtools.internal.lttng2.ust.core.Activator Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Export-Package: org.eclipse.linuxtools.internal.lttng2.ust.core;x-internal:=true, - org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage;x-friends:="org.eclipse.linuxtools.lttng2.ust.ui", + org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage;x-friends:="org.eclipse.linuxtools.lttng2.ust.ui,org.eclipse.linuxtools.lttng2.ust.core.tests", org.eclipse.linuxtools.internal.lttng2.ust.core.trace.callstack;x-friends:="org.eclipse.linuxtools.lttng2.ust.ui,org.eclipse.linuxtools.lttng2.ust.core.tests", org.eclipse.linuxtools.lttng2.ust.core.analysis.memory, org.eclipse.linuxtools.lttng2.ust.core.trace @@ -17,4 +17,6 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.core.resources, org.eclipse.linuxtools.ctf.core;bundle-version="3.0.0", org.eclipse.linuxtools.tmf.core;bundle-version="3.0.0", - org.eclipse.linuxtools.tmf.ctf.core + org.eclipse.linuxtools.tmf.ctf.core, + org.eclipse.linuxtools.lttng2.control.core +Import-Package: com.google.common.collect diff --git a/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/Messages.java b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/Messages.java new file mode 100644 index 0000000000..90f39b747b --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/Messages.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2014 É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 + * + * Contributors: + * Guilliano Molaire - Initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.lttng2.ust.core.analysis.memory; + +import org.eclipse.osgi.util.NLS; + +/** + * Message bundle for the ust memory analysis module + * + * @author Guilliano Molaire + * @since 3.0 + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.lttng2.ust.core.analysis.memory.messages"; //$NON-NLS-1$ + + /** Information regarding events loading prior to the analysis execution */ + public static String UstMemoryAnalysisModule_EventsLoadingInformation; + + /** Example of how to execute the application with the libc wrapper */ + public static String UstMemoryAnalysisModule_EventsLoadingExampleInformation; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } +} diff --git a/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java index 50856d0eb3..e4b3bd2167 100644 --- a/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java +++ b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/UstMemoryAnalysisModule.java @@ -8,17 +8,24 @@ * * Contributors: * Geneviève Bastien - Initial API and implementation + * Guilliano Molaire - Provide the requirements of the analysis *******************************************************************************/ package org.eclipse.linuxtools.lttng2.ust.core.analysis.memory; import org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage.MemoryUsageStateProvider; +import org.eclipse.linuxtools.internal.lttng2.ust.core.memoryusage.UstMemoryStrings; +import org.eclipse.linuxtools.lttng2.control.core.session.SessionConfigStrings; import org.eclipse.linuxtools.lttng2.ust.core.trace.LttngUstTrace; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAnalysisRequirement.ValuePriorityLevel; import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import com.google.common.collect.ImmutableSet; + /** * This analysis build a state system from the libc memory instrumentation on a * UST trace @@ -33,9 +40,37 @@ public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule { */ public static String ID = "org.eclipse.linuxtools.lttng2.ust.analysis.memory"; //$NON-NLS-1$ + private static final ImmutableSet REQUIRED_EVENTS = ImmutableSet.of( + UstMemoryStrings.MALLOC, + UstMemoryStrings.FREE, + UstMemoryStrings.CALLOC, + UstMemoryStrings.REALLOC, + UstMemoryStrings.MEMALIGN, + UstMemoryStrings.POSIX_MEMALIGN + ); + + /** The requirements as an immutable set */ + private static final ImmutableSet REQUIREMENTS; + + static { + /* Initialize the requirements for the analysis: domain and events */ + TmfAnalysisRequirement eventsReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_EVENT, REQUIRED_EVENTS, ValuePriorityLevel.MANDATORY); + /* + * In order to have these events, the libc wrapper with probes should be + * loaded + */ + eventsReq.addInformation(Messages.UstMemoryAnalysisModule_EventsLoadingInformation); + eventsReq.addInformation(Messages.UstMemoryAnalysisModule_EventsLoadingExampleInformation); + + /* The domain type of the analysis */ + TmfAnalysisRequirement domainReq = new TmfAnalysisRequirement(SessionConfigStrings.CONFIG_ELEMENT_DOMAIN); + domainReq.addValue(SessionConfigStrings.CONFIG_DOMAIN_TYPE_UST, ValuePriorityLevel.MANDATORY); + + REQUIREMENTS = ImmutableSet.of(domainReq, eventsReq); + } + @Override - protected - ITmfStateProvider createStateProvider() { + protected ITmfStateProvider createStateProvider() { return new MemoryUsageStateProvider(getTrace()); } @@ -52,4 +87,8 @@ public class UstMemoryAnalysisModule extends TmfStateSystemAnalysisModule { return (LttngUstTrace) super.getTrace(); } + @Override + public Iterable getAnalysisRequirements() { + return REQUIREMENTS; + } } diff --git a/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/messages.properties b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/messages.properties new file mode 100644 index 0000000000..fdc32e0300 --- /dev/null +++ b/org.eclipse.linuxtools.lttng2.ust.core/src/org/eclipse/linuxtools/lttng2/ust/core/analysis/memory/messages.properties @@ -0,0 +1,2 @@ +UstMemoryAnalysisModule_EventsLoadingInformation=The libc wrapper should be loaded in order to get the events in the trace output. +UstMemoryAnalysisModule_EventsLoadingExampleInformation=Start the application to trace with: LD_PRELOAD=/path/to/liblttng-ust-libc-wrapper.so ./myProgram. -- 2.34.1