Search in sources :

Example 6 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateSystemTest method testRangeQueryInvalidTime2.

@Test(expected = TimeRangeException.class)
public void testRangeQueryInvalidTime2() throws TimeRangeException {
    final ITmfStateSystem ss = fixture;
    assertNotNull(ss);
    try {
        int quark = ss.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
        long ts1 = startTime - 1L * NANOSECS_PER_SEC;
        /* invalid */
        long ts2 = startTime + 20L * NANOSECS_PER_SEC;
        /* invalid */
        StateSystemUtils.queryHistoryRange(ss, quark, ts1, ts2);
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail();
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 7 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class AbstractProviderTest method testOtherUstTrace.

// ------------------------------------------------------------------------
// 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;
    CtfTmfTrace ustTrace = CtfTmfTestTraceUtils.getTrace(otherUstTrace);
    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().toNanos());
        assertEquals(0, ss.getNbAttributes());
    } finally {
        if (module != null) {
            module.dispose();
        }
    }
    suppDir = new File(TmfTraceManager.getSupplementaryFileDir(ustTrace));
    ustTrace.dispose();
    deleteDirectory(suppDir);
    assertFalse(suppDir.exists());
}
Also used : TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) File(java.io.File) CtfTmfTrace(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 8 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class UstDebugInfoAnalysisModule method getMatchingFile.

/**
 * Get the binary file (executable or library) that corresponds to a given
 * instruction pointer, at a given time.
 *
 * @param ts
 *            The timestamp
 * @param vpid
 *            The VPID of the process we are querying for
 * @param ip
 *            The instruction pointer of the trace event. Normally comes
 *            from a 'ip' context.
 * @return A {@link UstDebugInfoLoadedBinaryFile} object, describing the
 *         binary file and its base address.
 * @noreference Meant to be used internally by
 *              {@link UstDebugInfoBinaryAspect} only.
 */
@VisibleForTesting
@Nullable
public UstDebugInfoLoadedBinaryFile getMatchingFile(long ts, long vpid, long ip) {
    try {
        final ITmfStateSystem ss = getStateSystem();
        if (ss == null) {
            /* State system might not yet be initialized */
            return null;
        }
        // $NON-NLS-1$
        List<Integer> possibleBaddrQuarks = ss.getQuarks(String.valueOf(vpid), "*");
        List<ITmfStateInterval> state = ss.queryFullState(ts);
        /* Get the most probable base address from all the known ones */
        OptionalLong potentialBaddr = possibleBaddrQuarks.stream().filter(quark -> Objects.equals(1, state.get(quark).getValue())).map(ss::getAttributeName).mapToLong(Long::parseLong).filter(baddr -> baddr <= ip).max();
        if (!potentialBaddr.isPresent()) {
            return null;
        }
        long baddr = potentialBaddr.getAsLong();
        final int baddrQuark = ss.getQuarkAbsolute(String.valueOf(vpid), String.valueOf(baddr));
        final int memszQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.MEMSZ_ATTRIB);
        final long memsz = state.get(memszQuark).getStateValue().unboxLong();
        /* Make sure the 'ip' fits the range of this object. */
        if (!(ip < baddr + memsz)) {
            /*
                 * Not the correct memory range after all. We do not have
                 * information about the library that was loaded here.
                 */
            return null;
        }
        final int pathQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.PATH_ATTRIB);
        String filePath = state.get(pathQuark).getStateValue().unboxStr();
        final int buildIdQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.BUILD_ID_ATTRIB);
        ITmfStateValue buildIdValue = state.get(buildIdQuark).getStateValue();
        String buildId = unboxStrOrNull(buildIdValue);
        final int debugLinkQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.DEBUG_LINK_ATTRIB);
        ITmfStateValue debugLinkValue = state.get(debugLinkQuark).getStateValue();
        String debugLink = unboxStrOrNull(debugLinkValue);
        final int isPicQuark = ss.getQuarkRelative(baddrQuark, UstDebugInfoStateProvider.IS_PIC_ATTRIB);
        boolean isPic = state.get(isPicQuark).getStateValue().unboxInt() != 0;
        // The baddrQuark interval lasts for the time this file is loaded
        ITmfStateInterval validityInterval = state.get(baddrQuark);
        return new UstDebugInfoLoadedBinaryFile(baddr, filePath, buildId, debugLink, isPic, validityInterval.getStartTime(), validityInterval.getEndTime());
    } catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException e) {
        /* Either the data is not available yet, or incomplete. */
        return null;
    }
}
Also used : ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) CtfUtils(org.eclipse.tracecompass.tmf.ctf.core.trace.CtfUtils) TmfStateSystemAnalysisModule(org.eclipse.tracecompass.tmf.core.statesystem.TmfStateSystemAnalysisModule) TreeSet(java.util.TreeSet) TmfAnalysisException(org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException) OptionalLong(java.util.OptionalLong) LttngUstTrace(org.eclipse.tracecompass.lttng2.ust.core.trace.LttngUstTrace) ImmutableList(com.google.common.collect.ImmutableList) Nullable(org.eclipse.jdt.annotation.Nullable) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) NonNullUtils.checkNotNull(org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Collection(java.util.Collection) Set(java.util.Set) TmfAbstractAnalysisRequirement(org.eclipse.tracecompass.tmf.core.analysis.requirements.TmfAbstractAnalysisRequirement) ITmfStateProvider(org.eclipse.tracecompass.tmf.core.statesystem.ITmfStateProvider) Objects(java.util.Objects) List(java.util.List) UstDebugInfoStateProvider(org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.debuginfo.UstDebugInfoStateProvider) StateSystemUtils(org.eclipse.tracecompass.statesystem.core.StateSystemUtils) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) OptionalLong(java.util.OptionalLong) OptionalLong(java.util.OptionalLong) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 9 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkSubrange.

