Search in sources :

Example 6 with TimeRangeException

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

the class StateSystemUtils method queryHistoryRange.

/**
 * Return the state history of a given attribute, but with at most one
 * update per "resolution". This can be useful for populating views (where
 * it's useless to have more than one query per pixel, for example). A
 * progress monitor can be used to cancel the query before completion.
 *
 * @param ss
 *            The state system to query
 * @param attributeQuark
 *            Which attribute this query is interested in
 * @param t1
 *            Start time of the range query
 * @param t2
 *            Target end time of the query. If t2 is greater than the end of
 *            the trace, we will return what we have up to the end of the
 *            history.
 * @param resolution
 *            The "step" of this query
 * @param monitor
 *            A progress monitor. If the monitor is canceled during a query,
 *            we will return what has been found up to that point. You can
 *            use "null" if you do not want to use one.
 * @return The List of states that happened between t1 and t2
 * @throws TimeRangeException
 *             If t1 is invalid, if t2 {@literal <=} t1, or if the
 *             resolution isn't greater than zero.
 * @throws AttributeNotFoundException
 *             If the attribute doesn't exist
 * @throws StateSystemDisposedException
 *             If the query is sent after the state system has been disposed
 */
public static List<ITmfStateInterval> queryHistoryRange(ITmfStateSystem ss, int attributeQuark, long t1, long t2, long resolution, @Nullable IProgressMonitor monitor) throws AttributeNotFoundException, StateSystemDisposedException {
    List<ITmfStateInterval> intervals = new LinkedList<>();
    ITmfStateInterval currentInterval = null;
    long ts, tEnd;
    /* Make sure the time range makes sense */
    if (t2 < t1 || resolution <= 0) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        throw new TimeRangeException(ss.getSSID() + " Start:" + t1 + ", End:" + t2 + ", Resolution:" + resolution);
    }
    /* Set the actual, valid end time of the range query */
    if (t2 > ss.getCurrentEndTime()) {
        tEnd = ss.getCurrentEndTime();
    } else {
        tEnd = t2;
    }
    IProgressMonitor mon = monitor;
    if (mon == null) {
        mon = new NullProgressMonitor();
    }
    /*
         * Iterate over the "resolution points". We skip unneeded queries in the
         * case the current interval is longer than the resolution.
         */
    for (ts = t1; ts <= tEnd; ts += ((currentInterval.getEndTime() - ts) / resolution + 1) * resolution) {
        if (mon.isCanceled()) {
            return intervals;
        }
        currentInterval = ss.querySingleState(ts, attributeQuark);
        intervals.add(currentInterval);
    }
    /* Add the interval at t2, if it wasn't included already. */
    if (currentInterval != null && currentInterval.getEndTime() < tEnd) {
        currentInterval = ss.querySingleState(tEnd, attributeQuark);
        intervals.add(currentInterval);
    }
    return intervals;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) LinkedList(java.util.LinkedList)

Example 7 with TimeRangeException

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

the class StateSystemUtils method queryHistoryRange.

/**
 * Return a list of state intervals, containing the "history" of a given
 * attribute between timestamps t1 and t2. The list will be ordered by
 * ascending time.
 * <p>
 * Note that contrary to queryFullState(), the returned list here is in the
 * "direction" of time (and not in the direction of attributes, as is the
 * case with queryFullState()).
 * </p>
 *
 * @param ss
 *            The state system to query
 * @param attributeQuark
 *            Which attribute this query is interested in
 * @param t1
 *            Start time of the range query
 * @param t2
 *            Target end time of the query. If t2 is greater than the end of
 *            the trace, we will return what we have up to the end of the
 *            history.
 * @return The List of state intervals that happened between t1 and t2
 * @throws TimeRangeException
 *             If t1 is invalid, or if t2 {@literal <=} t1
 * @throws AttributeNotFoundException
 *             If the requested quark does not exist in the model.
 * @throws StateSystemDisposedException
 *             If the query is sent after the state system has been disposed
 */
