Search in sources :

Example 6 with TimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.

the class TmfCommonXAxisChartViewer method createQueryParameters.

/**
 * Create map of parameters that will be used by updateData method. If a
 * viewer need a more specialized map than just the time requested it's its
 * responsibility to override this method and provide the desired instance.
 *
 * @param start
 *            The starting value
 * @param end
 *            The ending value
 * @param nb
 *            The number of entries
 * @return Map of parameters
 */
@NonNull
protected Map<String, Object> createQueryParameters(long start, long end, int nb) {
    Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(start, end, nb));
    Multimap<@NonNull Integer, @NonNull String> regexesMap = getRegexes();
    if (!regexesMap.isEmpty()) {
        parameters.put(DataProviderParameterUtils.REGEX_MAP_FILTERS_KEY, regexesMap.asMap());
    }
    return parameters;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 7 with TimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.

the class ThreadStatusDataProviderTest method assertAndGetTree.

private static Map<Long, String> assertAndGetTree(ThreadStatusDataProvider provider) throws IOException {
    TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> treeResponse = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), null);
    assertNotNull(treeResponse);
    assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
    TmfTreeModel<@NonNull TimeGraphEntryModel> treeModel = treeResponse.getModel();
    assertNotNull(treeModel);
    List<@NonNull TimeGraphEntryModel> treeEntries = treeModel.getEntries();
    List<String> expectedStrings = Files.readAllLines(Paths.get("testfiles/kernel_analysis/expectedThreadStatusTree"));
    assertEquals(expectedStrings.size(), treeEntries.size());
    for (int i = 0; i < expectedStrings.size(); i++) {
        String expectedString = expectedStrings.get(i);
        String[] split = expectedString.split(",");
        TimeGraphEntryModel threadEntry = treeEntries.get(i);
        // Assert common fields
        assertEquals(split[0], threadEntry.getName());
        assertEquals(Long.parseLong(split[1]), threadEntry.getStartTime());
        assertEquals(Long.parseLong(split[2]), threadEntry.getEndTime());
        if (threadEntry instanceof ThreadEntryModel) {
            // Verify the thread entry fields
            ThreadEntryModel threadEntryModel = (ThreadEntryModel) threadEntry;
            assertEquals(Integer.parseInt(split[3]), threadEntryModel.getThreadId());
            assertEquals(Integer.parseInt(split[4]), threadEntryModel.getProcessId());
            assertEquals(Integer.parseInt(split[5]), threadEntryModel.getParentThreadId());
        } else {
            // Make sure there is no extra expected fields
            assertEquals(3, split.length);
        }
    }
    Map<Long, String> map = new HashMap<>();
    for (TimeGraphEntryModel threadModel : treeEntries) {
        map.put(threadModel.getId(), threadModel.getName());
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ThreadEntryModel(org.eclipse.tracecompass.internal.analysis.os.linux.core.threadstatus.ThreadEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)

Example 8 with TimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.

the class CpuUsageDataProvider method getTree.

/**
 * @since 2.5
 */
@Override
protected TmfTreeModel<CpuUsageEntryModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(parameters);
    if (filter == null) {
        return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
    }
    long end = filter.getEnd();
    List<CpuUsageEntryModel> entryList = new ArrayList<>();
    Set<Integer> cpus = extractCpuSet(parameters);
    Map<String, Long> cpuUsageMap = getAnalysisModule().getCpuUsageInRange(cpus, filter.getStart(), end);
    double timeRange = end - filter.getStart();
    long totalTime = cpuUsageMap.getOrDefault(KernelCpuUsageAnalysis.TOTAL, 0l);
    long totalId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
    entryList.add(new CpuUsageEntryModel(totalId, -1, ImmutableList.of(getTrace().getName(), String.valueOf(Messages.CpuUsageDataProvider_Total), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * totalTime / timeRange : (float) 0), TIME_FORMATTER.format(totalTime)), TOTAL_SERIES_TID, totalTime));
    for (Entry<String, Long> entry : cpuUsageMap.entrySet()) {
        /*
             * Process only entries representing the total of all CPUs and that
             * have time on CPU
             */
        String key = entry.getKey();
        if (entry.getValue() == 0 || !key.startsWith(KernelCpuUsageAnalysis.TOTAL)) {
            continue;
        }
        String[] strings = key.split(KernelCpuUsageAnalysis.SPLIT_STRING, 2);
        if (strings.length > 1) {
            int tid = Integer.parseInt(strings[1]);
            Long time = entry.getValue();
            if (tid != 0) {
                entryList.add(new CpuUsageEntryModel(getId(tid), totalId, ImmutableList.of(getProcessName(tid, strings[1], end), String.valueOf(tid), String.format(Messages.CpuUsageDataProvider_TextPercent, timeRange > 0 ? 100 * time / timeRange : (float) 0), TIME_FORMATTER.format(time)), tid, time));
            }
        }
    }
    return new TmfTreeModel<>(ImmutableList.of(String.valueOf(Messages.CpuUsageDataProvider_ColumnProcess), OsStrings.tid(), String.valueOf(Messages.CpuUsageDataProvider_ColumnPercent), String.valueOf(Messages.CpuUsageDataProvider_ColumnTime)), entryList);
}
Also used : ArrayList(java.util.ArrayList) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) CpuUsageEntryModel(org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)

