use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ResourcesStatusDataProvider method getRowModel.
@Override
public TimeGraphModel getRowModel(ITmfStateSystem ss, @NonNull Map<@NonNull String, @NonNull Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
TreeMultimap<Integer, ITmfStateInterval> intervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparing(ITmfStateInterval::getStartTime));
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(parameters);
if (filter == null) {
return null;
}
Map<@NonNull Long, @NonNull Integer> idsToQuark = getSelectedEntries(filter);
/* Add the mapping for twin entries as they are not in the parent class BiMap */
addTwinIrqIds(filter, idsToQuark);
Collection<Long> times = getTimes(filter, ss.getStartTime(), ss.getCurrentEndTime());
/* Do the actual query */
Collection<@NonNull Integer> quarks = addThreadStatus(ss, idsToQuark.values());
for (ITmfStateInterval interval : ss.query2D(quarks, times)) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
intervals.put(interval.getAttribute(), interval);
}
Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = new HashMap<>();
Multimap<@NonNull Integer, @NonNull String> regexesMap = DataProviderParameterUtils.extractRegexFilter(parameters);
if (regexesMap != null) {
predicates.putAll(computeRegexPredicate(regexesMap));
}
@NonNull List<@NonNull ITimeGraphRowModel> rows = new ArrayList<>();
for (Map.Entry<Long, Integer> idToQuark : idsToQuark.entrySet()) {
if (monitor != null && monitor.isCanceled()) {
return null;
}
Long key = Objects.requireNonNull(idToQuark.getKey());
List<ITimeGraphState> eventList = new ArrayList<>();
for (ITmfStateInterval interval : intervals.get(idToQuark.getValue())) {
long startTime = interval.getStartTime();
long duration = interval.getEndTime() - startTime + 1;
Object status = interval.getValue();
Type type = fEntryModelTypes.get(interval.getAttribute());
if (status instanceof Integer) {
int s = (int) status;
int currentThreadQuark = ss.optQuarkRelative(interval.getAttribute(), Attributes.CURRENT_THREAD);
if (type == Type.CPU && s == StateValues.CPU_STATUS_RUN_SYSCALL) {
// add events for all the sampled current threads.
List<@NonNull ITimeGraphState> syscalls = getSyscalls(ss, interval, intervals.get(currentThreadQuark));
syscalls.forEach(timeGraphState -> applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor));
} else if (type == Type.CPU && s == StateValues.CPU_STATUS_RUN_USERMODE) {
// add events for all the sampled current threads.
List<@NonNull TimeGraphState> currentThreads = getCurrentThreads(ss, interval, intervals.get(currentThreadQuark));
currentThreads.forEach(timeGraphState -> applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor));
} else if (type == Type.CURRENT_THREAD && s != 0) {
String execName = null;
synchronized (fExecNamesCache) {
if (fExecNamesCache.containsEntry(status, interval)) {
NavigableSet<ITmfStateInterval> intervalSet = fExecNamesCache.get(s);
ITmfStateInterval execNameInterval = intervalSet.ceiling(interval);
if (execNameInterval != null && CACHE_COMPARATOR.compare(execNameInterval, interval) == 0) {
execName = (String) execNameInterval.getValue();
}
} else {
int quark = ss.optQuarkAbsolute(Attributes.THREADS, Integer.toString(s), Attributes.EXEC_NAME);
if (quark != ITmfStateSystem.INVALID_ATTRIBUTE) {
ITmfStateInterval namedInterval = ss.querySingleState(interval.getEndTime(), quark);
fExecNamesCache.put(s, namedInterval);
execName = (String) namedInterval.getValue();
}
}
}
TimeGraphState timeGraphState = new TimeGraphState(startTime, duration, execName != null ? execName + ' ' + '(' + String.valueOf(s) + ')' : String.valueOf(s), getSpecificStyleForTid(s));
applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
} else if (type == Type.CURRENT_THREAD) {
// add null state when current thread is 0
ITimeGraphState timeGraphState = new TimeGraphState(startTime, duration, Integer.MIN_VALUE);
applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
} else {
TimeGraphState timeGraphState = new TimeGraphState(startTime, duration, null, getElementStyle(type, s));
applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
}
} else if ((status instanceof Long) && (type == Type.FREQUENCY)) {
long s = (long) status;
// The value needs to fit in an integer (relative to max frequency)
Long maxFrequency = fFreqMap.get(interval.getAttribute());
TimeGraphState timeGraphState = new TimeGraphState(startTime, duration, String.valueOf(FREQUENCY_FORMATTER.format(s)), getSpecificStyleForFrequency((int) (s / FREQUENCY_MULTIPLIER), key, maxFrequency));
applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
} else {
ITimeGraphState timeGraphState = new TimeGraphState(startTime, duration, Integer.MIN_VALUE);
applyFilterAndAddState(eventList, timeGraphState, key, predicates, monitor);
}
}
rows.add(new TimeGraphRowModel(idToQuark.getKey(), eventList));
}
synchronized (fExecNamesCache) {
fExecNamesCache.clear();
}
return new TimeGraphModel(rows);
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState 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.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ControlFlowView method syncToRow.
private boolean syncToRow(ITimeGraphRowModel rowModel, long time, Map<Long, TimeGraphEntry> entryMap) {
long id = rowModel.getEntryID();
List<@NonNull ITimeGraphState> list = rowModel.getStates();
if (list.isEmpty()) {
return false;
}
ITimeGraphState event = list.get(0);
if (event.getStartTime() + event.getDuration() <= time && list.size() > 1) {
/*
* get the second time graph state as passing time - 1 as a first argument to
* the filter will get the previous state, if time is the beginning of an event
*/
event = list.get(1);
}
if (time == event.getStartTime()) {
TimeGraphEntry entry = entryMap.get(id);
if (entry != null) {
Display.getDefault().asyncExec(() -> getTimeGraphViewer().setSelection(entry, true));
return true;
}
}
return false;
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class FlameChartView method syncToRow.
private void syncToRow(ITimeGraphRowModel rowModel, long time, Map<Long, TimeGraphEntry> entryMap) {
long id = rowModel.getEntryID();
List<@NonNull ITimeGraphState> list = rowModel.getStates();
if (!list.isEmpty()) {
ITimeGraphState event = list.get(0);
if (event.getStartTime() + event.getDuration() <= time && list.size() > 1) {
/*
* get the second time graph state as passing time - 1 as a first argument to
* the filter will get the previous state, if time is the beginning of an event
*/
event = list.get(1);
}
if (event.getLabel() != null) {
fFunctions.put(id, event);
} else {
fFunctions.remove(id);
}
if (fSyncSelection && time == event.getStartTime()) {
TimeGraphEntry entry = entryMap.get(id);
if (entry != null) {
fSyncSelection = false;
Display.getDefault().asyncExec(() -> {
getTimeGraphViewer().setSelection(entry, true);
getTimeGraphViewer().getTimeGraphControl().fireSelectionChanged();
});
}
}
} else {
fFunctions.remove(id);
}
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState 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;
}
Aggregations