use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class InputOutputStateProvider method eventHandle.
@Override
protected void eventHandle(@Nullable ITmfEvent event) {
if (event == null) {
return;
}
final String eventName = event.getName();
try {
final ITmfStateSystemBuilder ss = NonNullUtils.checkNotNull(getStateSystemBuilder());
/*
* Feed event to the history system if it's known to cause a state
* transition.
*/
KernelEventHandler handler = fEventNames.get(eventName);
if (handler == null) {
if (isSyscallExit(eventName)) {
handler = fSysExitHandler;
} else if (isSyscallEntry(eventName)) {
handler = fSysEntryHandler;
}
}
if (handler != null) {
handler.handleEvent(ss, event);
}
} catch (TimeRangeException | StateValueTypeException | AttributeNotFoundException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Exception while building the IO state system", e);
}
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException 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.statesystem.core.exceptions.TimeRangeException 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.statesystem.core.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class ThreadStatusDataProvider method filter.
/**
* Filter the threads from a {@link TreeMultimap} according to if they are
* active or not
* @param traceEntry
*
* @param tidToEntry
* Threads to filter
* @param filter
* time range to query
* @return a list of the active threads
*/
@NonNull
private List<@NonNull TimeGraphEntryModel> filter(TimeGraphEntryModel traceEntry, TreeMultimap<Integer, ThreadEntryModel.Builder> tidToEntry, @NonNull Map<@NonNull String, @NonNull Object> parameters) {
// avoid putting everything as a child of the swapper thread.
Boolean isActiveFilter = DataProviderParameterUtils.extractBoolean(parameters, ACTIVE_THREAD_FILTER_KEY);
if (!Boolean.TRUE.equals(isActiveFilter)) {
ImmutableList.Builder<TimeGraphEntryModel> builder = ImmutableList.builder();
builder.add(traceEntry);
for (ThreadEntryModel.Builder entryBuilder : tidToEntry.values()) {
builder.add(build(entryBuilder));
}
return builder.build();
}
ITmfStateSystem ss = fModule.getStateSystem();
if (ss == null) {
return Collections.emptyList();
}
List<@NonNull Long> filter = DataProviderParameterUtils.extractTimeRequested(parameters);
if (filter == null || filter.isEmpty()) {
return Collections.emptyList();
}
long start = Long.max(filter.get(0), ss.getStartTime());
long end = Long.min(filter.get(filter.size() - 1), ss.getCurrentEndTime());
if (start > end) {
return Collections.emptyList();
}
List<@NonNull Long> selectedItems = DataProviderParameterUtils.extractSelectedItems(parameters);
if (selectedItems != null) {
Set<Long> cpus = Sets.newHashSet(selectedItems);
List<@NonNull Integer> quarks = ss.getQuarks(Attributes.THREADS, WILDCARD, Attributes.CURRENT_CPU_RQ);
Set<TimeGraphEntryModel> models = new HashSet<>();
models.add(traceEntry);
Map<Integer, Integer> rqToPidCache = new HashMap<>();
try {
for (ITmfStateInterval interval : ss.query2D(quarks, Long.max(ss.getStartTime(), start), end)) {
Object o = interval.getValue();
if (o instanceof Number && cpus.contains(((Number) o).longValue())) {
int attribute = interval.getAttribute();
try {
// Get the name of the thread
int nameQuark = ss.getQuarkRelative(ss.getParentAttributeQuark(attribute), Attributes.EXEC_NAME);
Iterable<@NonNull ITmfStateInterval> names2d = ss.query2D(Collections.singleton(nameQuark), interval.getStartTime(), interval.getEndTime());
Iterable<@NonNull String> names = Iterables.transform(names2d, intervalName -> String.valueOf(intervalName.getValue()));
int tid = rqToPidCache.computeIfAbsent(attribute, a -> Attributes.parseThreadAttributeName(ss.getAttributeName(ss.getParentAttributeQuark(a))).getFirst());
// Skip Idle (thread 0)
if (tid == 0) {
continue;
}
for (ThreadEntryModel.Builder model : tidToEntry.get(tid)) {
if (interval.getStartTime() <= model.getEndTime() && model.getStartTime() <= interval.getEndTime()) {
ThreadEntryModel build = build(model);
if (!Iterables.any(names, name -> name.equals(build.getName()))) {
continue;
}
models.add(build);
}
}
} catch (AttributeNotFoundException e) {
// $NON-NLS-1$
Activator.getDefault().logWarning("Unable to get the quark for the attribute name", e);
}
}
}
} catch (IndexOutOfBoundsException | TimeRangeException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Invalid query parameters", e);
} catch (StateSystemDisposedException e) {
return Collections.emptyList();
}
return Lists.newArrayList(models);
}
ImmutableList.Builder<TimeGraphEntryModel> builder = ImmutableList.builder();
builder.add(traceEntry);
for (ThreadEntryModel.Builder thread : tidToEntry.values()) {
Integer statusQuark = fQuarkMap.get(thread.getId());
if (statusQuark == null) {
continue;
}
QuarkIterator iterator = new QuarkIterator(ss, statusQuark, start, end);
Iterator<Object> values = Iterators.transform(iterator, ITmfStateInterval::getValue);
if (Iterators.any(values, ACTIVE_STATES::contains)) {
builder.add(build(thread));
}
}
return builder.build();
}
use of org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException in project tracecompass by tracecompass.
the class StateSystemPushPopTest method testEmptyStack.
/**
* Test the places where the stack is empty.
*/
@Test
public void testEmptyStack() {
final ITmfStateSystemBuilder ss2 = ss;
assertNotNull(ss2);
try {
/* At the start */
ITmfStateInterval interval = ss.querySingleState(1, attribute);
assertTrue(interval.getStateValue().isNull());
interval = StateSystemUtils.querySingleStackTop(ss2, 1, attribute);
assertEquals(null, interval);
/* Between the two "stacks" in the state history */
interval = ss.querySingleState(19, attribute);
assertTrue(interval.getStateValue().isNull());
interval = StateSystemUtils.querySingleStackTop(ss2, 19, attribute);
assertEquals(null, interval);
/* At the end */
interval = ss.querySingleState(27, attribute);
assertTrue(interval.getStateValue().isNull());
interval = StateSystemUtils.querySingleStackTop(ss2, 27, attribute);
assertEquals(null, interval);
} catch (AttributeNotFoundException | TimeRangeException | StateSystemDisposedException e) {
fail(errMsg + e.toString());
}
}
Aggregations