use of org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel 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.model.tree.TmfTreeDataModel in project tracecompass by tracecompass.
the class TmfFilteredXYChartViewer method handleCheckStateChangedEvent.
/**
* Update the chart depending on the selected entries.
*
* @param entries
* Counters to display on the chart
*/
@Override
public void handleCheckStateChangedEvent(Collection<ITmfTreeViewerEntry> entries) {
cancelUpdate();
Iterable<TmfGenericTreeEntry> counterEntries = Iterables.filter(entries, TmfGenericTreeEntry.class);
Collection<@NonNull Long> selectedIds = Sets.newHashSet(Iterables.transform(counterEntries, e -> e.getModel().getId()));
if (!selectedIds.containsAll(fSelectedIds)) {
clearContent();
}
fSelectedIds = selectedIds;
// Update the styles as well
BaseXYPresentationProvider presProvider = getPresentationProvider();
for (ITmfTreeViewerEntry entry : entries) {
if (entry instanceof TmfGenericTreeEntry) {
TmfGenericTreeEntry<TmfTreeDataModel> genericEntry = (TmfGenericTreeEntry<TmfTreeDataModel>) entry;
TmfTreeDataModel model = genericEntry.getModel();
OutputElementStyle style = model.getStyle();
if (style != null) {
presProvider.setStyle(model.getId(), style);
}
}
}
updateContent();
}
use of org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel in project tracecompass by tracecompass.
the class AbstractSegmentsStatisticsViewer method modelToTree.
/**
* Algorithm to convert a model (List of {@link SegmentStoreStatisticsModel}) to
* the tree.
*
* @param trace
* trace / experiment.
* @param model
* model to convert
* @return the resulting {@link TmfTreeViewerEntry}.
*/
@Nullable
private TmfTreeViewerEntry modelToTree(ITmfTrace trace, List<SegmentStoreStatisticsModel> model) {
TmfTreeViewerEntry root = getRoot(trace);
if (root == null) {
return null;
}
synchronized (root) {
root.getChildren().clear();
Map<Long, TmfTreeViewerEntry> map = new HashMap<>();
map.put(-1L, root);
for (TmfTreeDataModel entry : model) {
TmfTreeViewerEntry viewerEntry = new TmfGenericTreeEntry<>(entry);
map.put(entry.getId(), viewerEntry);
TmfTreeViewerEntry parent = map.get(entry.getParentId());
if (parent != null && !parent.getChildren().contains(viewerEntry)) {
parent.addChild(viewerEntry);
}
}
}
return root;
}
use of org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel in project tracecompass by tracecompass.
the class ExampleXYDataProvider method getTree.
@Override
protected TmfTreeModel<TmfTreeDataModel> getTree(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
// Make an entry for each base quark
List<TmfTreeDataModel> entryList = new ArrayList<>();
for (Integer quark : ss.getQuarks("CPUs", "*")) {
// $NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-1$
int statusQuark = ss.optQuarkRelative(quark, "Status");
if (statusQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
Long id = fIDToDisplayQuark.inverse().computeIfAbsent(statusQuark, q -> sfAtomicId.getAndIncrement());
entryList.add(new TmfTreeDataModel(id, -1, ss.getAttributeName(quark)));
}
}
return new TmfTreeModel<>(Collections.emptyList(), entryList);
}
use of org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel 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