Search in sources :

Example 6 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException 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 7 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException 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 8 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class InMemoryBackendTest method testDoQuery.

/**
 * Query the state system
 */
@Test
public void testDoQuery() {
    List<@Nullable ITmfStateInterval> interval = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
    for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
        interval.add(null);
    }
    IStateHistoryBackend backend = fixture;
    assertNotNull(backend);
    try {
        backend.doQuery(interval, 950);
    } catch (TimeRangeException | StateSystemDisposedException e) {
        fail(e.getMessage());
    }
    assertEquals(NUMBER_OF_ATTRIBUTES, interval.size());
    testInterval(interval.get(0), 900, 990, 9);
    testInterval(interval.get(1), 901, 991, 9);
    testInterval(interval.get(2), 902, 992, 9);
    testInterval(interval.get(3), 903, 993, 9);
    testInterval(interval.get(4), 904, 994, 9);
    testInterval(interval.get(5), 905, 995, 9);
    testInterval(interval.get(6), 906, 996, 9);
    testInterval(interval.get(7), 907, 997, 9);
    testInterval(interval.get(8), 908, 998, 9);
    testInterval(interval.get(9), 909, 999, 9);
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 9 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class InMemoryBackendTest method testQueryAttribute.

/**
 * Test single attribute then compare it to a full query
 */
@Test
public void testQueryAttribute() {
    try {
        IStateHistoryBackend backend = fixture;
        assertNotNull(backend);
        ITmfStateInterval[] interval = new TmfStateInterval[10];
        for (int i = 0; i < 10; i++) {
            interval[i] = backend.doSingularQuery(950, i);
        }
        testInterval(interval[0], 900, 990, 9);
        testInterval(interval[1], 901, 991, 9);
        testInterval(interval[2], 902, 992, 9);
        testInterval(interval[3], 903, 993, 9);
        testInterval(interval[4], 904, 994, 9);
        testInterval(interval[5], 905, 995, 9);
        testInterval(interval[6], 906, 996, 9);
        testInterval(interval[7], 907, 997, 9);
        testInterval(interval[8], 908, 998, 9);
        testInterval(interval[9], 909, 999, 9);
        List<@Nullable ITmfStateInterval> intervalQuery = new ArrayList<>(NUMBER_OF_ATTRIBUTES);
        for (int i = 0; i < NUMBER_OF_ATTRIBUTES; i++) {
            intervalQuery.add(null);
        }
        backend.doQuery(intervalQuery, 950);
        ITmfStateInterval[] ref = intervalQuery.toArray(new ITmfStateInterval[0]);
        assertArrayEquals(ref, interval);
    } catch (TimeRangeException | StateSystemDisposedException e) {
        fail(e.getMessage());
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) TmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) Test(org.junit.Test)

Example 10 with StateSystemDisposedException

use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.

the class StateSystem method queryFullState.

// --------------------------------------------------------------------------
// Regular query methods (sent to the back-end)
// --------------------------------------------------------------------------
@Override
public List<ITmfStateInterval> queryFullState(long t) throws TimeRangeException, StateSystemDisposedException {
    if (isDisposed) {
        throw new StateSystemDisposedException();
    }
    try (ScopeLog log = new // $NON-NLS-1$
    ScopeLog(// $NON-NLS-1$
    LOGGER, // $NON-NLS-1$
    Level.FINER, // $NON-NLS-1$
    "StateSystem:FullQuery", "ssid", getSSID(), "ts", t)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        final int nbAttr = getNbAttributes();
        List<@Nullable ITmfStateInterval> stateInfo = new ArrayList<>(nbAttr);
        /*
             * Bring the size of the array to the current number of attributes
             */
        for (int i = 0; i < nbAttr; i++) {
            stateInfo.add(null);
        }
        /*
             * If we are currently building the history, also query the
             * "ongoing" states for stuff that might not yet be written to the
             * history.
             */
        if (transState.isActive()) {
            transState.doQuery(stateInfo, t);
        }
        /* Query the storage backend */
        backend.doQuery(stateInfo, t);
        /*
             * We should have previously inserted an interval for every
             * attribute.
             */
        for (ITmfStateInterval interval : stateInfo) {
            if (interval == null) {
                // $NON-NLS-1$
                throw new IllegalStateException("Incoherent interval storage");
            }
        }
        return stateInfo;
    }
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog)

Aggregations

StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)96 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)78 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)51 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)40 Test (org.junit.Test)38 NonNull (org.eclipse.jdt.annotation.NonNull)25 ArrayList (java.util.ArrayList)24 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)16 HashMap (java.util.HashMap)15 Nullable (org.eclipse.jdt.annotation.Nullable)15 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)12 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)11 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)10 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)9 Map (java.util.Map)7