use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class HistogramDataProvider method fetchTree.
@Override
public TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
if (fCached != null) {
return fCached;
}
fModule.waitForInitialization();
Builder<TmfTreeDataModel> builder = ImmutableList.builder();
builder.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(getTrace().getName())));
builder.add(new TmfTreeDataModel(fTotalId, fTraceId, Collections.singletonList(Objects.requireNonNull(Messages.HistogramDataProvider_Total))));
ITmfStateSystem eventsSs = Objects.requireNonNull(fModule.getStateSystem(TmfStatisticsEventTypesModule.ID));
if (eventsSs.optQuarkAbsolute(Attributes.LOST_EVENTS) != ITmfStateSystem.INVALID_ATTRIBUTE) {
builder.add(new TmfTreeDataModel(fLostId, fTraceId, Collections.singletonList(Objects.requireNonNull(Messages.HistogramDataProvider_Lost))));
}
if (eventsSs.waitUntilBuilt(0)) {
TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> response = new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), builder.build()), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
fCached = response;
return response;
}
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), builder.build()), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class TmfXyResponseFactory method create.
/**
* Create a {@link TmfModelResponse} for values with a common X axis values,
* with a either RUNNING or COMPLETED status. Model is not null, it's either
* partial or full.
*
* @param title
* Chart title
* @param xValues
* The x values requested by the viewer
* @param yModels
* Collection of IYModel
* @param isComplete
* Tells whether the computed model is complete or partial
* @return A {@link TmfModelResponse} with either a running status or a
* completed status
*/
public static TmfModelResponse<ITmfXyModel> create(String title, long[] xValues, Collection<IYModel> yModels, boolean isComplete) {
List<ISeriesModel> series = Lists.transform(new ArrayList<>(yModels), model -> {
SeriesModelBuilder builder = new SeriesModelBuilder(model.getId(), model.getName(), xValues, model.getData());
TmfXYAxisDescription yAxis = model.getYAxisDescription();
if (yAxis != null) {
builder.yAxisDescription(yAxis);
}
return builder.build();
});
ITmfXyModel model = new TmfXyModel(title, series);
if (isComplete) {
return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, Objects.requireNonNull(CommonStatusMessage.COMPLETED));
}
return new TmfModelResponse<>(model, ITmfResponse.Status.RUNNING, Objects.requireNonNull(CommonStatusMessage.RUNNING));
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class TmfTimeGraphCompositeDataProvider method fetchRowModel.
@Override
public TmfModelResponse<TimeGraphModel> fetchRowModel(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
boolean isComplete = true;
ImmutableList.Builder<ITimeGraphRowModel> series = ImmutableList.builder();
for (P dataProvider : getProviders()) {
TmfModelResponse<TimeGraphModel> response = dataProvider.fetchRowModel(fetchParameters, monitor);
isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
TimeGraphModel model = response.getModel();
if (model != null) {
series.addAll(model.getRows());
}
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
}
if (isComplete) {
return new TmfModelResponse<>(new TimeGraphModel(series.build()), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
return new TmfModelResponse<>(new TimeGraphModel(series.build()), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse 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();
}
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class TmfTreeCompositeDataProvider method fetchTree.
@Override
public TmfModelResponse<TmfTreeModel<M>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
boolean isComplete = true;
List<Entry<M, Object>> entries = new ArrayList<>();
List<ITableColumnDescriptor> columnDescriptor = null;
Table<Object, Long, @NonNull M> scopedEntries = HashBasedTable.create();
for (P dataProvider : fProviders) {
Map<Long, AtomicInteger> indexMap = new HashMap<>();
TmfModelResponse<TmfTreeModel<M>> response = dataProvider.fetchTree(fetchParameters, monitor);
isComplete &= response.getStatus() == ITmfResponse.Status.COMPLETED;
TmfTreeModel<M> model = response.getModel();
if (model != null) {
Object scope = (model.getScope() == null) ? dataProvider : model.getScope();
Map<Long, @NonNull M> row = scopedEntries.row(scope);
for (M entry : model.getEntries()) {
M previous = row.putIfAbsent(entry.getId(), entry);
// Ignore duplicate entries from different data providers
if (previous == null) {
if (entry.getParentId() == -1) {
entries.add(new SimpleEntry(entry, scope));
} else {
/*
* Insert new entries from subsequent data providers
* at the correct position in the entries list. New
* entries are inserted before sibling entries from
* previous data providers.
*/
int index = indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
int pos = 0;
while (pos < entries.size()) {
Entry<M, Object> added = entries.get(pos);
if (added.getValue().equals(scope) && added.getKey().getParentId() == entry.getParentId()) {
if (index == 0) {
break;
}
index--;
}
pos++;
}
if (pos < entries.size()) {
entries.add(pos, new SimpleEntry(entry, scope));
} else {
entries.add(new SimpleEntry(entry, scope));
}
}
} else {
indexMap.computeIfAbsent(entry.getParentId(), l -> new AtomicInteger()).getAndIncrement();
}
}
// Use the column descriptor of the first model. All descriptors are supposed to be the same
if (columnDescriptor == null) {
columnDescriptor = model.getColumnDescriptors();
}
}
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
}
TmfTreeModel.Builder<M> treeModelBuilder = new TmfTreeModel.Builder<>();
if (columnDescriptor == null) {
columnDescriptor = Collections.emptyList();
}
treeModelBuilder.setColumnDescriptors(columnDescriptor).setEntries(Lists.transform(entries, e -> e.getKey()));
if (isComplete) {
return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
return new TmfModelResponse<>(treeModelBuilder.build(), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
Aggregations