use of org.eclipse.tracecompass.analysis.timing.core.segmentstore.IGroupingSegmentAspect 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);
}
Aggregations