Search in sources :

Example 26 with OutputElementStyle

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()));
    }
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 27 with OutputElementStyle

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);
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ArrayList(java.util.ArrayList) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TmfTreeDataModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeDataModel)

Example 28 with OutputElementStyle

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;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)

Example 29 with OutputElementStyle

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;
}
Also used : OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState) TimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphState) ArrayList(java.util.ArrayList) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ITimeGraphState(org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)

Example 30 with OutputElementStyle

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, "");
}
Also used : Iterables(com.google.common.collect.Iterables) AnnotationType(org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.IAnnotation.AnnotationType) TmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp) BiFunction(java.util.function.BiFunction) ITmfEventAspect(org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) HashMap(java.util.HashMap) Function(java.util.function.Function) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) StyleProperties(org.eclipse.tracecompass.tmf.core.model.StyleProperties) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) DataProviderParameterUtils(org.eclipse.tracecompass.tmf.core.dataprovider.DataProviderParameterUtils) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) List(java.util.List) TmfTraceUtils(org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) ExecutionType(org.eclipse.tracecompass.tmf.core.request.ITmfEventRequest.ExecutionType) Status(org.eclipse.tracecompass.tmf.core.response.ITmfResponse.Status) Collections(java.util.Collections) NonNull(org.eclipse.jdt.annotation.NonNull) SymbolType(org.eclipse.tracecompass.tmf.core.model.StyleProperties.SymbolType) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ITmfEvent(org.eclipse.tracecompass.tmf.core.event.ITmfEvent) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) LinkedHashMap(java.util.LinkedHashMap) NonNull(org.eclipse.jdt.annotation.NonNull) OutputElementStyle(org.eclipse.tracecompass.tmf.core.model.OutputElementStyle) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) Collection(java.util.Collection) TmfEventRequest(org.eclipse.tracecompass.tmf.core.request.TmfEventRequest) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

OutputElementStyle (org.eclipse.tracecompass.tmf.core.model.OutputElementStyle)31 RGBAColor (org.eclipse.tracecompass.tmf.core.presentation.RGBAColor)12 Nullable (org.eclipse.jdt.annotation.Nullable)11 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 NonNull (org.eclipse.jdt.annotation.NonNull)7 LinkedHashMap (java.util.LinkedHashMap)5 Point (org.eclipse.swt.graphics.Point)5 LongPoint (org.eclipse.tracecompass.internal.tmf.ui.widgets.timegraph.TimeGraphRender.LongPoint)5 Color (org.eclipse.swt.graphics.Color)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 StyleManager (org.eclipse.tracecompass.tmf.ui.model.StyleManager)4 ITimeEvent (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent)4 Collection (java.util.Collection)3 Stack (java.util.Stack)3 RGB (org.eclipse.swt.graphics.RGB)3 Annotation (org.eclipse.tracecompass.internal.provisional.tmf.core.model.annotations.Annotation)3 IOutputStyleProvider (org.eclipse.tracecompass.tmf.core.model.IOutputStyleProvider)3 ITimeGraphState (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphState)3 StateItem (org.eclipse.tracecompass.tmf.ui.widgets.timegraph.StateItem)3