Search in sources :

Example 1 with ITmfStateValue

use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.

the class AbstractProviderTest method getCallStack.

/**
 * Get the callstack for the given timestamp, for this particular trace
 */
private static String[] getCallStack(ITmfStateSystem ss, int pid, String threadName, long timestamp) {
    try {
        String processName = (pid == CallStackStateProvider.UNKNOWN_PID) ? CallStackStateProvider.UNKNOWN : Integer.toString(pid);
        int stackAttribute = ss.getQuarkAbsolute("Processes", processName, threadName, "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] = Long.toHexString(state.get(quark).getStateValue().unboxLong());
        }
        return ret;
    } catch (AttributeNotFoundException e) {
        fail(e.getMessage());
    } catch (StateSystemDisposedException e) {
        fail(e.getMessage());
    }
    fail();
    return null;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)

Example 2 with ITmfStateValue

use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue 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 3 with ITmfStateValue

use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.

the class StateSystemTest method testSetAndQueryOngoing.

/**
 * Test modifying or updating the state value, then querying it
 */
@Test
public void testSetAndQueryOngoing() {
    ITmfStateSystemBuilder ss = fSs;
    assertNotNull(ss);
    long time = 10;
    int quark = ss.getQuarkAbsoluteAndAdd("Test");
    // Modify the attribute, then query the ongoing value
    long val = 10L;
    ss.modifyAttribute(time, val, quark);
    // Query the state value
    ITmfStateValue ongoingState = ss.queryOngoingState(quark);
    assertTrue(ongoingState.getType() == Type.LONG);
    assertEquals(val, ongoingState.unboxLong());
    // Query the value
    Object ongoing = ss.queryOngoing(quark);
    assertTrue(ongoing instanceof Long);
    assertEquals(val, ongoing);
    // Modify with a state value, the query the ongoing value
    val = 12L;
    ss.modifyAttribute(time + 1, val, quark);
    // Query the state value
    ongoingState = ss.queryOngoingState(quark);
    assertTrue(ongoingState.getType() == Type.LONG);
    assertEquals(val, ongoingState.unboxLong());
    // Query the value
    ongoing = ss.queryOngoing(quark);
    assertTrue(ongoing instanceof Long);
    assertEquals(val, ongoing);
    // Update the ongoing value with a state value, then query
    val = 14L;
    ss.updateOngoingState(TmfStateValue.newValue(val), quark);
    // Query the state value
    ongoingState = ss.queryOngoingState(quark);
    assertTrue(ongoingState.getType() == Type.LONG);
    assertEquals(val, ongoingState.unboxLong());
    // Query the value
    ongoing = ss.queryOngoing(quark);
    assertTrue(ongoing instanceof Long);
    assertEquals(val, ongoing);
    // Update the ongoing value, then query
    val = 16L;
    ss.updateOngoingState(val, quark);
    // Query the state value
    ongoingState = ss.queryOngoingState(quark);
    assertTrue(ongoingState.getType() == Type.LONG);
    assertEquals(val, ongoingState.unboxLong());
    // Query the value
    ongoing = ss.queryOngoing(quark);
    assertTrue(ongoing instanceof Long);
    assertEquals(val, ongoing);
}
Also used : ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) Test(org.junit.Test)

Example 4 with ITmfStateValue

use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.

the class TmfStateValueScenarioTest method testAttributePool.

/**
 * Test that attribute pool are generated and populated correctly
 *
 * @throws StateSystemDisposedException
 *             Exceptions thrown during state system verification
 * @throws AttributeNotFoundException
 *             Exceptions thrown during state system verification
 */
@Test
public void testAttributePool() throws AttributeNotFoundException, StateSystemDisposedException {
    XmlPatternAnalysis module = fModule;
    assertNotNull(module);
    ITmfStateSystem ss = module.getStateSystem(module.getId());
    assertNotNull(ss);
    int quark = ss.getQuarkAbsolute("Operations");
    List<Integer> subAttributes = ss.getSubAttributes(quark, false);
    assertEquals("Number of attribute pool children", 2, subAttributes.size());
    final int[] expectedStarts = { 1, 2, 3, 5, 7, 10, 14, 20, 20 };
    ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue() };
    XmlUtilsTest.verifyStateIntervals("testAttributePool", ss, subAttributes.get(0), expectedStarts, expectedValues);
    final int[] expectedStarts2 = { 1, 2, 3, 4, 20 };
    ITmfStateValue[] expectedValues2 = { TmfStateValue.nullValue(), TmfStateValue.newValueString("op1"), TmfStateValue.newValueString("op2"), TmfStateValue.nullValue() };
    XmlUtilsTest.verifyStateIntervals("testAttributePool", ss, subAttributes.get(1), expectedStarts2, expectedValues2);
}
Also used : XmlPatternAnalysis(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Example 5 with ITmfStateValue

use of org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue in project tracecompass by tracecompass.

the class TmfStateValueTest method testStateValueHostId.

/**
 * Test using the HostID event field. It should give the host ID for value
 *
 * @throws StateSystemDisposedException
 *             Exceptions thrown during state system verification
 * @throws AttributeNotFoundException
 *             Exceptions thrown during state system verification
 */
@Test
public void testStateValueHostId() throws AttributeNotFoundException, StateSystemDisposedException {
    DataDrivenAnalysisModule module = fModule;
    assertNotNull(module);
    ITmfStateSystem ss = module.getStateSystem();
    assertNotNull(ss);
    int quark = ss.getQuarkAbsolute("hostID");
    final int[] expectedStarts = { 1, 20 };
    ITmfStateValue[] expectedValues = { TmfStateValue.newValueString("testTrace4.xml") };
    XmlUtilsTest.verifyStateIntervals("testHostId", ss, quark, expectedStarts, expectedValues);
}
Also used : DataDrivenAnalysisModule(org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test) XmlUtilsTest(org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)

Aggregations

ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)53 Test (org.junit.Test)19 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)16 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)15 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)10 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)10 XmlUtilsTest (org.eclipse.tracecompass.tmf.analysis.xml.core.tests.module.XmlUtilsTest)10 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)9 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)8 DataDrivenAnalysisModule (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.fsm.module.DataDrivenAnalysisModule)7 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)7 NonNull (org.eclipse.jdt.annotation.NonNull)4 Nullable (org.eclipse.jdt.annotation.Nullable)4 IOException (java.io.IOException)3 XmlPatternAnalysis (org.eclipse.tracecompass.internal.tmf.analysis.xml.core.pattern.stateprovider.XmlPatternAnalysis)3 ITmfEventField (org.eclipse.tracecompass.tmf.core.event.ITmfEventField)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 KernelAnalysisModule (org.eclipse.tracecompass.analysis.os.linux.core.kernel.KernelAnalysisModule)2