use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class SegmentStoreScatterDataProvider method fetchTree.
/**
* @since 4.0
*/
@Override
public TmfModelResponse<TmfTreeModel<TmfTreeDataModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
ISegmentStoreProvider provider = fProvider;
if (provider instanceof IAnalysisModule) {
IAnalysisModule module = (IAnalysisModule) provider;
IProgressMonitor mon = monitor != null ? monitor : new NullProgressMonitor();
module.waitForCompletion(mon);
if (mon.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
}
ISegmentStore<ISegment> segStore = provider.getSegmentStore();
if (segStore == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
if (filter == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
long start = filter.getStart();
long end = filter.getEnd();
final Iterable<ISegment> intersectingElements = Iterables.filter(segStore.getIntersectingElements(start, end), s -> s.getStart() >= start);
Map<String, INamedSegment> segmentTypes = new HashMap<>();
IAnalysisModule module = (provider instanceof IAnalysisModule) ? (IAnalysisModule) provider : null;
boolean complete = module == null ? true : module.isQueryable(filter.getEnd());
// Create the list of segment types that will each create a series
for (INamedSegment segment : Iterables.filter(intersectingElements, INamedSegment.class)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
segmentTypes.put(segment.getName(), segment);
}
Builder<TmfTreeDataModel> nodes = new ImmutableList.Builder<>();
nodes.add(new TmfTreeDataModel(fTraceId, -1, Collections.singletonList(String.valueOf(getTrace().getName()))));
Map<IGroupingSegmentAspect, Map<String, Long>> names = new HashMap<>();
for (Entry<String, INamedSegment> series : segmentTypes.entrySet()) {
long parentId = fTraceId;
/*
* Create a tree sorting aspects by "Grouping aspect" much like
* counter analyses
*/
for (IGroupingSegmentAspect aspect : fGroupingAspects) {
names.putIfAbsent(aspect, new HashMap<>());
Map<String, Long> map = names.get(aspect);
if (map == null) {
break;
}
String name = String.valueOf(aspect.resolve(series.getValue()));
String key = GROUP_PREFIX + name;
Long uniqueId = map.get(key);
if (uniqueId == null) {
uniqueId = getUniqueId(key);
map.put(key, uniqueId);
nodes.add(new TmfTreeDataModel(uniqueId, parentId, name));
}
parentId = uniqueId;
}
long seriesId = getUniqueId(series.getKey());
nodes.add(new TmfTreeDataModel(seriesId, parentId, series.getKey()));
}
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), nodes.build()), complete ? ITmfResponse.Status.COMPLETED : ITmfResponse.Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class AbstractTimeGraphDataProvider method fetchRowModel.
@Override
public final TmfModelResponse<TimeGraphModel> fetchRowModel(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
A module = getAnalysisModule();
if (!module.waitForInitialization()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
ITmfStateSystem ss = module.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
long currentEnd = ss.getCurrentEndTime();
Object times = parameters.get(DataProviderParameterUtils.REQUESTED_TIME_KEY);
Object items = parameters.get(DataProviderParameterUtils.REQUESTED_ITEMS_KEY);
if (!(times instanceof List<?>) || ((List<?>) times).isEmpty() || !(items instanceof Collection<?>)) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
Object end = Iterables.getLast(((List<?>) times));
if (!(end instanceof Number)) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
boolean complete = ss.waitUntilBuilt(0) || ((Number) end).longValue() <= currentEnd;
try (FlowScopeLog scope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, "AbstractTimeGraphDataProvider#fetchRowModel").setCategory(getClass().getSimpleName()).build()) {
TimeGraphModel models = getRowModel(ss, parameters, monitor);
if (models == null) {
// getRowModel returns null if the query was cancelled.
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
return new TmfModelResponse<>(models, complete ? Status.COMPLETED : Status.RUNNING, complete ? CommonStatusMessage.COMPLETED : CommonStatusMessage.RUNNING);
} catch (StateSystemDisposedException | TimeRangeException | IndexOutOfBoundsException e) {
return new TmfModelResponse<>(null, Status.FAILED, String.valueOf(e.getMessage()));
}
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class TmfTimeGraphCompositeDataProvider method fetchStyle.
@Override
public TmfModelResponse<OutputStyleModel> fetchStyle(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
Map<String, OutputElementStyle> styles = new HashMap<>();
for (P dataProvider : getProviders()) {
if (dataProvider instanceof IOutputStyleProvider) {
TmfModelResponse<OutputStyleModel> response = ((IOutputStyleProvider) dataProvider).fetchStyle(fetchParameters, monitor);
OutputStyleModel model = response.getModel();
if (model != null) {
styles.putAll(model.getStyles());
}
}
}
if (styles.isEmpty()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
return new TmfModelResponse<>(new OutputStyleModel(styles), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class CustomOutputAnnotationProvider method fetchAnnotations.
@Override
public TmfModelResponse<AnnotationModel> fetchAnnotations(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
Object markerID = fetchParameters.get(DataProviderParameterUtils.REQUESTED_MARKER_SET_KEY);
Object hostID = fetchParameters.get(DataProviderParameterUtils.REQUESTED_TRACE_KEY);
Optional<ITmfTrace> requestedTrace = getTrace(hostID);
/*
* Ignore if trace is not the requested trace, or if no requested trace,
* if the trace is not the first element of its trace set.
*/
if ((requestedTrace.isPresent() && !requestedTrace.get().equals(fTrace)) || (!requestedTrace.isPresent() && !isFirstTrace())) {
// $NON-NLS-1$
return new TmfModelResponse<>(null, Status.COMPLETED, "");
}
if (markerID == null) {
return new TmfModelResponse<>(null, Status.FAILED, NO_MARKER_ID);
}
MarkerSet ms = getMarkerSet(markerID);
if (ms == null) {
return new TmfModelResponse<>(null, Status.FAILED, formatError(markerID));
}
return getAnnotationProvider(requestedTrace.isPresent() ? requestedTrace.get() : null, ms).fetchAnnotations(fetchParameters, monitor);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class TmfTreeCompositeDataProvider method fetchAnnotationCategories.
@Override
public TmfModelResponse<AnnotationCategoriesModel> fetchAnnotationCategories(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
AnnotationCategoriesModel model = new AnnotationCategoriesModel(Collections.emptyList());
for (P dataProvider : getProviders()) {
if (dataProvider instanceof IOutputAnnotationProvider) {
TmfModelResponse<AnnotationCategoriesModel> response = ((IOutputAnnotationProvider) dataProvider).fetchAnnotationCategories(fetchParameters, monitor);
model = AnnotationCategoriesModel.of(model, response.getModel());
}
}
if (model.getAnnotationCategories().isEmpty()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
return new TmfModelResponse<>(model, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Aggregations