Example 9 with TimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.

the class KernelMemoryUsageDataProvider method getTree.

/**
 * @since 2.5
 */
@Override
protected TmfTreeModel<MemoryUsageTreeModel> getTree(ITmfStateSystem ss, Map<String, Object> parameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException {
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(parameters);
    if (filter == null) {
        return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
    }
    long start = filter.getStart();
    long end = filter.getEnd();
    // Let the list of active states be null if we aren't filtering
    List<ITmfStateInterval> active = null;
    Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(parameters);
    if (isFiltered != null && isFiltered) {
        if (start == end || start > ss.getCurrentEndTime() || end < ss.getStartTime()) {
            /*
                 * return an empty list if the filter is empty or does not intersect the state
                 * system
                 */
            return new TmfTreeModel<>(Collections.emptyList(), Collections.emptyList());
        }
        active = ss.queryFullState(Long.max(start, ss.getStartTime()));
    }
    List<MemoryUsageTreeModel> nodes = new ArrayList<>();
    List<Integer> threadQuarkList = ss.getSubAttributes(ITmfStateSystem.ROOT_ATTRIBUTE, false);
    long totalId = getId(ITmfStateSystem.ROOT_ATTRIBUTE);
    nodes.add(new MemoryUsageTreeModel(totalId, -1, TOTAL_TID, Collections.singletonList(getTrace().getName())));
    for (Integer threadQuark : threadQuarkList) {
        if (active == null || ((threadQuark < active.size()) && active.get(threadQuark).getEndTime() < end)) {
            String tidString = ss.getAttributeName(threadQuark);
            String procname = fProcessNameMap.computeIfAbsent(tidString, string -> getProcessName(string, end));
            // Ensure that we reuse the same id for a given quark.
            long id = getId(threadQuark);
            nodes.add(new MemoryUsageTreeModel(id, totalId, parseTid(tidString), Collections.singletonList(procname)));
        }
    }
    return new TmfTreeModel<>(Collections.emptyList(), nodes);
}
Also used : MemoryUsageTreeModel(org.eclipse.tracecompass.analysis.os.linux.core.memory.MemoryUsageTreeModel) ITmfStateInterval(org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval) ArrayList(java.util.ArrayList) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)

Example 10 with TimeQueryFilter

use of org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter in project tracecompass by tracecompass.

the class ControlFlowCheckActiveProvider method getActiveIds.

private Set<Long> getActiveIds(TimeGraphEntry cfe, TmfTimeRange range) {
    ITimeGraphDataProvider<? extends TimeGraphEntryModel> dataProvider = BaseDataProviderTimeGraphView.getProvider(cfe);
    if (range.equals(fRange) && dataProvider.equals(fProvider) || !(dataProvider instanceof ThreadStatusDataProvider)) {
        return fActive;
    }
    TimeQueryFilter filter = new TimeQueryFilter(range.getStartTime().toNanos(), range.getEndTime().toNanos(), 2);
    Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.timeQueryToMap(filter);
    parameters.put(ThreadStatusDataProvider.ACTIVE_THREAD_FILTER_KEY, true);
    TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = ((ThreadStatusDataProvider) dataProvider).fetchTree(parameters, null);
    TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
    if (model == null) {
        // query must have failed, return empty and don't invalidate the cache.
        return Collections.emptySet();
    }
    fRange = range;
    fActive = model.getEntries().stream().map(TimeGraphEntryModel::getId).collect(Collectors.toSet());
    return fActive;
}
Also used : NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) ThreadStatusDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.threadstatus.ThreadStatusDataProvider)

Aggregations

TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)28 SelectionTimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter)16 NonNull (org.eclipse.jdt.annotation.NonNull)14 TmfTreeModel (org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel)14 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 TimeGraphEntryModel (org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel)4 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 CpuUsageEntryModel (org.eclipse.tracecompass.analysis.os.linux.core.cpuusage.CpuUsageEntryModel)3 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)3 ITmfStateSystem (org.eclipse.tracecompass.statesystem.core.ITmfStateSystem)3 StateSystemDisposedException (org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException)3 ITmfStateInterval (org.eclipse.tracecompass.statesystem.core.interval.ITmfStateInterval)3 IAnalysisModule (org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule)3 ITimeGraphArrow (org.eclipse.tracecompass.tmf.core.model.timegraph.ITimeGraphArrow)3