/**
 * Test that getIteratorOverQuark returns the correct intervals for a range
 * included in the state system range
 */
@Test
public void testIteratorOverQuarkSubrange() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    int quark;
    try {
        quark = ss.getQuarkAbsolute(DUMMY_STRING);
        QuarkIterator iterator = new QuarkIterator(ss, quark, 1800L);
        /* There should be one interval ranging from 1500L to 2000L */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1500L, interval.getStartTime());
        assertEquals(2000L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 10 with ITmfStateSystem

use of org.eclipse.tracecompass.statesystem.core.ITmfStateSystem in project tracecompass by tracecompass.

the class StateSystemUtilsTest method testIteratorOverQuarkEndTime.

/**
 * Test that getIteratorOverQuark returns the correct intervals for a range
 * included in the state system range
 */
@Test
public void testIteratorOverQuarkEndTime() {
    ITmfStateSystem ss = fStateSystem;
    assertNotNull(ss);
    int quark;
    try {
        quark = ss.getQuarkAbsolute(DUMMY_STRING);
        QuarkIterator iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1199);
        /* There should be one interval ranging from 1000L to 1199L */
        assertTrue(iterator.hasNext());
        ITmfStateInterval interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, Long.MIN_VALUE, 1200);
        /* There should be 2 intervals ranging from 1000L to 1199L and 1200L to 1499L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1000L, interval.getStartTime());
        assertEquals(1199L, interval.getEndTime());
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1200L, interval.getStartTime());
        assertEquals(1499L, interval.getEndTime());
        /* There should not be a next interval */
        assertFalse(iterator.hasNext());
        iterator = new QuarkIterator(ss, quark, 1800, 5000);
        /* There should be one interval ranging from 1500L to 2000L */
        assertTrue(iterator.hasNext());
        interval = iterator.next();
        assertNotNull(interval);
        assertEquals(1500L, interval.getStartTime());
        assertEquals(2000L, interval.getEndTime());
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    }
}
Also used : AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) QuarkIterator(org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Aggregations

ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)137 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)52 Test (org.junit.Test)52 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)51 NonNull (org.eclipse.jdt.annotation.NonNull)32 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)30 Nullable (org.eclipse.jdt.annotation.Nullable)26 ArrayList (java.util.ArrayList)25 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)23 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)22 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)22 HashMap (java.util.HashMap)18 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)16 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)16 AtomicLong (java.util.concurrent.atomic.AtomicLong)15 DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 List (java.util.List)9 QuarkIterator (org.eclipse.tracecompass.statesystem.core.StateSystemUtils.QuarkIterator)9 TmfAnalysisException (org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException)9