use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class TmfMipmapStateProviderTest method testQueryMipAvg.
/**
* Test a single query to the state system for an average
*
* Make sure the state system has data.
*
* Hint: the value read should always be more or less(t / 1000)
*/
@Test
public void testQueryMipAvg() {
assertNotNull(ssq);
try {
List<ITmfStateInterval> intervals = ssq.queryFullState(TEST_TIMESTAMP);
int mipmapQuark = ssq.getQuarkAbsolute(TEST_ATTRIBUTE_NAME, AbstractTmfMipmapStateProvider.AVG_STRING);
assertEquals("avg nblevels", NB_LEVELS, intervals.get(mipmapQuark).getStateValue().unboxInt());
for (int level = 1; level < NB_LEVELS; level++) {
long width = (long) Math.pow(RESOLUTION, level);
int levelQuark = ssq.getQuarkRelative(mipmapQuark, String.valueOf(level));
ITmfStateInterval interval = intervals.get(levelQuark);
double valueDouble = interval.getStateValue().unboxDouble();
assertEquals("avg value @ level " + level, 0.5 + (width / 2) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width, valueDouble, DELTA);
assertEquals("avg start time @ level " + level, START_TIME + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getStartTime());
assertEquals("avg end time @ level " + level, START_TIME + (INTERVAL * width) + (((TEST_TIMESTAMP - START_TIME) / INTERVAL) / width) * width * INTERVAL, interval.getEndTime() + 1);
}
} catch (TimeRangeException e) {
fail(e.getMessage());
} catch (StateSystemDisposedException e) {
fail(e.getMessage());
} catch (AttributeNotFoundException e) {
fail(e.getMessage());
} catch (StateValueTypeException e) {
fail(e.getMessage());
}
assertTrue(true);
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class CallsiteIterator method getCallsite.
@Nullable
private TimeCallsite getCallsite(@Nullable ITmfStateInterval fileInterval, @Nullable ITmfStateInterval lineInterval) {
ITmfStateSystem ss = fSS;
if (ss == null || fileInterval == null || lineInterval == null) {
return null;
}
try {
Object value = fileInterval.getValue();
if (value instanceof Integer) {
long fileId = (Integer) value + ss.getStartTime();
// Query line number
Object lineValue = lineInterval.getValue();
if (lineValue instanceof Integer) {
long line = (Integer) lineValue;
String fileName = fInterner.resolve(ss, fileId, fSourceQuark);
if (fileName != null) {
long time = Math.max(fileInterval.getStartTime(), lineInterval.getStartTime());
return new TimeCallsite(new TmfCallsite(fileName, line == -1 ? null : line), time);
}
}
}
} catch (StateSystemDisposedException e) {
// Skip
}
return null;
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class LostEventsOutputAnnotationProvider method fetchAnnotations.
@SuppressWarnings("null")
@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
IProgressMonitor progressMonitor = monitor;
if (progressMonitor == null) {
progressMonitor = new NullProgressMonitor();
}
ITmfStateSystem ss = getStateSystem();
if (ss == null) {
return NO_DATA;
}
int lostEventsQuark = getLostEventsQuark(ss);
if (lostEventsQuark == -1) {
return NO_DATA;
}
List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
@Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
if (timeRequested == null || timeRequested.size() < 2 || (categories != null && !categories.contains(LOST_EVENTS))) {
return NO_DATA;
}
if (timeRequested.equals(fLastRequest)) {
// $NON-NLS-1$
return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
}
fLastRequest = new ArrayList<>(timeRequested);
TreeMultimap<String, Annotation> markers = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(Annotation::getStartTime));
try {
long start = Math.max(timeRequested.get(0), ss.getStartTime());
long end = Math.min(timeRequested.get(timeRequested.size() - 1), ss.getCurrentEndTime());
if (start <= end) {
List<Long> times = new ArrayList<>(getTimes(ss, timeRequested));
/* Update start to ensure that the previous marker is included. */
start = Math.max(start - 1, ss.getStartTime());
/* Update end to ensure that the next marker is included. */
long nextStartTime = ss.querySingleState(end, lostEventsQuark).getEndTime() + 1;
end = Math.min(nextStartTime, ss.getCurrentEndTime());
times.set(0, start);
times.set(times.size() - 1, end);
for (ITmfStateInterval interval : ss.query2D(ImmutableList.of(lostEventsQuark), times)) {
if (progressMonitor.isCanceled()) {
fLastRequest = Collections.emptyList();
fLastAnnotationModel = new AnnotationModel(Collections.emptyMap());
// $NON-NLS-1$
return new TmfModelResponse<>(fLastAnnotationModel, Status.CANCELLED, "");
}
if (interval.getStateValue().isNull()) {
continue;
}
long lostEventsStartTime = interval.getStartTime();
/*
* The end time of the lost events range is the value of the
* attribute, not the end time of the interval.
*/
long lostEventsEndTime = interval.getStateValue().unboxLong();
long duration = lostEventsEndTime - lostEventsStartTime;
Map<String, Object> style = new HashMap<>();
style.put(StyleProperties.COLOR, COLOR);
style.put(StyleProperties.OPACITY, OPACITY);
markers.put(LOST_EVENTS, new Annotation(lostEventsStartTime, duration, -1, AnnotationType.CHART, null, new OutputElementStyle(LOST_EVENTS, style)));
}
}
} catch (StateSystemDisposedException e) {
/* ignored */
}
fLastAnnotationModel = new AnnotationModel(markers.asMap());
// $NON-NLS-1$
return new TmfModelResponse<>(fLastAnnotationModel, Status.COMPLETED, "");
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class HistogramDataProvider method fetchXY.
@Override
@NonNull
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
fModule.waitForInitialization();
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
long[] xValues = new long[0];
if (filter == null) {
return TmfXyResponseFactory.create(TITLE, xValues, Collections.emptyList(), true);
}
xValues = filter.getTimesRequested();
Collection<Long> selected = filter.getSelectedItems();
int n = xValues.length;
ImmutableList.Builder<IYModel> builder = ImmutableList.builder();
final ITmfStatistics stats = Objects.requireNonNull(fModule.getStatistics());
if (selected.contains(fTotalId)) {
List<Long> values = stats.histogramQuery(filter.getTimesRequested());
double[] y = new double[n];
Arrays.setAll(y, values::get);
String totalName = getTrace().getName() + '/' + Messages.HistogramDataProvider_Total;
builder.add(new YModel(fTotalId, totalName, y));
}
ITmfStateSystem eventsSs = fModule.getStateSystem(TmfStatisticsEventTypesModule.ID);
if (selected.contains(fLostId) && eventsSs != null) {
try {
YModel series = getLostEvents(eventsSs, xValues);
builder.add(series);
} catch (StateSystemDisposedException e) {
return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.STATE_SYSTEM_FAILED);
}
}
boolean completed = eventsSs != null ? eventsSs.waitUntilBuilt(0) || eventsSs.getCurrentEndTime() >= filter.getEnd() : false;
return TmfXyResponseFactory.create(TITLE, xValues, builder.build(), completed);
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException in project tracecompass by tracecompass.
the class AbstractTreeDataProvider method fetchTree.
@Override
public final TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
fLock.readLock().lock();
try {
if (fCached != null) {
/*
* If the tree depends on the filter, isCacheable should return false (by
* contract). If the tree is not cacheable, fCached will always be null, and we
* will never enter this block.
*/
return fCached;
}
} finally {
fLock.readLock().unlock();
}
fLock.writeLock().lock();
fAnalysisModule.waitForInitialization();
ITmfStateSystem ss = fAnalysisModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
boolean complete = ss.waitUntilBuilt(0);
try (FlowScopeLog scope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTreeDataProvider#fetchTree").setCategory(getClass().getSimpleName()).build()) {
TmfTreeModel<M> tree = null;
/* Don't query empty state system */
if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
tree = getTree(ss, fetchParameters, monitor);
for (M model : tree.getEntries()) {
if (model instanceof ICoreElementResolver) {
fEntryMetadata.put(model.getId(), ((ICoreElementResolver) model).getMetadata());
}
}
}
if (complete) {
TmfModelResponse<TmfTreeModel<M>> response = new TmfModelResponse<>(tree, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
if (isCacheable()) {
fCached = response;
}
return response;
}
return new TmfModelResponse<>(tree, ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
} catch (StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
} finally {
fLock.writeLock().unlock();
}
}
Aggregations