Search in sources :

Example 21 with TimeRangeException

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

the class KernelThreadInformationProvider method getStatusIntervalsForThread.

/**
 * Get the status intervals for a given thread with a resolution
 *
 * @param module
 *            The kernel analysis instance to run this method on
 * @param threadId
 *            The ID of the thread to get the intervals for
 * @param start
 *            The start time of the requested range
 * @param end
 *            The end time of the requested range
 * @param resolution
 *            The resolution or the minimal time between the requested
 *            intervals. If interval times are smaller than resolution, only
 *            the first interval is returned, the others are ignored.
 * @param monitor
 *            A progress monitor for this task
 * @return The list of status intervals for this thread, an empty list is
 *         returned if either the state system is {@code null} or the quark
 *         is not found
 */
public static List<ITmfStateInterval> getStatusIntervalsForThread(KernelAnalysisModule module, Integer threadId, long start, long end, long resolution, IProgressMonitor monitor) {
    ITmfStateSystem ss = module.getStateSystem();
    if (ss == null) {
        return Collections.emptyList();
    }
    try {
        int threadQuark = ss.getQuarkAbsolute(Attributes.THREADS, threadId.toString());
        List<ITmfStateInterval> statusIntervals = StateSystemUtils.queryHistoryRange(ss, threadQuark, Math.max(start, ss.getStartTime()), Math.min(end - 1, ss.getCurrentEndTime()), resolution, monitor);
        return statusIntervals;
    } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
    // Do Nothing
    }
    return Collections.emptyList();
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)

Example 22 with TimeRangeException

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

the class KernelThreadInformationProvider method getThreadOnCpu.

/**
 * Get the ID of the thread running on the CPU at time ts
 *
 * TODO: This method may later be replaced by an aspect, when the aspect can
 * resolve to something that is not an event
 *
 * @param module
 *            The kernel analysis instance to run this method on
 * @param cpuId
 *            The CPU number the process is running on
 * @param ts
 *            The timestamp at which we want the running process
 * @return The TID of the thread running on CPU cpuId at time ts or
 *         {@code null} if either no thread is running or we do not know.
 */
@Nullable
public static Integer getThreadOnCpu(KernelAnalysisModule module, long cpuId, long ts) {
    ITmfStateSystem ss = module.getStateSystem();
    if (ss == null) {
        return null;
    }
    try {
        int cpuQuark = ss.getQuarkAbsolute(Attributes.CPUS, Long.toString(cpuId), Attributes.CURRENT_THREAD);
        ITmfStateInterval interval = ss.querySingleState(ts, cpuQuark);
        ITmfStateValue val = interval.getStateValue();
        if (val.getType().equals(Type.INTEGER)) {
            return val.unboxInt();
        }
    } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
    }
    return null;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 23 with TimeRangeException

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

the class KernelThreadInformationProvider method getParentPid.

/**
 * Get the parent process ID of a thread
 *
 * @param module
 *            The kernel analysis instance to run this method on
 * @param threadId
 *            The thread ID of the process for which to get the parent
 * @param ts
 *            The timestamp at which to get the parent
 * @return The parent PID or {@code null} if the PPID is not found.
 */
@Nullable
public static Integer getParentPid(KernelAnalysisModule module, Integer threadId, long ts) {
    ITmfStateSystem ss = module.getStateSystem();
    if (ss == null) {
        return null;
    }
    Integer ppidNode;
    try {
        ppidNode = ss.getQuarkAbsolute(Attributes.THREADS, threadId.toString(), Attributes.PPID);
        ITmfStateInterval ppidInterval = ss.querySingleState(ts, ppidNode);
        ITmfStateValue ppidValue = ppidInterval.getStateValue();
        if (ppidValue.getType().equals(Type.INTEGER)) {
            return Integer.valueOf(ppidValue.unboxInt());
        }
    } catch (AttributeNotFoundException | StateSystemDisposedException | TimeRangeException e) {
    }
    return null;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) AttributeNotFoundException(org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 24 with TimeRangeException

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

the class TidAnalysisModule method getThreadOnCpuAtTime.

/**
 * Gets the current thread ID on a given CPU for a given time
 *
 * @param cpu
 *            the CPU
 * @param time
 *            the time in nanoseconds
 * @return the current TID at the time on the CPU or {@code null} if not
 *         known
 */
@Nullable
public Integer getThreadOnCpuAtTime(int cpu, long time) {
    ITmfStateSystem stateSystem = getStateSystem();
    if (stateSystem == null || time < stateSystem.getStartTime()) {
        return null;
    }
    Integer tid = null;
    // Query at time - 1, because at the boundary (sched_switches), the "thread on
    // CPU" should be the previous thread, not the next one (as LTTng contexts and
    // perf traces show).
    long queryTime = Math.max(time - 1, stateSystem.getStartTime());
    try {
        int cpuQuark = stateSystem.optQuarkAbsolute(Integer.toString(cpu));
        if (cpuQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
            return null;
        }
        ITmfStateInterval state = fCache.get(cpuQuark);
        if (state == null || !state.intersects(queryTime)) {
            state = stateSystem.querySingleState(queryTime, cpuQuark);
            fCache.put(cpuQuark, state);
        }
        Object value = state.getValue();
        if (value instanceof Integer) {
            tid = (Integer) value;
        }
    } catch (StateSystemDisposedException | TimeRangeException e) {
        Activator.getDefault().logError(NonNullUtils.nullToEmptyString(e.getMessage()), e);
    }
    return tid;
}
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) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 25 with TimeRangeException

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

the class IOStateSystemSegmentStore method getIntersectingElements.

@Override
@NonNull
public Iterable<@NonNull ISegment> getIntersectingElements(long start, long end) {
    long startTime = Math.max(start, fStateSystem.getStartTime());
    long endTime = Math.min(end, fStateSystem.getCurrentEndTime());
    if (startTime > endTime) {
        return Collections.emptySet();
    }
    List<@NonNull ISegment> segments = new ArrayList<>();
    try {
        for (ITmfStateInterval interval : fStateSystem.query2D(fSegmentQuarks.keySet(), startTime, endTime)) {
            RequestIntervalSegment segment = RequestIntervalSegment.create(interval, fSegmentQuarks.get(interval.getAttribute()));
            if (segment != null) {
                segments.add(segment);
            }
        }
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e1) {
    // Nothing to do
    }
    return segments;
}
Also used : StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) NonNull(org.eclipse.jdt.annotation.NonNull)

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