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;
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations