Search in sources :

Example 6 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class StateSystemTest method testRangeQuery1.

/**
 * Test a range query (with no resolution parameter, so all intervals)
 */
@Test
public void testRangeQuery1() {
    long time1 = interestingTimestamp1;
    long time2 = time1 + 1L * NANOSECS_PER_SEC;
    int quark;
    List<ITmfStateInterval> intervals;
    final ITmfStateSystem ss = fixture;
    assertNotNull(ss);
    try {
        quark = ss.getQuarkAbsolute(Attributes.CPUS, "0", Attributes.CURRENT_THREAD);
        intervals = StateSystemUtils.queryHistoryRange(ss, quark, time1, time2);
        assertEquals(487, intervals.size());
        /* Number of context switches! */
        assertEquals(1685, intervals.get(100).getStateValue().unboxInt());
        assertEquals(1331668248427681372L, intervals.get(205).getEndTime());
    } catch (AttributeNotFoundException | StateSystemDisposedException e) {
        fail();
    }
}
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) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Test(org.junit.Test)

Example 7 with ITmfStateInterval

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

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval in project tracecompass by tracecompass.

the class UstMemoryUsageDataProvider method getYSeriesModels.

/**
 * @since 3.3
 */
@Override
@Nullable
protected Collection<IYModel> getYSeriesModels(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return null;
    }
    long[] xValues = filter.getTimesRequested();
    long currentEnd = ss.getCurrentEndTime();
    Map<Integer, IYModel> models = initYModels(ss, filter);
    for (ITmfStateInterval interval : ss.query2D(models.keySet(), getTimes(filter, ss.getStartTime(), currentEnd))) {
        if (monitor != null && monitor.isCanceled()) {
            return null;
        }
        IYModel model = models.get(interval.getAttribute());
        Object value = interval.getValue();
        if (model != null && value instanceof Number) {
            int from = Arrays.binarySearch(xValues, interval.getStartTime());
            from = (from >= 0) ? from : -1 - from;
            int to = Arrays.binarySearch(xValues, interval.getEndTime());
            to = (to >= 0) ? to + 1 : -1 - to;
            Arrays.fill(model.getData(), from, to, ((Number) value).doubleValue());
        }
    }
    return models.values();
}
Also used : SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 9 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval 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 10 with ITmfStateInterval

use of org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval 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)

Aggregations

ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)155 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)78 Test (org.junit.Test)56 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)52 AttributeNotFoundException (org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException)43 TimeRangeException (org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException)41 ArrayList (java.util.ArrayList)37 NonNull (org.eclipse.jdt.annotation.NonNull)27 Nullable (org.eclipse.jdt.annotation.Nullable)20 HashMap (java.util.HashMap)19 IStateHistoryBackend (org.eclipse.tracecompass.statesystem.core.backend.IStateHistoryBackend)16 ITmfStateValue (org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)15 StateValueTypeException (org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException)14 TmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.TmfStateInterval)12 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)12 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)12 ImmutableList (com.google.common.collect.ImmutableList)11 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 ITmfStateSystemBuilder (org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder)11 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)11