Search in sources :

Example 1 with IGroupingSegmentAspect

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);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) HashMap(java.util.HashMap) SeriesModelBuilder(org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder) Builder(com.google.common.collect.ImmutableList.Builder) ITmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) INamedSegment(org.eclipse.tracecompass.segmentstore.core.segment.interfaces.INamedSegment) IGroupingSegmentAspect(org.eclipse.tracecompass.analysis.timing.core.segmentstore.IGroupingSegmentAspect) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) AtomicLong(java.util.concurrent.atomic.AtomicLong) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) HashBiMap(com.google.common.collect.HashBiMap)

Aggregations

BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 Builder (com.google.common.collect.ImmutableList.Builder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IGroupingSegmentAspect (org.eclipse.tracecompass.analysis.timing.core.segmentstore.IGroupingSegmentAspect)1 ISegmentStoreProvider (org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider)1 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)1 INamedSegment (org.eclipse.tracecompass.segmentstore.core.segment.interfaces.INamedSegment)1 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)1 SeriesModelBuilder (org.eclipse.tracecompass.tmf.core.model.SeriesModel.SeriesModelBuilder)1 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 ITmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel)1 TmfTreeDataModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1