org.eclipse.tracecompass.lttng2.ust.core,
org.eclipse.tracecompass.lttng2.control.core
Export-Package: org.eclipse.tracecompass.lttng2.ust.core.tests,
- org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack
+ org.eclipse.tracecompass.lttng2.ust.core.tests.callstack
Import-Package: com.google.common.collect
@DebugSuite.SuiteClasses({
ActivatorTest.class,
org.eclipse.tracecompass.lttng2.ust.core.tests.analysis.memory.AllTests.class,
- org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack.AllTests.class
+ org.eclipse.tracecompass.lttng2.ust.core.tests.callstack.AllTests.class
})
public class AllTests {
import java.util.Set;
-import org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage.UstMemoryStrings;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStrings;
import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings;
import org.eclipse.tracecompass.lttng2.ust.core.analysis.memory.UstMemoryAnalysisModule;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014, 2015 Ericsson
+ *
+ * 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:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.callstack;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.util.List;
+
+import org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackProvider;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
+import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
+import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
+import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
+import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
+import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.Timeout;
+
+/**
+ * Base class for the UST callstack state provider tests.
+ *
+ * @author Alexandre Montplaisir
+ */
+public abstract class AbstractProviderTest {
+
+ /** Time-out tests after 20 seconds */
+ @Rule public TestRule globalTimeout= new Timeout(20000);
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+
+ private static final CtfTmfTestTrace otherUstTrace = CtfTmfTestTrace.HELLO_LOST;
+
+ private CtfTmfTrace fTrace = null;
+ private ITmfStateSystem fSS = null;
+ private TestLttngCallStackModule fModule;
+
+
+ // ------------------------------------------------------------------------
+ // Abstract methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * @return The test trace to use for this test
+ */
+ protected abstract CtfTmfTestTrace getTestTrace();
+
+ /**
+ * @return The name of the executable process in that particular trace
+ */
+ protected abstract String getProcName();
+
+ /**
+ * Get the list of timestamps to query in that trace.
+ *
+ * @param index
+ * Which of the test timestamps?
+ * @return That particular timestamp
+ */
+ protected abstract long getTestTimestamp(int index);
+
+ // ------------------------------------------------------------------------
+ // Maintenance
+ // ------------------------------------------------------------------------
+
+ /**
+ * Perform pre-class initialization.
+ */
+ @Before
+ public void setUp() {
+ CtfTmfTestTrace testTrace = getTestTrace();
+
+ CtfTmfTrace trace = testTrace.getTrace();
+ fTrace = trace;
+ fModule = new TestLttngCallStackModule();
+ try {
+ assertTrue(fModule.setTrace(trace));
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+ fModule.schedule();
+ assertTrue(fModule.waitForCompletion());
+
+ fSS = fModule.getStateSystem();
+ assertNotNull(fSS);
+ }
+
+ /**
+ * Perform post-class clean-up.
+ */
+ @After
+ public void tearDown() {
+ fModule.dispose();
+ if (fTrace != null) {
+ fTrace.dispose();
+ File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fTrace));
+ deleteDirectory(suppDir);
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // Test methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * Test the handling of generic UST traces who do not contain the required
+ * information.
+ */
+ @Test
+ public void testOtherUstTrace() {
+ /* Initialize the trace and analysis module */
+ File suppDir;
+ try (CtfTmfTrace ustTrace = otherUstTrace.getTrace();) {
+ TestLttngCallStackModule module = null;
+ try {
+ module = new TestLttngCallStackModule();
+ try {
+ assertTrue(module.setTrace(ustTrace));
+ } catch (TmfAnalysisException e) {
+ fail();
+ }
+ module.schedule();
+ assertTrue(module.waitForCompletion());
+
+ /* Make sure the generated state system exists, but is empty */
+ ITmfStateSystem ss = module.getStateSystem();
+ assertNotNull(ss);
+ assertTrue(ss.getStartTime() >= ustTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
+ assertEquals(0, ss.getNbAttributes());
+ } finally {
+ if (module != null) {
+ module.dispose();
+ }
+ }
+ suppDir = new File(TmfTraceManager.getSupplementaryFileDir(ustTrace));
+ }
+ deleteDirectory(suppDir);
+ assertFalse(suppDir.exists());
+ }
+
+ /**
+ * Test that the callstack state system is there and contains data.
+ */
+ @Test
+ public void testConstruction() {
+ assertNotNull(fSS);
+ assertTrue(fSS.getNbAttributes() > 0);
+ }
+
+ /**
+ * Test the callstack at the beginning of the state system.
+ */
+ @Test
+ public void testCallStackBegin() {
+ long start = fSS.getStartTime();
+ String[] cs = getCallStack(fSS, getProcName(), start);
+ assertEquals(1, cs.length);
+
+ assertEquals("40472b", cs[0]);
+ }
+
+ /**
+ * Test the callstack somewhere in the trace.
+ */
+ @Test
+ public void testCallStack1() {
+ String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(0));
+ assertEquals(2, cs.length);
+
+ assertEquals("40472b", cs[0]);
+ assertEquals("403d60", cs[1]);
+ }
+
+ /**
+ * Test the callstack somewhere in the trace.
+ */
+ @Test
+ public void testCallStack2() {
+ String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(1));
+ assertEquals(3, cs.length);
+
+ assertEquals("40472b", cs[0]);
+ assertEquals("403b14", cs[1]);
+ assertEquals("401b23", cs[2]);
+ }
+
+ /**
+ * Test the callstack somewhere in the trace.
+ */
+ @Test
+ public void testCallStack3() {
+ String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(2));
+ assertEquals(4, cs.length);
+
+ assertEquals("40472b", cs[0]);
+ assertEquals("4045c8", cs[1]);
+ assertEquals("403760", cs[2]);
+ assertEquals("401aac", cs[3]);
+ }
+
+ /**
+ * Test the callstack at the end of the trace/state system.
+ */
+ @Test
+ public void testCallStackEnd() {
+ long end = fSS.getCurrentEndTime();
+ String[] cs = getCallStack(fSS, getProcName(), end);
+ assertEquals(3, cs.length);
+
+ assertEquals("40472b", cs[0]);
+ assertEquals("4045c8", cs[1]);
+ assertEquals("403760", cs[2]);
+ }
+
+ // ------------------------------------------------------------------------
+ // Utility methods
+ // ------------------------------------------------------------------------
+
+ /** 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();
+ }
+
+ /** Get the callstack for the given timestamp, for this particular trace */
+ private static String[] getCallStack(ITmfStateSystem ss, String processName, long timestamp) {
+ try {
+ int stackAttribute = ss.getQuarkAbsolute("Threads", processName, "CallStack");
+ List<ITmfStateInterval> state = ss.queryFullState(timestamp);
+ int depth = state.get(stackAttribute).getStateValue().unboxInt();
+
+ int stackTop = ss.getQuarkRelative(stackAttribute, String.valueOf(depth));
+ ITmfStateValue expectedValue = state.get(stackTop).getStateValue();
+ ITmfStateInterval interval = StateSystemUtils.querySingleStackTop(ss, timestamp, stackAttribute);
+ assertNotNull(interval);
+ assertEquals(expectedValue, interval.getStateValue());
+
+ String[] ret = new String[depth];
+ for (int i = 0; i < depth; i++) {
+ int quark = ss.getQuarkRelative(stackAttribute, String.valueOf(i + 1));
+ ret[i] = state.get(quark).getStateValue().unboxStr();
+ }
+ return ret;
+
+ } catch (AttributeNotFoundException e) {
+ fail(e.getMessage());
+ } catch (StateSystemDisposedException e) {
+ fail(e.getMessage());
+ }
+ fail();
+ return null;
+ }
+
+ private class TestLttngCallStackModule extends TmfStateSystemAnalysisModule {
+
+ @Override
+ protected ITmfStateProvider createStateProvider() {
+ return new LttngUstCallStackProvider(checkNotNull(getTrace()));
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Ericsson
+ *
+ * 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:
+ * Alexandre Montplaisir - Initial implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.callstack;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * Test suite for org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+ LttngUstCallStackProviderFastTest.class,
+ LttngUstCallStackProviderTest.class
+})
+public class AllTests {
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 Ericsson
+ *
+ * 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:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.callstack;
+
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.BeforeClass;
+
+/**
+ * Test suite for the UST callstack state provider, using the trace of a program
+ * instrumented with lttng-ust-cyg-profile-fast.so tracepoints. These do not
+ * contain the function addresses in the func_exit events.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstCallStackProviderFastTest extends AbstractProviderTest {
+
+ private static final long[] timestamps = { 1379361250310000000L,
+ 1379361250498400000L,
+ 1379361250499759000L };
+
+ /**
+ * Class setup
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(CtfTmfTestTrace.CYG_PROFILE_FAST.exists());
+ }
+
+ @Override
+ protected CtfTmfTestTrace getTestTrace() {
+ return CtfTmfTestTrace.CYG_PROFILE_FAST;
+ }
+
+ @Override
+ protected String getProcName() {
+ return "glxgears-29822";
+ }
+
+ @Override
+ protected long getTestTimestamp(int index) {
+ return timestamps[index];
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2014 Ericsson
+ *
+ * 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:
+ * Alexandre Montplaisir - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.lttng2.ust.core.tests.callstack;
+
+import static org.junit.Assume.assumeTrue;
+
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.junit.BeforeClass;
+
+/**
+ * Test suite for the UST callstack state provider, using the trace of a program
+ * instrumented with lttng-ust-cyg-profile.so tracepoints.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstCallStackProviderTest extends AbstractProviderTest {
+
+ private static final long[] timestamps = { 1378850463600000000L,
+ 1378850463770000000L,
+ 1378850463868753000L };
+
+ /**
+ * Class setup
+ */
+ @BeforeClass
+ public static void setUpClass() {
+ assumeTrue(CtfTmfTestTrace.CYG_PROFILE.exists());
+ }
+
+ @Override
+ protected CtfTmfTestTrace getTestTrace() {
+ return CtfTmfTestTrace.CYG_PROFILE;
+ }
+
+ @Override
+ protected String getProcName() {
+ return "glxgears-16073";
+ }
+
+ @Override
+ protected long getTestTimestamp(int index) {
+ return timestamps[index];
+ }
+
+}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2014, 2015 Ericsson
- *
- * 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:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.util.List;
-
-import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.callstack.LttngUstCallStackProvider;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
-import org.eclipse.tracecompass.statesystem.core.StateSystemUtils;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
-import org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
-import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;
-import org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
-import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TestRule;
-import org.junit.rules.Timeout;
-
-/**
- * Base class for the UST callstack state provider tests.
- *
- * @author Alexandre Montplaisir
- */
-public abstract class AbstractProviderTest {
-
- /** Time-out tests after 20 seconds */
- @Rule public TestRule globalTimeout= new Timeout(20000);
-
- // ------------------------------------------------------------------------
- // Attributes
- // ------------------------------------------------------------------------
-
- private static final CtfTmfTestTrace otherUstTrace = CtfTmfTestTrace.HELLO_LOST;
-
- private CtfTmfTrace fTrace = null;
- private ITmfStateSystem fSS = null;
- private TestLttngCallStackModule fModule;
-
-
- // ------------------------------------------------------------------------
- // Abstract methods
- // ------------------------------------------------------------------------
-
- /**
- * @return The test trace to use for this test
- */
- protected abstract CtfTmfTestTrace getTestTrace();
-
- /**
- * @return The name of the executable process in that particular trace
- */
- protected abstract String getProcName();
-
- /**
- * Get the list of timestamps to query in that trace.
- *
- * @param index
- * Which of the test timestamps?
- * @return That particular timestamp
- */
- protected abstract long getTestTimestamp(int index);
-
- // ------------------------------------------------------------------------
- // Maintenance
- // ------------------------------------------------------------------------
-
- /**
- * Perform pre-class initialization.
- */
- @Before
- public void setUp() {
- CtfTmfTestTrace testTrace = getTestTrace();
-
- CtfTmfTrace trace = testTrace.getTrace();
- fTrace = trace;
- fModule = new TestLttngCallStackModule();
- try {
- assertTrue(fModule.setTrace(trace));
- } catch (TmfAnalysisException e) {
- fail();
- }
- fModule.schedule();
- assertTrue(fModule.waitForCompletion());
-
- fSS = fModule.getStateSystem();
- assertNotNull(fSS);
- }
-
- /**
- * Perform post-class clean-up.
- */
- @After
- public void tearDown() {
- fModule.dispose();
- if (fTrace != null) {
- fTrace.dispose();
- File suppDir = new File(TmfTraceManager.getSupplementaryFileDir(fTrace));
- deleteDirectory(suppDir);
- }
- }
-
- // ------------------------------------------------------------------------
- // Test methods
- // ------------------------------------------------------------------------
-
- /**
- * Test the handling of generic UST traces who do not contain the required
- * information.
- */
- @Test
- public void testOtherUstTrace() {
- /* Initialize the trace and analysis module */
- File suppDir;
- try (CtfTmfTrace ustTrace = otherUstTrace.getTrace();) {
- TestLttngCallStackModule module = null;
- try {
- module = new TestLttngCallStackModule();
- try {
- assertTrue(module.setTrace(ustTrace));
- } catch (TmfAnalysisException e) {
- fail();
- }
- module.schedule();
- assertTrue(module.waitForCompletion());
-
- /* Make sure the generated state system exists, but is empty */
- ITmfStateSystem ss = module.getStateSystem();
- assertNotNull(ss);
- assertTrue(ss.getStartTime() >= ustTrace.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
- assertEquals(0, ss.getNbAttributes());
- } finally {
- if (module != null) {
- module.dispose();
- }
- }
- suppDir = new File(TmfTraceManager.getSupplementaryFileDir(ustTrace));
- }
- deleteDirectory(suppDir);
- assertFalse(suppDir.exists());
- }
-
- /**
- * Test that the callstack state system is there and contains data.
- */
- @Test
- public void testConstruction() {
- assertNotNull(fSS);
- assertTrue(fSS.getNbAttributes() > 0);
- }
-
- /**
- * Test the callstack at the beginning of the state system.
- */
- @Test
- public void testCallStackBegin() {
- long start = fSS.getStartTime();
- String[] cs = getCallStack(fSS, getProcName(), start);
- assertEquals(1, cs.length);
-
- assertEquals("40472b", cs[0]);
- }
-
- /**
- * Test the callstack somewhere in the trace.
- */
- @Test
- public void testCallStack1() {
- String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(0));
- assertEquals(2, cs.length);
-
- assertEquals("40472b", cs[0]);
- assertEquals("403d60", cs[1]);
- }
-
- /**
- * Test the callstack somewhere in the trace.
- */
- @Test
- public void testCallStack2() {
- String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(1));
- assertEquals(3, cs.length);
-
- assertEquals("40472b", cs[0]);
- assertEquals("403b14", cs[1]);
- assertEquals("401b23", cs[2]);
- }
-
- /**
- * Test the callstack somewhere in the trace.
- */
- @Test
- public void testCallStack3() {
- String[] cs = getCallStack(fSS, getProcName(), getTestTimestamp(2));
- assertEquals(4, cs.length);
-
- assertEquals("40472b", cs[0]);
- assertEquals("4045c8", cs[1]);
- assertEquals("403760", cs[2]);
- assertEquals("401aac", cs[3]);
- }
-
- /**
- * Test the callstack at the end of the trace/state system.
- */
- @Test
- public void testCallStackEnd() {
- long end = fSS.getCurrentEndTime();
- String[] cs = getCallStack(fSS, getProcName(), end);
- assertEquals(3, cs.length);
-
- assertEquals("40472b", cs[0]);
- assertEquals("4045c8", cs[1]);
- assertEquals("403760", cs[2]);
- }
-
- // ------------------------------------------------------------------------
- // Utility methods
- // ------------------------------------------------------------------------
-
- /** 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();
- }
-
- /** Get the callstack for the given timestamp, for this particular trace */
- private static String[] getCallStack(ITmfStateSystem ss, String processName, long timestamp) {
- try {
- int stackAttribute = ss.getQuarkAbsolute("Threads", processName, "CallStack");
- List<ITmfStateInterval> state = ss.queryFullState(timestamp);
- int depth = state.get(stackAttribute).getStateValue().unboxInt();
-
- int stackTop = ss.getQuarkRelative(stackAttribute, String.valueOf(depth));
- ITmfStateValue expectedValue = state.get(stackTop).getStateValue();
- ITmfStateInterval interval = StateSystemUtils.querySingleStackTop(ss, timestamp, stackAttribute);
- assertNotNull(interval);
- assertEquals(expectedValue, interval.getStateValue());
-
- String[] ret = new String[depth];
- for (int i = 0; i < depth; i++) {
- int quark = ss.getQuarkRelative(stackAttribute, String.valueOf(i + 1));
- ret[i] = state.get(quark).getStateValue().unboxStr();
- }
- return ret;
-
- } catch (AttributeNotFoundException e) {
- fail(e.getMessage());
- } catch (StateSystemDisposedException e) {
- fail(e.getMessage());
- }
- fail();
- return null;
- }
-
- private class TestLttngCallStackModule extends TmfStateSystemAnalysisModule {
-
- @Override
- protected ITmfStateProvider createStateProvider() {
- return new LttngUstCallStackProvider(checkNotNull(getTrace()));
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2015 Ericsson
- *
- * 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:
- * Alexandre Montplaisir - Initial implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-
-/**
- * Test suite for org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack
- */
-@RunWith(Suite.class)
-@Suite.SuiteClasses({
- LttngUstCallStackProviderFastTest.class,
- LttngUstCallStackProviderTest.class
-})
-public class AllTests {
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- *
- * 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:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack;
-
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.BeforeClass;
-
-/**
- * Test suite for the UST callstack state provider, using the trace of a program
- * instrumented with lttng-ust-cyg-profile-fast.so tracepoints. These do not
- * contain the function addresses in the func_exit events.
- *
- * @author Alexandre Montplaisir
- */
-public class LttngUstCallStackProviderFastTest extends AbstractProviderTest {
-
- private static final long[] timestamps = { 1379361250310000000L,
- 1379361250498400000L,
- 1379361250499759000L };
-
- /**
- * Class setup
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(CtfTmfTestTrace.CYG_PROFILE_FAST.exists());
- }
-
- @Override
- protected CtfTmfTestTrace getTestTrace() {
- return CtfTmfTestTrace.CYG_PROFILE_FAST;
- }
-
- @Override
- protected String getProcName() {
- return "glxgears-29822";
- }
-
- @Override
- protected long getTestTimestamp(int index) {
- return timestamps[index];
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2014 Ericsson
- *
- * 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:
- * Alexandre Montplaisir - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.lttng2.ust.core.tests.trace.callstack;
-
-import static org.junit.Assume.assumeTrue;
-
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
-import org.junit.BeforeClass;
-
-/**
- * Test suite for the UST callstack state provider, using the trace of a program
- * instrumented with lttng-ust-cyg-profile.so tracepoints.
- *
- * @author Alexandre Montplaisir
- */
-public class LttngUstCallStackProviderTest extends AbstractProviderTest {
-
- private static final long[] timestamps = { 1378850463600000000L,
- 1378850463770000000L,
- 1378850463868753000L };
-
- /**
- * Class setup
- */
- @BeforeClass
- public static void setUpClass() {
- assumeTrue(CtfTmfTestTrace.CYG_PROFILE.exists());
- }
-
- @Override
- protected CtfTmfTestTrace getTestTrace() {
- return CtfTmfTestTrace.CYG_PROFILE;
- }
-
- @Override
- protected String getProcName() {
- return "glxgears-16073";
- }
-
- @Override
- protected long getTestTimestamp(int index) {
- return timestamps[index];
- }
-
-}
Bundle-ActivationPolicy: lazy
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.memoryusage;x-friends:="org.eclipse.tracecompass.lttng2.ust.ui,org.eclipse.tracecompass.lttng2.ust.core.tests",
- org.eclipse.tracecompass.internal.lttng2.ust.core.trace.callstack;x-friends:="org.eclipse.tracecompass.lttng2.ust.ui,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.core.analysis.memory,
org.eclipse.tracecompass.lttng2.ust.core.trace
Require-Bundle: org.eclipse.core.runtime,
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2014, 2015 Ericsson, É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:
+ * Matthew Khouzam - Initial API and implementation
+ * Geneviève Bastien - Memory is per thread and only total is kept
+ **********************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory;
+
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
+import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
+import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
+import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
+import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
+import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
+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;
+
+/**
+ * State provider to track the memory of the threads using the UST libc wrapper
+ * memory events.
+ *
+ * @author Matthew Khouzam
+ * @author Geneviève Bastien
+ */
+public class UstMemoryStateProvider extends AbstractTmfStateProvider {
+
+ /* Version of this state provider */
+ private static final int VERSION = 1;
+
+ /* Maps a pointer to a memory zone to the size of the memory */
+ private final Map<Long, Long> fMemory = new HashMap<>();
+
+ private static final Long MINUS_ONE = Long.valueOf(-1);
+ private static final Long ZERO = Long.valueOf(0);
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ /**
+ * Constructor
+ *
+ * @param trace
+ * trace
+ */
+ public UstMemoryStateProvider(@NonNull LttngUstTrace trace) {
+ super(trace, "Ust:Memory"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void eventHandle(ITmfEvent event) {
+ String name = event.getName();
+ switch (name) {
+ case UstMemoryStrings.MALLOC: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
+ setMem(event, ptr, size);
+ }
+ break;
+ case UstMemoryStrings.FREE: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ setMem(event, ptr, ZERO);
+ }
+ break;
+ case UstMemoryStrings.CALLOC: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ Long nmemb = (Long) event.getContent().getField(UstMemoryStrings.FIELD_NMEMB).getValue();
+ Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
+ setMem(event, ptr, size * nmemb);
+ }
+ break;
+ case UstMemoryStrings.REALLOC: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ Long newPtr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_INPTR).getValue();
+ Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
+ setMem(event, ptr, ZERO);
+ setMem(event, newPtr, size);
+ }
+ break;
+ case UstMemoryStrings.MEMALIGN: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
+ setMem(event, ptr, size);
+ }
+ break;
+ case UstMemoryStrings.POSIX_MEMALIGN: {
+ Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_OUTPTR).getValue();
+ if (ZERO.equals(ptr)) {
+ return;
+ }
+ Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
+ setMem(event, ptr, size);
+ }
+ break;
+ default:
+ break;
+ }
+
+ }
+
+ @Override
+ public ITmfStateProvider getNewInstance() {
+ return new UstMemoryStateProvider(getTrace());
+ }
+
+ @Override
+ public LttngUstTrace getTrace() {
+ return (LttngUstTrace) super.getTrace();
+ }
+
+ @Override
+ public int getVersion() {
+ return VERSION;
+ }
+
+ private static Long getVtid(ITmfEvent event) {
+ ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_VTID);
+ if (field == null) {
+ return MINUS_ONE;
+ }
+ return (Long) field.getValue();
+ }
+
+ private static String getProcname(ITmfEvent event) {
+ ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_PROCNAME);
+ if (field == null) {
+ return EMPTY_STRING;
+ }
+ return (String) field.getValue();
+ }
+
+ private void setMem(ITmfEvent event, Long ptr, Long size) {
+ ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
+ long ts = event.getTimestamp().getValue();
+ Long tid = getVtid(event);
+
+ Long memoryDiff = size;
+ /* Size is 0, it means it was deleted */
+ if (ZERO.equals(size)) {
+ Long memSize = fMemory.remove(ptr);
+ if (memSize == null) {
+ return;
+ }
+ memoryDiff = -memSize;
+ } else {
+ fMemory.put(ptr, size);
+ }
+ try {
+ int tidQuark = ss.getQuarkAbsoluteAndAdd(tid.toString());
+ int tidMemQuark = ss.getQuarkRelativeAndAdd(tidQuark, UstMemoryStrings.UST_MEMORY_MEMORY_ATTRIBUTE);
+
+ ITmfStateValue prevMem = ss.queryOngoingState(tidMemQuark);
+ /* First time we set this value */
+ if (prevMem.isNull()) {
+ int procNameQuark = ss.getQuarkRelativeAndAdd(tidQuark, UstMemoryStrings.UST_MEMORY_PROCNAME_ATTRIBUTE);
+ String procName = getProcname(event);
+ /*
+ * No tid/procname for the event for the event, added to a
+ * 'others' thread
+ */
+ if (tid.equals(MINUS_ONE)) {
+ procName = UstMemoryStrings.OTHERS;
+ }
+ ss.modifyAttribute(ts, TmfStateValue.newValueString(procName), procNameQuark);
+ prevMem = TmfStateValue.newValueLong(0);
+ }
+
+ long prevMemValue = prevMem.unboxLong();
+ prevMemValue += memoryDiff.longValue();
+ ss.modifyAttribute(ts, TmfStateValue.newValueLong(prevMemValue), tidMemQuark);
+ } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson, É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:
+ * Matthew Khouzam, Geneviève Bastien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory;
+
+/**
+ * Strings for the memory usage state system using the LTTng UST libc
+ * instrumentation
+ *
+ * @author Matthew Khouzam
+ * @author Geneviève Bastien
+ */
+@SuppressWarnings({ "nls", "javadoc" })
+public interface UstMemoryStrings {
+
+ /** Memory state system attribute name */
+ static final String UST_MEMORY_MEMORY_ATTRIBUTE = "Memory"; //$NON-NLS-1$
+ /** Procname state system attribute name */
+ static final String UST_MEMORY_PROCNAME_ATTRIBUTE = "Procname"; //$NON-NLS-1$
+ /** Name of the attribute to store memory usage of events with no context */
+ static final String OTHERS = "Others";
+
+ /* UST_libc event names */
+ static final String MALLOC = "ust_libc:malloc";
+ static final String CALLOC = "ust_libc:calloc";
+ static final String REALLOC = "ust_libc:realloc";
+ static final String FREE = "ust_libc:free";
+ static final String MEMALIGN = "ust_libc:memalign";
+ static final String POSIX_MEMALIGN = "ust_libc:posix_memalign";
+
+ /* Possible contexts */
+ static final String CONTEXT_VTID = "context._vtid";
+ static final String CONTEXT_PROCNAME = "context._procname";
+
+ /* Event fields */
+ static final String FIELD_PTR = "ptr";
+ static final String FIELD_NMEMB = "nmemb";
+ static final String FIELD_SIZE = "size";
+ static final String FIELD_OUTPTR = "out_ptr";
+ static final String FIELD_INPTR = "in_ptr";
+
+}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2013, 2015 Ericsson
+ *
+ * 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:
+ * Alexandre Montplaisir - Initial API and implementation
+ * Patrick Tasse - Add support for thread id
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.lttng2.ust.core.callstack;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jdt.annotation.NonNull;
+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.ctf.core.event.CtfTmfEvent;
+
+/**
+ * Callstack provider for LTTng-UST traces.
+ *
+ * If the traces contains 'func_entry' and 'func_exit' event (see the
+ * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
+ * can use this information to populate the TMF Callstack View.
+ *
+ * Granted, most UST traces will not contain this information. In this case,
+ * this will simply build an empty state system, and the view will remain
+ * unavailable.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class LttngUstCallStackProvider extends CallStackStateProvider {
+
+ // ------------------------------------------------------------------------
+ // Event strings
+ // ------------------------------------------------------------------------
+
+ /** Name of the fake field for the vtid contexts */
+ private static final String CONTEXT_VTID = "context._vtid"; //$NON-NLS-1$
+
+ /** Name of the fake field for the procname context */
+ private static final String CONTEXT_PROCNAME = "context._procname"; //$NON-NLS-1$
+
+ /** Field name for the target function address */
+ private static final String FIELD_ADDR = "addr"; //$NON-NLS-1$
+
+ /** Event names indicating function entry */
+ private static final Set<String> FUNC_ENTRY_EVENTS = new HashSet<>();
+
+ /** Event names indicating function exit */
+ private static final Set<String> FUNC_EXIT_EVENTS = new HashSet<>();
+
+ static {
+ /* This seems overkill, but it will be checked every event. Gotta go FAST! */
+ FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
+ FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
+
+ FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
+ FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
+ }
+
+ /**
+ * Version number of this state provider. Please bump this if you modify
+ * the contents of the generated state history in some way.
+ */
+ private static final int VERSION = 2;
+
+ // ------------------------------------------------------------------------
+ // Constructor
+ // ------------------------------------------------------------------------
+
+ /**
+ * Constructor
+ *
+ * @param trace
+ * The UST trace
+ */
+ public LttngUstCallStackProvider(@NonNull ITmfTrace trace) {
+ super(trace);
+ }
+
+ // ------------------------------------------------------------------------
+ // Methods from AbstractTmfStateProvider
+ // ------------------------------------------------------------------------
+
+ @Override
+ public LttngUstCallStackProvider getNewInstance() {
+ return new LttngUstCallStackProvider(getTrace());
+ }
+
+ @Override
+ public int getVersion() {
+ return VERSION;
+ }
+
+ // ------------------------------------------------------------------------
+ // Methods from CallStackStateProvider
+ // ------------------------------------------------------------------------
+
+ /**
+ * Check that this event contains the required information we need to be
+ * used in the call stack view. We need at least the "procname" and "vtid"
+ * contexts.
+ */
+ @Override
+ protected boolean considerEvent(ITmfEvent event) {
+ if (!(event instanceof CtfTmfEvent)) {
+ return false;
+ }
+ ITmfEventField content = ((CtfTmfEvent) event).getContent();
+ if (content.getField(CONTEXT_VTID) == null ||
+ content.getField(CONTEXT_PROCNAME) == null) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String functionEntry(ITmfEvent event) {
+ String eventName = event.getName();
+ if (!FUNC_ENTRY_EVENTS.contains(eventName)) {
+ return null;
+ }
+ Long address = (Long) event.getContent().getField(FIELD_ADDR).getValue();
+ return Long.toHexString(address);
+ }
+
+ @Override
+ public String functionExit(ITmfEvent event) {
+ String eventName = event.getName();
+ if (!FUNC_EXIT_EVENTS.contains(eventName)) {
+ return null;
+ }
+ /*
+ * The 'addr' field may or may not be present in func_exit events,
+ * depending on if cyg-profile.so or cyg-profile-fast.so was used.
+ */
+ ITmfEventField field = event.getContent().getField(FIELD_ADDR);
+ if (field == null) {
+ return CallStackStateProvider.UNDEFINED;
+ }
+ Long address = (Long) field.getValue();
+ return Long.toHexString(address);
+ }
+
+ @Override
+ public String getThreadName(ITmfEvent event) {
+ /* Class type and content was already checked if we get called here */
+ ITmfEventField content = ((CtfTmfEvent) event).getContent();
+ String procName = (String) content.getField(CONTEXT_PROCNAME).getValue();
+ Long vtid = (Long) content.getField(CONTEXT_VTID).getValue();
+
+ if (procName == null || vtid == null) {
+ throw new IllegalStateException();
+ }
+
+ return new String(procName + '-' + vtid.toString());
+ }
+
+ @Override
+ protected Long getThreadId(ITmfEvent event) {
+ ITmfEventField content = ((CtfTmfEvent) event).getContent();
+ return (Long) content.getField(CONTEXT_VTID).getValue();
+ }
+}
+++ /dev/null
-/**********************************************************************
- * Copyright (c) 2014, 2015 Ericsson, É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:
- * Matthew Khouzam - Initial API and implementation
- * Geneviève Bastien - Memory is per thread and only total is kept
- **********************************************************************/
-
-package org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage;
-
-import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
-import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
-import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
-import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
-import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
-import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
-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;
-
-/**
- * State provider to track the memory of the threads using the UST libc wrapper
- * memory events.
- *
- * @author Matthew Khouzam
- * @author Geneviève Bastien
- */
-public class MemoryUsageStateProvider extends AbstractTmfStateProvider {
-
- /* Version of this state provider */
- private static final int VERSION = 1;
-
- /* Maps a pointer to a memory zone to the size of the memory */
- private final Map<Long, Long> fMemory = new HashMap<>();
-
- private static final Long MINUS_ONE = Long.valueOf(-1);
- private static final Long ZERO = Long.valueOf(0);
- private static final String EMPTY_STRING = ""; //$NON-NLS-1$
-
- /**
- * Constructor
- *
- * @param trace
- * trace
- */
- public MemoryUsageStateProvider(@NonNull LttngUstTrace trace) {
- super(trace, "Ust:Memory"); //$NON-NLS-1$
- }
-
- @Override
- protected void eventHandle(ITmfEvent event) {
- String name = event.getName();
- switch (name) {
- case UstMemoryStrings.MALLOC: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
- setMem(event, ptr, size);
- }
- break;
- case UstMemoryStrings.FREE: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- setMem(event, ptr, ZERO);
- }
- break;
- case UstMemoryStrings.CALLOC: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- Long nmemb = (Long) event.getContent().getField(UstMemoryStrings.FIELD_NMEMB).getValue();
- Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
- setMem(event, ptr, size * nmemb);
- }
- break;
- case UstMemoryStrings.REALLOC: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- Long newPtr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_INPTR).getValue();
- Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
- setMem(event, ptr, ZERO);
- setMem(event, newPtr, size);
- }
- break;
- case UstMemoryStrings.MEMALIGN: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_PTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
- setMem(event, ptr, size);
- }
- break;
- case UstMemoryStrings.POSIX_MEMALIGN: {
- Long ptr = (Long) event.getContent().getField(UstMemoryStrings.FIELD_OUTPTR).getValue();
- if (ZERO.equals(ptr)) {
- return;
- }
- Long size = (Long) event.getContent().getField(UstMemoryStrings.FIELD_SIZE).getValue();
- setMem(event, ptr, size);
- }
- break;
- default:
- break;
- }
-
- }
-
- @Override
- public ITmfStateProvider getNewInstance() {
- return new MemoryUsageStateProvider(getTrace());
- }
-
- @Override
- public LttngUstTrace getTrace() {
- return (LttngUstTrace) super.getTrace();
- }
-
- @Override
- public int getVersion() {
- return VERSION;
- }
-
- private static Long getVtid(ITmfEvent event) {
- ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_VTID);
- if (field == null) {
- return MINUS_ONE;
- }
- return (Long) field.getValue();
- }
-
- private static String getProcname(ITmfEvent event) {
- ITmfEventField field = event.getContent().getField(UstMemoryStrings.CONTEXT_PROCNAME);
- if (field == null) {
- return EMPTY_STRING;
- }
- return (String) field.getValue();
- }
-
- private void setMem(ITmfEvent event, Long ptr, Long size) {
- ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
- long ts = event.getTimestamp().getValue();
- Long tid = getVtid(event);
-
- Long memoryDiff = size;
- /* Size is 0, it means it was deleted */
- if (ZERO.equals(size)) {
- Long memSize = fMemory.remove(ptr);
- if (memSize == null) {
- return;
- }
- memoryDiff = -memSize;
- } else {
- fMemory.put(ptr, size);
- }
- try {
- int tidQuark = ss.getQuarkAbsoluteAndAdd(tid.toString());
- int tidMemQuark = ss.getQuarkRelativeAndAdd(tidQuark, UstMemoryStrings.UST_MEMORY_MEMORY_ATTRIBUTE);
-
- ITmfStateValue prevMem = ss.queryOngoingState(tidMemQuark);
- /* First time we set this value */
- if (prevMem.isNull()) {
- int procNameQuark = ss.getQuarkRelativeAndAdd(tidQuark, UstMemoryStrings.UST_MEMORY_PROCNAME_ATTRIBUTE);
- String procName = getProcname(event);
- /*
- * No tid/procname for the event for the event, added to a
- * 'others' thread
- */
- if (tid.equals(MINUS_ONE)) {
- procName = UstMemoryStrings.OTHERS;
- }
- ss.modifyAttribute(ts, TmfStateValue.newValueString(procName), procNameQuark);
- prevMem = TmfStateValue.newValueLong(0);
- }
-
- long prevMemValue = prevMem.unboxLong();
- prevMemValue += memoryDiff.longValue();
- ss.modifyAttribute(ts, TmfStateValue.newValueLong(prevMemValue), tidMemQuark);
- } catch (AttributeNotFoundException | TimeRangeException | StateValueTypeException e) {
- throw new IllegalStateException(e);
- }
- }
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2014 Ericsson, É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:
- * Matthew Khouzam, Geneviève Bastien - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage;
-
-/**
- * Strings for the memory usage state system using the LTTng UST libc
- * instrumentation
- *
- * @author Matthew Khouzam
- * @author Geneviève Bastien
- */
-@SuppressWarnings({ "nls", "javadoc" })
-public interface UstMemoryStrings {
-
- /** Memory state system attribute name */
- static final String UST_MEMORY_MEMORY_ATTRIBUTE = "Memory"; //$NON-NLS-1$
- /** Procname state system attribute name */
- static final String UST_MEMORY_PROCNAME_ATTRIBUTE = "Procname"; //$NON-NLS-1$
- /** Name of the attribute to store memory usage of events with no context */
- static final String OTHERS = "Others";
-
- /* UST_libc event names */
- static final String MALLOC = "ust_libc:malloc";
- static final String CALLOC = "ust_libc:calloc";
- static final String REALLOC = "ust_libc:realloc";
- static final String FREE = "ust_libc:free";
- static final String MEMALIGN = "ust_libc:memalign";
- static final String POSIX_MEMALIGN = "ust_libc:posix_memalign";
-
- /* Possible contexts */
- static final String CONTEXT_VTID = "context._vtid";
- static final String CONTEXT_PROCNAME = "context._procname";
-
- /* Event fields */
- static final String FIELD_PTR = "ptr";
- static final String FIELD_NMEMB = "nmemb";
- static final String FIELD_SIZE = "size";
- static final String FIELD_OUTPTR = "out_ptr";
- static final String FIELD_INPTR = "in_ptr";
-
-}
+++ /dev/null
-/*******************************************************************************
- * Copyright (c) 2013, 2015 Ericsson
- *
- * 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:
- * Alexandre Montplaisir - Initial API and implementation
- * Patrick Tasse - Add support for thread id
- *******************************************************************************/
-
-package org.eclipse.tracecompass.internal.lttng2.ust.core.trace.callstack;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.jdt.annotation.NonNull;
-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.ctf.core.event.CtfTmfEvent;
-
-/**
- * Callstack provider for LTTng-UST traces.
- *
- * If the traces contains 'func_entry' and 'func_exit' event (see the
- * lttng-ust-cyg-profile manpage), AND contains vtid and procname contexts, we
- * can use this information to populate the TMF Callstack View.
- *
- * Granted, most UST traces will not contain this information. In this case,
- * this will simply build an empty state system, and the view will remain
- * unavailable.
- *
- * @author Alexandre Montplaisir
- */
-public class LttngUstCallStackProvider extends CallStackStateProvider {
-
- // ------------------------------------------------------------------------
- // Event strings
- // ------------------------------------------------------------------------
-
- /** Name of the fake field for the vtid contexts */
- private static final String CONTEXT_VTID = "context._vtid"; //$NON-NLS-1$
-
- /** Name of the fake field for the procname context */
- private static final String CONTEXT_PROCNAME = "context._procname"; //$NON-NLS-1$
-
- /** Field name for the target function address */
- private static final String FIELD_ADDR = "addr"; //$NON-NLS-1$
-
- /** Event names indicating function entry */
- private static final Set<String> FUNC_ENTRY_EVENTS = new HashSet<>();
-
- /** Event names indicating function exit */
- private static final Set<String> FUNC_EXIT_EVENTS = new HashSet<>();
-
- static {
- /* This seems overkill, but it will be checked every event. Gotta go FAST! */
- FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile:func_entry"); //$NON-NLS-1$
- FUNC_ENTRY_EVENTS.add("lttng_ust_cyg_profile_fast:func_entry"); //$NON-NLS-1$
-
- FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile:func_exit"); //$NON-NLS-1$
- FUNC_EXIT_EVENTS.add("lttng_ust_cyg_profile_fast:func_exit"); //$NON-NLS-1$
- }
-
- /**
- * Version number of this state provider. Please bump this if you modify
- * the contents of the generated state history in some way.
- */
- private static final int VERSION = 2;
-
- // ------------------------------------------------------------------------
- // Constructor
- // ------------------------------------------------------------------------
-
- /**
- * Constructor
- *
- * @param trace
- * The UST trace
- */
- public LttngUstCallStackProvider(@NonNull ITmfTrace trace) {
- super(trace);
- }
-
- // ------------------------------------------------------------------------
- // Methods from AbstractTmfStateProvider
- // ------------------------------------------------------------------------
-
- @Override
- public LttngUstCallStackProvider getNewInstance() {
- return new LttngUstCallStackProvider(getTrace());
- }
-
- @Override
- public int getVersion() {
- return VERSION;
- }
-
- // ------------------------------------------------------------------------
- // Methods from CallStackStateProvider
- // ------------------------------------------------------------------------
-
- /**
- * Check that this event contains the required information we need to be
- * used in the call stack view. We need at least the "procname" and "vtid"
- * contexts.
- */
- @Override
- protected boolean considerEvent(ITmfEvent event) {
- if (!(event instanceof CtfTmfEvent)) {
- return false;
- }
- ITmfEventField content = ((CtfTmfEvent) event).getContent();
- if (content.getField(CONTEXT_VTID) == null ||
- content.getField(CONTEXT_PROCNAME) == null) {
- return false;
- }
- return true;
- }
-
- @Override
- public String functionEntry(ITmfEvent event) {
- String eventName = event.getName();
- if (!FUNC_ENTRY_EVENTS.contains(eventName)) {
- return null;
- }
- Long address = (Long) event.getContent().getField(FIELD_ADDR).getValue();
- return Long.toHexString(address);
- }
-
- @Override
- public String functionExit(ITmfEvent event) {
- String eventName = event.getName();
- if (!FUNC_EXIT_EVENTS.contains(eventName)) {
- return null;
- }
- /*
- * The 'addr' field may or may not be present in func_exit events,
- * depending on if cyg-profile.so or cyg-profile-fast.so was used.
- */
- ITmfEventField field = event.getContent().getField(FIELD_ADDR);
- if (field == null) {
- return CallStackStateProvider.UNDEFINED;
- }
- Long address = (Long) field.getValue();
- return Long.toHexString(address);
- }
-
- @Override
- public String getThreadName(ITmfEvent event) {
- /* Class type and content was already checked if we get called here */
- ITmfEventField content = ((CtfTmfEvent) event).getContent();
- String procName = (String) content.getField(CONTEXT_PROCNAME).getValue();
- Long vtid = (Long) content.getField(CONTEXT_VTID).getValue();
-
- if (procName == null || vtid == null) {
- throw new IllegalStateException();
- }
-
- return new String(procName + '-' + vtid.toString());
- }
-
- @Override
- protected Long getThreadId(ITmfEvent event) {
- ITmfEventField content = ((CtfTmfEvent) event).getContent();
- return (Long) content.getField(CONTEXT_VTID).getValue();
- }
-}
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage.MemoryUsageStateProvider;
-import org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage.UstMemoryStrings;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStateProvider;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStrings;
import org.eclipse.tracecompass.lttng2.control.core.session.SessionConfigStrings;
import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
import org.eclipse.tracecompass.tmf.core.analysis.TmfAnalysisRequirement;
@Override
protected ITmfStateProvider createStateProvider() {
- return new MemoryUsageStateProvider(checkNotNull(getTrace()));
+ return new UstMemoryStateProvider(checkNotNull(getTrace()));
}
/**
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.tracecompass.internal.lttng2.ust.core.memoryusage.UstMemoryStrings;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStrings;
import org.eclipse.tracecompass.internal.tmf.core.Activator;
import org.eclipse.tracecompass.lttng2.ust.core.analysis.memory.UstMemoryAnalysisModule;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
-import org.eclipse.tracecompass.internal.lttng2.ust.core.trace.callstack.LttngUstCallStackProvider;
+import org.eclipse.tracecompass.internal.lttng2.ust.core.callstack.LttngUstCallStackProvider;
import org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace;
import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
import org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider;