use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState in project tracecompass by tracecompass.
the class XmlTimeGraphDataProviderTest method assertEqualsStates.
private static void assertEqualsStates(String name, String string, @NonNull List<@NonNull ITimeGraphState> states) {
String[] stringStates = string.split(",");
for (int i = 0; i < stringStates.length / 4; i++) {
ITimeGraphState state = states.get(i);
assertNotNull("State " + i + " for " + name, state);
assertEquals("Start time of state " + i + " for " + name, Long.parseLong(stringStates[i * 4]), state.getStartTime());
assertEquals("Duration of state " + i + " for " + name, Long.parseLong(stringStates[i * 4 + 1]), state.getDuration());
assertEquals("Value of state " + i + " for " + name, Long.parseLong(stringStates[i * 4 + 2]), state.getValue());
assertEquals("Label of state " + i + " for " + name, stringStates[i * 4 + 3], String.valueOf(state.getLabel()));
}
assertEquals("Expected number of states", stringStates.length / 4, states.size());
}
use of org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState 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.ITimeGraphState 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.ITimeGraphState 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.ITimeGraphState 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);
}
}
Aggregations