use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel in project tracecompass by tracecompass.
the class XmlTimeGraphDataProvider method createRows.
@NonNull
private Collection<@NonNull ITimeGraphRowModel> createRows(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, long[] timesRequested, @NonNull Map<@NonNull String, @NonNull Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
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));
}
long currentEndTime = ss.getCurrentEndTime();
Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>(idToDisplayQuark.size());
for (Entry<Integer, Long> entry : idToDisplayQuark.entrySet()) {
quarkToRow.put(entry.getKey(), new TimeGraphRowModel(entry.getValue(), new ArrayList<>()));
}
for (ITmfStateInterval interval : ss.query2D(idToDisplayQuark.keySet(), getTimes(ss, timesRequested))) {
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);
applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
}
}
for (ITimeGraphRowModel model : quarkToRow.values()) {
model.getStates().sort(Comparator.comparingLong(ITimeGraphState::getStartTime));
}
return quarkToRow.values();
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel in project tracecompass by tracecompass.
the class StateSystemDataProvider method getModuleRowModels.
private static ITimeGraphRowModel getModuleRowModels(ModuleEntryModel module) {
TimeGraphRowModel moduleRow = new TimeGraphRowModel(module.getId(), new ArrayList<>());
List<@NonNull ITimeGraphState> states = moduleRow.getStates();
states.add(new TimeGraphState(module.getStartTime(), module.getEndTime() - module.getStartTime(), Integer.MAX_VALUE));
return moduleRow;
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel in project tracecompass by tracecompass.
the class StateSystemDataProvider method getRowModels.
private List<@NonNull ITimeGraphRowModel> getRowModels(ITmfStateSystem ss, Map<Integer, Long> idToDisplayQuark, @Nullable List<Long> times, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
// Create predicates
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));
}
// Create quark to row
Map<Integer, ITimeGraphRowModel> quarkToRow = new HashMap<>(idToDisplayQuark.size());
for (Entry<Integer, Long> entry : idToDisplayQuark.entrySet()) {
quarkToRow.put(entry.getKey(), new TimeGraphRowModel(entry.getValue(), new ArrayList<>()));
}
for (ITmfStateInterval interval : ss.query2D(idToDisplayQuark.keySet(), getTimes(ss, times))) {
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, ss.getCurrentEndTime());
applyFilterAndAddState(states, timeGraphState, row.getEntryID(), predicates, monitor);
}
}
// sort every row model so their states can be in chronological order
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.TimeGraphRowModel in project tracecompass by tracecompass.
the class StateSystemDataProvider method fetchRowModel.
@Override
@NonNull
public TmfModelResponse<@NonNull TimeGraphModel> fetchRowModel(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
Table<ITmfStateSystem, Integer, Long> table = HashBasedTable.create();
// Get the quarks to display
Collection<Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
synchronized (fEntryBuilder) {
if (selectedItems == null) {
// No selected items, take them all
selectedItems = fIDToDisplayQuark.keySet();
}
for (Long id : selectedItems) {
Pair<ITmfStateSystem, Integer> pair = fIDToDisplayQuark.get(id);
if (pair != null) {
table.put(pair.getFirst(), pair.getSecond(), id);
}
}
}
List<@NonNull ITimeGraphRowModel> allRows = new ArrayList<>();
try {
List<Long> times = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
for (Entry<ITmfStateSystem, Map<Integer, Long>> ssEntry : table.rowMap().entrySet()) {
ITmfStateSystem ss = Objects.requireNonNull(ssEntry.getKey());
List<@NonNull ITimeGraphRowModel> rows = getRowModels(ss, ssEntry.getValue(), times, fetchParameters, monitor);
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
synchronized (fEntryBuilder) {
// Add the SS
Long ssId = fSsToId.get(ss);
if (ssId != null && selectedItems.contains(ssId)) {
TimeGraphRowModel ssRow = new TimeGraphRowModel(ssId, new ArrayList<>());
List<@NonNull ITimeGraphState> states = ssRow.getStates();
states.add(new TimeGraphState(ss.getStartTime(), ss.getCurrentEndTime() - ss.getStartTime(), Integer.MAX_VALUE));
rows.add(ssRow);
}
}
allRows.addAll(rows);
}
synchronized (fEntryBuilder) {
for (ModuleEntryModel module : fModuleEntryModelList) {
if (selectedItems.contains(module.getId())) {
allRows.add(getModuleRowModels(module));
}
}
}
if (monitor != null && monitor.isCanceled()) {
return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
}
return new TmfModelResponse<>(new TimeGraphModel(allRows), Status.COMPLETED, CommonStatusMessage.COMPLETED);
} catch (IndexOutOfBoundsException | TimeRangeException | StateSystemDisposedException e) {
return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.STATE_SYSTEM_FAILED);
}
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphRowModel 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);
}
Aggregations