use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method fetchTree.
@Override
@NonNull
public TmfModelResponse<@NonNull TmfTreeModel<@NonNull TimeGraphEntryModel>> fetchTree(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
if (fLastEnd == Long.MAX_VALUE) {
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), filter(Objects.requireNonNull(fTraceEntry), fTidToEntry, fetchParameters)), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
fModule.waitForInitialization();
ITmfStateSystem ss = fModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
/*
* As we are caching the intermediate result, we only want a single thread to
* update them.
*/
synchronized (fBuildMap) {
boolean complete = ss.waitUntilBuilt(0);
@NonNull List<@NonNull TimeGraphEntryModel> list = Collections.emptyList();
/* Don't query empty state system */
if (ss.getNbAttributes() > 0 && ss.getStartTime() != Long.MIN_VALUE) {
long end = ss.getCurrentEndTime();
fLastEnd = Long.max(fLastEnd, ss.getStartTime());
TreeMultimap<Integer, ITmfStateInterval> threadData = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(ITmfStateInterval::getStartTime));
/*
* Create a List with the threads' PPID and EXEC_NAME quarks for the 2D query .
*/
List<Integer> quarks = new ArrayList<>(ss.getQuarks(Attributes.THREADS, WILDCARD, Attributes.EXEC_NAME));
quarks.addAll(ss.getQuarks(Attributes.THREADS, WILDCARD, Attributes.PPID));
quarks.addAll(ss.getQuarks(Attributes.THREADS, WILDCARD, Attributes.PID));
try {
for (ITmfStateInterval interval : ss.query2D(quarks, Long.min(fLastEnd, end), end)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
threadData.put(interval.getAttribute(), interval);
}
} catch (TimeRangeException | StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, e.getClass().getName() + ':' + String.valueOf(e.getMessage()));
}
// update the trace Entry.
TimeGraphEntryModel traceEntry = new TimeGraphEntryModel(fTraceId, -1, getTrace().getName(), ss.getStartTime(), end);
fTraceEntry = traceEntry;
for (Integer threadQuark : ss.getQuarks(Attributes.THREADS, WILDCARD)) {
String threadAttributeName = ss.getAttributeName(threadQuark);
Pair<Integer, Integer> entryKey = Attributes.parseThreadAttributeName(threadAttributeName);
int threadId = entryKey.getFirst();
if (threadId < 0) {
// ignore the 'unknown' (-1) thread
continue;
}
int execNameQuark = ss.optQuarkRelative(threadQuark, Attributes.EXEC_NAME);
int ppidQuark = ss.optQuarkRelative(threadQuark, Attributes.PPID);
int pidQuark = ss.optQuarkRelative(threadQuark, Attributes.PID);
NavigableSet<ITmfStateInterval> ppidIntervals = threadData.get(ppidQuark);
NavigableSet<ITmfStateInterval> pidIntervals = threadData.get(pidQuark);
for (ITmfStateInterval execNameInterval : threadData.get(execNameQuark)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
updateEntry(threadQuark, entryKey, ppidIntervals, execNameInterval, pidIntervals);
}
}
fLastEnd = end;
list = filter(traceEntry, fTidToEntry, fetchParameters);
}
for (TimeGraphEntryModel model : list) {
fEntryMetadata.put(model.getId(), model.getMetadata());
}
if (complete) {
fBuildMap.clear();
fLastEnd = Long.MAX_VALUE;
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
return new TmfModelResponse<>(new TmfTreeModel<>(Collections.emptyList(), list), ITmfResponse.Status.RUNNING, CommonStatusMessage.RUNNING);
}
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method fetchRowModel.
@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, IProgressMonitor monitor) {
ITmfStateSystem ss = fModule.getStateSystem();
if (ss == null) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
TreeMultimap<Integer, ITmfStateInterval> intervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(ITmfStateInterval::getStartTime));
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
Map<Long, Integer> selectedIdsToQuarks = getSelectedIdsToQuarks(filter);
Collection<Integer> stateAndSyscallQuarks = addSyscall(selectedIdsToQuarks.values(), ss);
Collection<Long> times = getTimes(ss, filter);
try {
/* Do the actual query */
for (ITmfStateInterval interval : ss.query2D(stateAndSyscallQuarks, times)) {
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
intervals.put(interval.getAttribute(), interval);
}
} catch (TimeRangeException | StateSystemDisposedException e) {
return new TmfModelResponse<>(null, ITmfResponse.Status.FAILED, String.valueOf(e.getMessage()));
}
Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(fetchParameters);
if (regexesMap != null) {
predicates.putAll(computeRegexPredicate(regexesMap));
}
@NonNull List<@NonNull ITimeGraphRowModel> rows = new ArrayList<>();
for (Entry<Long, Integer> entry : selectedIdsToQuarks.entrySet()) {
int quark = entry.getValue();
NavigableSet<ITmfStateInterval> states = intervals.get(quark);
NavigableSet<ITmfStateInterval> syscalls = intervals.get(ss.optQuarkRelative(quark, Attributes.SYSTEM_CALL));
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, ITmfResponse.Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
List<ITimeGraphState> eventList = new ArrayList<>();
states.forEach(i -> {
ITimeGraphState timegraphState = createTimeGraphState(i, syscalls);
Long key = Objects.requireNonNull(entry.getKey());
applyFilterAndAddState(eventList, timegraphState, key, predicates, monitor);
});
rows.add(new TimeGraphRowModel(entry.getKey(), eventList));
}
return new TmfModelResponse<>(new TimeGraphModel(rows), ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class CallStackDataProvider method fetchTooltip.
@Override
@NonNull
public TmfModelResponse<@NonNull Map<@NonNull String, @NonNull String>> fetchTooltip(Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
CallStackAnalysis analysis = getAnalysisModule();
Map<String, String> tooltips = new HashMap<>();
List<@NonNull Long> selected = DataProviderParameterUtils.extractSelectedItems(parameters);
List<@NonNull Long> times = DataProviderParameterUtils.extractTimeRequested(parameters);
// This data provider doesn't have any annotations or arrows
Object element = parameters.get(DataProviderParameterUtils.REQUESTED_ELEMENT_KEY);
if (element instanceof IAnnotation || element instanceof ITimeGraphArrow) {
return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
if (selected != null && times != null) {
Map<@NonNull Long, @NonNull Integer> md = getSelectedEntries(selected);
ITmfTrace trace = getTrace();
for (Long time : times) {
for (Entry<@NonNull Long, @NonNull Integer> entry : md.entrySet()) {
Long result = analysis.resolveDeviceId(entry.getValue(), time);
if (result != null) {
String deviceId = String.valueOf(result);
String deviceType = analysis.resolveDeviceType(entry.getValue(), time);
tooltips.put(deviceType, deviceId);
Iterable<@NonNull CallsiteAnalysis> csas = TmfTraceUtils.getAnalysisModulesOfClass(trace, CallsiteAnalysis.class);
for (CallsiteAnalysis csa : csas) {
List<@NonNull ITmfCallsite> res = csa.getCallsites(String.valueOf(trace.getUUID()), deviceType, deviceId, time);
if (!res.isEmpty()) {
tooltips.put(TmfStrings.source(), String.valueOf(res.get(0)));
}
}
return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
ITmfStateSystem stateSystem = analysis.getStateSystem();
if (stateSystem != null) {
try {
Collection<@NonNull ISymbolProvider> symbolProviders = SymbolProviderManager.getInstance().getSymbolProviders(trace);
ITmfStateInterval interval = stateSystem.querySingleState(Objects.requireNonNull(time), Objects.requireNonNull(entry.getValue()));
Object value = interval.getValue();
if (value instanceof Number) {
long longValue = ((Number) value).longValue();
for (ISymbolProvider provider : symbolProviders) {
TmfResolvedSymbol symbol = provider.getSymbol(longValue);
if (symbol != null) {
tooltips.put(Messages.CallStackDataProvider_toolTipState, symbol.getSymbolName());
tooltips.put(Messages.CallStackDataProvider_toolTipAddress, String.format(ADDRESS_FORMAT, symbol.getBaseAddress()));
break;
}
}
tooltips.computeIfAbsent(Messages.CallStackDataProvider_toolTipState, unused -> String.format(ADDRESS_FORMAT, longValue));
} else if (value != null) {
tooltips.put(Messages.CallStackDataProvider_toolTipState, interval.getValueString());
}
} catch (StateSystemDisposedException e) {
// $NON-NLS-1$
Activator.getInstance().logError("State System Disposed", e);
}
}
}
}
}
return new TmfModelResponse<>(tooltips, ITmfResponse.Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class FlameChartView method getPreviousEventAction.
/**
* Get the previous event action.
*
* @return The Action object
*/
private Action getPreviousEventAction() {
Action prevAction = fPrevEventAction;
if (prevAction == null) {
Action superPrevAction = getTimeGraphViewer().getPreviousEventAction();
prevAction = new Action() {
@Override
public void run() {
TimeGraphViewer viewer = getTimeGraphViewer();
ITimeGraphEntry entry = viewer.getSelection();
if (entry instanceof TimeGraphEntry) {
TimeGraphEntry callStackEntry = (TimeGraphEntry) entry;
ITimeGraphDataProvider<? extends TimeGraphEntryModel> provider = getProvider(callStackEntry);
long selectionBegin = viewer.getSelectionBegin();
SelectionTimeQueryFilter filter = new SelectionTimeQueryFilter(Lists.newArrayList(Long.MIN_VALUE, selectionBegin), Collections.singleton(callStackEntry.getEntryModel().getId()));
TmfModelResponse<@NonNull TimeGraphModel> response = provider.fetchRowModel(FetchParametersUtils.selectionTimeQueryToMap(filter), null);
TimeGraphModel model = response.getModel();
if (model == null || model.getRows().size() != 1) {
return;
}
List<@NonNull ITimeGraphState> row = model.getRows().get(0).getStates();
if (row.size() != 1) {
return;
}
ITimeGraphState stackInterval = row.get(0);
viewer.setSelectedTimeNotify(stackInterval.getStartTime(), true);
int stackLevel = stackInterval.getValue();
ITimeGraphEntry selectedEntry = callStackEntry.getParent().getChildren().get(Integer.max(0, stackLevel - 1));
viewer.setSelection(selectedEntry, true);
viewer.getTimeGraphControl().fireSelectionChanged();
startZoomThread(viewer.getTime0(), viewer.getTime1());
}
}
};
prevAction.setText(superPrevAction.getText());
prevAction.setToolTipText(superPrevAction.getToolTipText());
prevAction.setImageDescriptor(superPrevAction.getImageDescriptor());
fPrevEventAction = prevAction;
}
return prevAction;
}
use of org.eclipse.tracecompass.tmf.core.response.TmfModelResponse in project tracecompass by tracecompass.
the class SegmentStoreStatisticsDataProvider method fetchTree.
@Override
public TmfModelResponse<TmfTreeModel<SegmentStoreStatisticsModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
IAnalysisModule module = fModule;
if (module != null) {
if (monitor != null) {
module.waitForCompletion(monitor);
if (monitor.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
} else {
module.waitForCompletion();
}
}
IStatistics<ISegment> statsTotal = fProvider.getStatsTotal();
if (statsTotal == null) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
}
List<SegmentStoreStatisticsModel> list = new ArrayList<>();
String rootName = getRootEntryName();
if (rootName == null) {
rootName = getTrace().getName();
}
list.add(new SegmentStoreStatisticsModel(fTraceId, -1, getCellLabels(NonNullUtils.nullToEmptyString(rootName), statsTotal), statsTotal));
/*
* Add statistics for full duration.
*/
long totalId = getUniqueId(TOTAL_PREFIX);
list.add(new SegmentStoreStatisticsModel(totalId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Total), statsTotal), statsTotal));
Map<String, IStatistics<ISegment>> totalStats = fProvider.getStatsPerType();
for (Entry<String, IStatistics<ISegment>> entry : totalStats.entrySet()) {
IStatistics<ISegment> statistics = entry.getValue();
list.add(new SegmentStoreStatisticsModel(getUniqueId(TOTAL_PREFIX + entry.getKey()), totalId, getCellLabels(entry.getKey(), statistics), statistics));
}
/*
* Add statistics for selection if any.
*/
TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(fetchParameters);
if (filter != null && isFiltered != null && isFiltered) {
long start = filter.getStart();
long end = filter.getEnd();
IProgressMonitor nonNullMonitor = monitor != null ? monitor : new NullProgressMonitor();
IStatistics<ISegment> statsForRange = fProvider.getStatsForRange(start, end, nonNullMonitor);
if (statsForRange == null) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
long selectionId = getUniqueId(SELECTION_PREFIX);
if (statsForRange.getNbElements() > 0) {
list.add(new SegmentStoreStatisticsModel(selectionId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Selection), statsForRange), statsForRange));
Map<String, IStatistics<ISegment>> selectionStats = fProvider.getStatsPerTypeForRange(start, end, nonNullMonitor);
for (Entry<String, IStatistics<ISegment>> entry : selectionStats.entrySet()) {
IStatistics<ISegment> statistics = entry.getValue();
list.add(new SegmentStoreStatisticsModel(getUniqueId(SELECTION_PREFIX + entry.getKey()), selectionId, getCellLabels(entry.getKey(), statistics), statistics));
}
}
}
TmfTreeModel.Builder<SegmentStoreStatisticsModel> treeModelBuilder = new TmfTreeModel.Builder();
treeModelBuilder.setColumnDescriptors(getColumnDescriptors());
treeModelBuilder.setEntries(Collections.unmodifiableList(list));
return new TmfModelResponse<>(treeModelBuilder.build(), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Aggregations