public static List<ITmfStateInterval> queryHistoryRange(ITmfStateSystem ss, int attributeQuark, long t1, long t2) throws AttributeNotFoundException, StateSystemDisposedException {
    List<ITmfStateInterval> intervals;
    ITmfStateInterval currentInterval;
    long ts, tEnd;
    /* Make sure the time range makes sense */
    if (t2 < t1) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TimeRangeException(ss.getSSID() + " Start:" + t1 + ", End:" + t2);
    }
    /* Set the actual, valid end time of the range query */
    if (t2 > ss.getCurrentEndTime()) {
        tEnd = ss.getCurrentEndTime();
    } else {
        tEnd = t2;
    }
    /* Get the initial state at time T1 */
    intervals = new ArrayList<>();
    currentInterval = ss.querySingleState(t1, attributeQuark);
    intervals.add(currentInterval);
    /* Get the following state changes */
    ts = currentInterval.getEndTime();
    while (ts != -1 && ts < tEnd) {
        ts++;
        /* To "jump over" to the next state in the history */
        currentInterval = ss.querySingleState(ts, attributeQuark);
        intervals.add(currentInterval);
        ts = currentInterval.getEndTime();
    }
    return intervals;
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 8 with TimeRangeException

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

the class XmlTimeGraphDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
    // TODO server: Parameters validation should be handle separately. It
    // can be either in the data provider itself or before calling it. It
    // will avoid the creation of filters and the content of the map can be
    // use directly.
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    for (Long id : filter.getSelectedItems()) {
        Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
        if (pair != null) {
            table.put(pair.getFirst(), pair.getSecond(), id);
        }
    }
    List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
    try {
        for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
            Collection<@NonNull ITimeGraphRowModel> rows = createRows(ssEntry.getKey(), ssEntry.getValue(), filter.getTimesRequested(), fetchParameters, monitor);
            allRows.addAll(rows);
        }
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) Map(java.util.Map) HashMap(java.util.HashMap) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 9 with TimeRangeException

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

the class DataDrivenTimeGraphDataProvider method fetchRowModel.

@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    // TODO server: Parameters validation should be handle separately. It
    // can be either in the data provider itself or before calling it. It
    // will avoid the creation of filters and the content of the map can be
    // use directly.
    SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
    if (filter == null) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
    }
    Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
    for (Long id : filter.getSelectedItems()) {
        Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
        if (pair != null) {
            table.put(pair.getFirst(), pair.getSecond(), id);
        }
    }
    List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
    try {
        for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
            Collection<@NonNull ITimeGraphRowModel> rows = createRows(ssEntry.getKey(), ssEntry.getValue(), fetchParameters, monitor);
            allRows.addAll(rows);
        }
    } catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
    }
    return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) TimeGraphModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphModel) ArrayList(java.util.ArrayList) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) StateSystemDisposedException(org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException) ITimeGraphRowModel(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphRowModel) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashMap(java.util.HashMap) Map(java.util.Map) ITmfStateSystem(org.eclipse.tracecompass.statesystem.core.ITmfStateSystem) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 10 with TimeRangeException

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

the class TmfMipmapStateProviderStub method eventHandle.

@Override
protected void eventHandle(ITmfEvent ev) {
    ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
    final long ts = ev.getTimestamp().toNanos();
    try {
        int quark = ss.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME);
        ITmfStateValue value = (ITmfStateValue) ev.getContent().getValue();
        modifyMipmapAttribute(ts, value, quark, MIN | MAX | AVG, resolution);
    } catch (TimeRangeException e) {
        Activator.logError(ERROR_INVALID_TIMESTAMP, e);
    } catch (StateValueTypeException e) {
        Activator.logError(ERROR_INVALID_STATE_VALUE, e);
    }
}
Also used : TimeRangeException(org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException) ITmfStateSystemBuilder(org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder) StateValueTypeException(org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException) ITmfStateValue(org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue)

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