use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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.OutputElementStyle in project tracecompass by tracecompass.
the class DisksIODataProvider method getTree.
@Override
protected TmfTreeModel<TmfTreeDataModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) {
List<TmfTreeDataModel> nodes = new ArrayList<>();
long rootId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
nodes.add(new TmfTreeDataModel(rootId, -1, Collections.singletonList(getTrace().getName()), false, null));
String readName = Objects.requireNonNull(Messages.DisksIODataProvider_read);
String writeName = Objects.requireNonNull(Messages.DisksIODataProvider_write);
int i = 0;
for (Integer diskQuark : ss.getQuarks(Attributes.DISKS, "*")) {
// $NON-NLS-1$
String diskName = DiskUtils.getDiskName(ss, diskQuark);
long diskId = getId(diskQuark);
nodes.add(new TmfTreeDataModel(diskId, rootId, Collections.singletonList(diskName), false, null));
// Do not add the read/write entries if there was no read/write
int readQuark = ss.optQuarkRelative(diskQuark, Attributes.SECTORS_READ);
int writeQuark = ss.optQuarkRelative(diskQuark, Attributes.SECTORS_WRITTEN);
if (readQuark == ITmfStateSystem.INVALID_ATTRIBUTE && writeQuark == ITmfStateSystem.INVALID_ATTRIBUTE) {
continue;
}
// Get read and write color for this disk
Pair<String, String> pair = COLOR_LIST.get(i % COLOR_LIST.size());
String seriesStyle = SUPPORTED_STYLES.get((i / COLOR_LIST.size()) % SUPPORTED_STYLES.size());
if (readQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
nodes.add(new TmfTreeDataModel(getId(readQuark), diskId, Collections.singletonList(readName), true, new OutputElementStyle(BASE_STYLE, ImmutableMap.of(StyleProperties.COLOR, pair.getFirst(), StyleProperties.SERIES_STYLE, seriesStyle, StyleProperties.STYLE_NAME, diskName + '/' + readName))));
}
if (writeQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
nodes.add(new TmfTreeDataModel(getId(writeQuark), diskId, Collections.singletonList(writeName), true, new OutputElementStyle(BASE_STYLE, ImmutableMap.of(StyleProperties.COLOR, pair.getSecond(), StyleProperties.SERIES_STYLE, seriesStyle, StyleProperties.STYLE_NAME, diskName + '/' + writeName))));
}
i++;
}
return new TmfTreeModel<>(Collections.emptyList(), nodes);
}
use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle in project tracecompass by tracecompass.
the class ResourcesStatusDataProvider method getCurrentThreads.
/**
* Get a list of all the current threads over the duration of the current
* usermode interval, as several threads can be scheduled over that interval
*
* @param ss
* backing state system
* @param userModeInterval
* interval representing the CPUs current user mode state.
* @param currentThreadIntervals
* Current Threads intervals for the same CPU with the time query
* filter sampling
* @return a List of intervals with the current thread name label.
*/
private static List<@NonNull TimeGraphState> getCurrentThreads(@NonNull ITmfStateSystem ss, ITmfStateInterval userModeInterval, @NonNull NavigableSet<ITmfStateInterval> currentThreadIntervals) throws StateSystemDisposedException {
List<@NonNull TimeGraphState> list = new ArrayList<>();
for (ITmfStateInterval currentThread : currentThreadIntervals) {
// filter the current thread intervals which overlap the usermode interval
if (currentThread.getStartTime() <= userModeInterval.getEndTime() && currentThread.getEndTime() >= userModeInterval.getStartTime()) {
long start = Long.max(userModeInterval.getStartTime(), currentThread.getStartTime());
long end = Long.min(userModeInterval.getEndTime(), currentThread.getEndTime());
long duration = end - start + 1;
Object tid = currentThread.getValue();
if (tid instanceof Integer) {
int execNameQuark = ss.optQuarkAbsolute(Attributes.THREADS, String.valueOf(tid), Attributes.EXEC_NAME);
if (execNameQuark != ITmfStateSystem.INVALID_ATTRIBUTE) {
Object currentThreadName = ss.querySingleState(currentThread.getEndTime(), execNameQuark).getValue();
if (currentThreadName instanceof String) {
list.add(new TimeGraphState(start, duration, (String) currentThreadName, STYLE_MAP.computeIfAbsent(LinuxStyle.USERMODE.getLabel(), style -> new OutputElementStyle(style))));
continue;
}
}
}
list.add(new TimeGraphState(start, duration, null, STYLE_MAP.computeIfAbsent(LinuxStyle.USERMODE.getLabel(), style -> new OutputElementStyle(style))));
}
}
return list;
}
use of org.eclipse.tracecompass.tmf.core.model.OutputElementStyle 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.OutputElementStyle in project tracecompass by tracecompass.
the class EventAnnotationProvider method fetchAnnotations.
@Override
public TmfModelResponse<@NonNull AnnotationModel> fetchAnnotations(Map<@NonNull String, @NonNull Object> fetchParameters, @Nullable IProgressMonitor monitor) {
List<Long> timeRequested = DataProviderParameterUtils.extractTimeRequested(fetchParameters);
List<@NonNull Long> entries = DataProviderParameterUtils.extractSelectedItems(fetchParameters);
@Nullable Set<@NonNull String> categories = DataProviderParameterUtils.extractSelectedCategories(fetchParameters);
if (timeRequested == null || entries == null) {
return NO_DATA;
}
TmfModelResponse<@NonNull TmfTreeModel<M>> tree = Objects.requireNonNull(fTreeResolver.apply(fetchParameters, monitor));
TmfTreeModel<M> model = tree.getModel();
if (model == null) {
return NO_DATA;
}
Function<M, Integer> keyMapper = entry -> (Integer) Iterables.get(entry.getMetadata().get(fMetadataKey), 0);
Predicate<M> predicate = entry -> {
Collection<@NonNull Object> collection = entry.getMetadata().get(fMetadataKey);
return !collection.isEmpty() && !Objects.equals(Iterables.get(collection, 0), -1);
};
Map<Integer, TimeGraphEntryModel> rowMap = new LinkedHashMap<>();
List<@NonNull M> entries2 = model.getEntries();
entries2.stream().filter(predicate).filter(fAdditionalPredicate).forEach(element -> rowMap.put(keyMapper.apply(element), element));
Map<String, Collection<Annotation>> markers = new LinkedHashMap<>();
TmfTimeRange tr = new TmfTimeRange(TmfTimestamp.fromNanos(timeRequested.get(0)), TmfTimestamp.fromNanos(timeRequested.get(timeRequested.size() - 1)));
EventAnnotationProvider<@NonNull M> lock = this;
synchronized (lock) {
for (ITmfTrace source : fMarkerTraces) {
TmfEventRequest old = fRunningRequests.remove(source);
if (old != null && old.isRunning()) {
old.cancel();
}
}
for (ITmfTrace source : fMarkerTraces) {
if (categories != null && !categories.contains(source.getName())) {
// marker category is filtered out
continue;
}
TmfEventRequest req = new TmfEventRequest(ITmfEvent.class, tr, 0, Integer.MAX_VALUE, ExecutionType.FOREGROUND) {
private int timesliceIndex = 0;
private Set<Object> values = new HashSet<>();
private long next() {
if (timeRequested.size() > timesliceIndex + 1) {
return timeRequested.get(timesliceIndex + 1);
}
return Long.MAX_VALUE;
}
@Override
public void handleData(ITmfEvent event) {
super.handleData(event);
while (event.getTimestamp().toNanos() > next()) {
timesliceIndex++;
values.clear();
if (timesliceIndex >= timeRequested.size() - 1) {
done();
return;
}
}
Object value = TmfTraceUtils.resolveEventAspectOfClassForEvent(event.getTrace(), fAspect, event);
if (value != null && !values.contains(value)) {
values.add(value);
synchronized (markers) {
Collection<Annotation> markerList = markers.computeIfAbsent(String.valueOf(event.getTrace().getName()), string -> new ArrayList<>());
TimeGraphEntryModel entryModel = rowMap.get(value);
if (entryModel != null) {
String name = event.getName();
Map<String, Object> style = new HashMap<>();
style.put(StyleProperties.SYMBOL_TYPE, SymbolType.INVERTED_TRIANGLE);
style.put(StyleProperties.COLOR, getMarkerColor(name));
style.put(StyleProperties.HEIGHT, 0.3);
style.put(StyleProperties.VERTICAL_ALIGN, StyleProperties.VerticalAlign.TOP);
markerList.add(new Annotation(event.getTimestamp().toNanos(), 0L, entryModel.getId(), AnnotationType.CHART, name, new OutputElementStyle(name, style)));
}
}
}
}
private String getMarkerColor(String name) {
// $NON-NLS-1$
return Objects.requireNonNull(fMarkerColorCache.computeIfAbsent(name, label -> Objects.requireNonNull(String.format("#%6x", label.hashCode() & 0xffffff))));
}
};
fRunningRequests.put(source, req);
source.sendRequest(req);
}
try {
for (ITmfTrace source : fMarkerTraces) {
TmfEventRequest req = null;
synchronized (lock) {
req = fRunningRequests.get(source);
}
if (req != null) {
req.waitForCompletion();
fRunningRequests.remove(source);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
// $NON-NLS-1$
return new TmfModelResponse<>(new AnnotationModel(markers), Status.COMPLETED, "");
}
Aggregations