Search in sources :

Example 1 with TimeRangeException

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

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

the class InMemoryBackendTest method init.

/**
 * Test setup. make a state system that is moderately large
 */
@BeforeClass
public static void init() {
    IStateHistoryBackend backend = StateHistoryBackendFactory.createInMemoryBackend(SSID, 0);
    for (int attribute = 0; attribute < NUMBER_OF_ATTRIBUTES; attribute++) {
        for (int timeStart = 0; timeStart < 1000; timeStart++) {
            try {
                final int stateEndTime = (timeStart * 100) + 90 + attribute;
                final int stateStartTime = timeStart * 100 + attribute;
                backend.insertPastState(stateStartTime, stateEndTime, attribute, timeStart % 100);
                if (timeStart != 999) {
                    backend.insertPastState(stateEndTime + 1, stateEndTime + 9, attribute, (Object) null);
                }
            } catch (TimeRangeException e) {
                /* Should not happen here */
                throw new IllegalStateException();
            }
        }
    }
    fixture = backend;
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) IStateHistoryBackend(org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend) BeforeClass(org.junit.BeforeClass)

Example 3 with TimeRangeException

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

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

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

the class HTInterval method readFrom.

/**
 * Reader factory method. Builds the interval using an already-allocated
 * ByteBuffer, which normally comes from a NIO FileChannel.
 *
 * The interval is just a start, end, attribute and value, this is the
 * layout of the HTInterval on disk
 * <ul>
 * <li>start (2-9 bytes)</li>
 * <li>end (2-9 bytes)</li>
 * <li>attribute (4 bytes)</li>
 * <li>sv type (1 byte)</li>
 * <li>sv ( 0 bytes for null, 4 for int , 8 for long and double, and the
 * length of the string +2 for strings (it's variable))</li>
 * </ul>
 *
 * @param buffer
 *            The ByteBuffer from which to read the information
 * @param nodeStart
 *             The start time of the node this interval is linked to
 * @return The interval object
 * @throws IOException
 *             If there was an error reading from the buffer
 */
public static final HTInterval readFrom(ByteBuffer buffer, long nodeStart) throws IOException {
    Object value;
    int posStart = buffer.position();
    /* Read the Data Section entry */
    long intervalStart = HTVarInt.readLong(buffer) + nodeStart;
    long intervalEnd = HTVarInt.readLong(buffer) + intervalStart;
    int attribute = buffer.getInt();
    /* Read the 'type' of the value, then react accordingly */
    byte valueType = buffer.get();
    switch(valueType) {
        case TYPE_NULL:
            value = null;
            break;
        case TYPE_INTEGER:
            value = buffer.getInt();
            break;
        case TYPE_STRING:
            {
                /* the first short = the size to read */
                int valueSize = buffer.getShort();
                byte[] array = new byte[valueSize];
                buffer.get(array);
                value = new String(array, CHARSET);
                /* Confirm the 0'ed byte at the end */
                byte res = buffer.get();
                if (res != 0) {
                    throw new IOException(errMsg);
                }
                break;
            }
        case TYPE_LONG:
            /* Go read the matching entry in the Strings section of the block */
            value = buffer.getLong();
            break;
        case TYPE_DOUBLE:
            /* Go read the matching entry in the Strings section of the block */
            value = buffer.getDouble();
            break;
        case TYPE_CUSTOM:
            {
                short valueSize = buffer.getShort();
                ISafeByteBufferReader safeBuffer = SafeByteBufferFactory.wrapReader(buffer, valueSize);
                value = CustomStateValue.readSerializedValue(safeBuffer);
                break;
            }
        default:
            /* Unknown data, better to not make anything up... */
            throw new IOException(errMsg);
    }
    try {
        return new HTInterval(intervalStart, intervalEnd, attribute, value, buffer.position() - posStart);
    } catch (TimeRangeException e) {
        throw new IOException(errMsg);
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) IOException(java.io.IOException) ISafeByteBufferReader(org.eclipse.tracecompass.datastore.core.serialization.ISafeByteBufferReader)

Aggregations

TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)55 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)41 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)40 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)22 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)20 Test (org.junit.Test)17 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)15 NonNull (org.eclipse.jdt.annotation.NonNull)13 ArrayList (java.util.ArrayList)12 Nullable (org.eclipse.jdt.annotation.Nullable)11 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)10 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)9 HashMap (java.util.HashMap)8 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)8 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)8 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)6 TimeGraphModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel)6 List (java.util.List)5 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)5