use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ExampleTimeGraphDataProvider method getDefaultRowModels.
@Nullable
private List<ITimeGraphRowModel> getDefaultRowModels(Map<String, Object> fetchParameters, ITmfStateSystem ss, @Nullable IProgressMonitor monitor) throws IndexOutOfBoundsException, TimeRangeException, StateSystemDisposedException {
Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>();
// Prepare the quarks to display
Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
if (selectedItems == null) {
// No selected items, take them all
selectedItems = fIDToDisplayQuark.keySet();
}
for (Long id : selectedItems) {
Integer quark = fIDToDisplayQuark.get(id);
if (quark != null) {
quarkToRow.put(quark, new TimeGraphRowModel(id, new ArrayList<>()));
}
}
// This regex map automatically filters or highlights the entry
// according to the global filter entered by the user
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));
}
// Query the state system to fill the states
long currentEndTime = ss.getCurrentEndTime();
for (ITmfStateInterval interval : ss.query2D(quarkToRow.keySet(), getTimes(ss, DataProviderParameterUtils.extractTimeRequested(fetchParameters)))) {
if (monitor != null && monitor.isCanceled()) {
return Collections.emptyList();
}
ITimeGraphRowModel row = quarkToRow.get(interval.getAttribute());
if (row != null) {
List<@NonNull ITimeGraphState> states = row.getStates();
ITimeGraphState timeGraphState = getStateFromInterval(interval, currentEndTime);
// This call will compare the state with the filter predicate
applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
}
}
for (ITimeGraphRowModel model : quarkToRow.values()) {
model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
}
return new ArrayList<>(quarkToRow.values());
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class CriticalPathDataProvider method fetchRowModel.
@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(@NonNull Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
IGraphWorker graphWorker = getCurrent();
if (graphWorker == null) {
return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
CriticalPathVisitor visitor = fHorizontalVisitorCache.getIfPresent(graphWorker);
if (visitor == null) {
return new TmfModelResponse<>(null, Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
// TODO server: Parameters validation should be handle separately. It
// can be either in the data provider itself or before calling it. It
// will avoid the creation of filters and the content of the map can be
// use directly.
SelectionTimeQueryFilter filter = FetchParametersUtils.createSelectionTimeQuery(fetchParameters);
if (filter == null) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
}
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));
}
List<@NonNull ITimeGraphRowModel> rowModels = new ArrayList<>();
for (Long id : filter.getSelectedItems()) {
/*
* need to use asMap, so that we don't return a row for an ID that does not
* belong to this provider, else fStates.get(id) might return an empty
* collection for an id from another data provider.
*/
Collection<ITimeGraphState> states = visitor.fStates.asMap().get(id);
if (states != null) {
List<ITimeGraphState> filteredStates = new ArrayList<>();
for (ITimeGraphState state : states) {
if (overlaps(state.getStartTime(), state.getDuration(), filter.getTimesRequested())) {
// Reset the properties for this state before filtering
state.setActiveProperties(0);
applyFilterAndAddState(filteredStates, state, id, predicates, monitor);
}
}
rowModels.add(new TimeGraphRowModel(id, filteredStates));
}
}
return new TmfModelResponse<>(new TimeGraphModel(rowModels), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ThreadStatusDataProviderTest method assertEqualsStates.
private static void assertEqualsStates(String string, @NonNull List<@NonNull ITimeGraphState> states, String element) {
String[] stringStates = string.split(",");
for (int i = 0; i < stringStates.length / 4; i++) {
ITimeGraphState state = states.get(i);
assertEquals(element + ": start time at position " + i, Long.parseLong(stringStates[i * 4]), state.getStartTime());
assertEquals(element + ": duration at position " + i, Long.parseLong(stringStates[i * 4 + 1]), state.getDuration());
OutputElementStyle style = state.getStyle();
if (style == null) {
// Expected a value of Long
try {
assertEquals(element + ": value at position " + i, Long.parseLong(stringStates[i * 4 + 2]), state.getValue());
} catch (NumberFormatException e) {
fail(element + ": value at position " + i + ": did not expect a null style");
}
} else {
assertEquals(element + ": value at position " + i, stringStates[i * 4 + 2], style.getParentKey());
}
assertEquals(element + ": label at position " + i, stringStates[i * 4 + 3], String.valueOf(state.getLabel()));
}
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ResourcesStatusDataProvider method getSyscalls.
/**
* Get a list of all the system call states over the duration of the current
* syscall interval, as several threads can be scheduled over that interval
*
* @param ss
* backing state system
* @param syscallInterval
* current syscall interval
* @param currentThreadIntervals
* sampled current thread intervals for the CPU
* @return a List of intervals with the system call name label.
*/
private static List<@NonNull ITimeGraphState> getSyscalls(@NonNull ITmfStateSystem ss, ITmfStateInterval syscallInterval, @NonNull NavigableSet<ITmfStateInterval> currentThreadIntervals) throws StateSystemDisposedException {
List<@NonNull ITimeGraphState> list = new ArrayList<>();
for (ITmfStateInterval currentThread : currentThreadIntervals) {
// filter the current thread intervals which overlap the syscall interval
if (currentThread.getStartTime() <= syscallInterval.getEndTime() && currentThread.getEndTime() >= syscallInterval.getStartTime()) {
long start = Long.max(syscallInterval.getStartTime(), currentThread.getStartTime());
long end = Long.min(syscallInterval.getEndTime(), currentThread.getEndTime());
long duration = end - start + 1;
Object tid = currentThread.getValue();
if (tid instanceof Integer) {
int syscallQuark = ss.optQuarkAbsolute(Attributes.THREADS, String.valueOf(tid), Attributes.SYSTEM_CALL);
if (syscallQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
Object syscallName = ss.querySingleState(start, syscallQuark).getValue();
if (syscallName instanceof String) {
list.add(new TimeGraphState(start, duration, String.valueOf(syscallName), STYLE_MAP.computeIfAbsent(LinuxStyle.SYSCALL.getLabel(), style -> new OutputElementStyle(style))));
continue;
}
}
}
list.add(new TimeGraphState(start, duration, null, STYLE_MAP.computeIfAbsent(LinuxStyle.SYSCALL.getLabel(), style -> new OutputElementStyle(style))));
}
}
return list;
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method createTimeGraphState.
@NonNull
private static ITimeGraphState createTimeGraphState(ITmfStateInterval interval, NavigableSet<ITmfStateInterval> syscalls) {
long startTime = interval.getStartTime();
long duration = interval.getEndTime() - startTime + 1;
Object status = interval.getValue();
if (status instanceof Integer) {
int s = (int) status;
if (s == StateValues.PROCESS_STATUS_RUN_SYSCALL) {
// intervals are sorted by start time
ITmfStateInterval syscall = syscalls.floor(new TmfStateInterval(startTime, startTime + 1, 0, 0));
if (syscall != null) {
Object value = syscall.getValue();
if (value instanceof String) {
return new TimeGraphState(startTime, duration, String.valueOf(value), getElementStyle(s));
}
}
}
return new TimeGraphState(startTime, duration, null, getElementStyle(s));
}
return new TimeGraphState(startTime, duration, Integer.MIN_VALUE);
}
Aggregations