Search in sources :

Example 11 with TimeQueryFilter

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

the class ActiveThreadsFilter method getActiveThreads.

@NonNull
private static Set<Long> getActiveThreads(TmfTimeRange winRange, @NonNull ITmfTrace trace) {
    ThreadStatusDataProvider threadStatusProvider = DataProviderManager.getInstance().getDataProvider(trace, ThreadStatusDataProvider.ID, ThreadStatusDataProvider.class);
    if (threadStatusProvider == null) {
        return Collections.emptySet();
    }
    long beginTS = winRange.getStartTime().getValue();
    long endTS = winRange.getEndTime().getValue();
    TimeQueryFilter filter = new TimeQueryFilter(beginTS, endTS, 2);
    Map<@NonNull String, @NonNull Object> parameters = FetchParametersUtils.timeQueryToMap(filter);
    parameters.put(ThreadStatusDataProvider.ACTIVE_THREAD_FILTER_KEY, true);
    TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = threadStatusProvider.fetchTree(parameters, null);
    TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
    if (model == null) {
        return Collections.emptySet();
    }
    HashSet<Long> activeThreads = Sets.newHashSet(Iterables.transform(model.getEntries(), TimeGraphEntryModel::getId));
    return activeThreads == null ? Collections.emptySet() : activeThreads;
}
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) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) ThreadStatusDataProvider(org.eclipse.tracecompass.internal.analysis.os.linux.core.threadstatus.ThreadStatusDataProvider) NonNull(org.eclipse.jdt.annotation.NonNull)

Example 12 with TimeQueryFilter

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

the class SegmentStoreStatisticsDataProvider method fetchTree.

@Override
public TmfModelResponse<TmfTreeModel<SegmentStoreStatisticsModel>> fetchTree(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    IAnalysisModule module = fModule;
    if (module != null) {
        if (monitor != null) {
            module.waitForCompletion(monitor);
            if (monitor.isCanceled()) {
                return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
            }
        } else {
            module.waitForCompletion();
        }
    }
    IStatistics<ISegment> statsTotal = fProvider.getStatsTotal();
    if (statsTotal == null) {
        return new TmfModelResponse<>(null, Status.FAILED, CommonStatusMessage.ANALYSIS_INITIALIZATION_FAILED);
    }
    List<SegmentStoreStatisticsModel> list = new ArrayList<>();
    String rootName = getRootEntryName();
    if (rootName == null) {
        rootName = getTrace().getName();
    }
    list.add(new SegmentStoreStatisticsModel(fTraceId, -1, getCellLabels(NonNullUtils.nullToEmptyString(rootName), statsTotal), statsTotal));
    /*
         * Add statistics for full duration.
         */
    long totalId = getUniqueId(TOTAL_PREFIX);
    list.add(new SegmentStoreStatisticsModel(totalId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Total), statsTotal), statsTotal));
    Map<String, IStatistics<ISegment>> totalStats = fProvider.getStatsPerType();
    for (Entry<String, IStatistics<ISegment>> entry : totalStats.entrySet()) {
        IStatistics<ISegment> statistics = entry.getValue();
        list.add(new SegmentStoreStatisticsModel(getUniqueId(TOTAL_PREFIX + entry.getKey()), totalId, getCellLabels(entry.getKey(), statistics), statistics));
    }
    /*
         * Add statistics for selection if any.
         */
    TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
    Boolean isFiltered = DataProviderParameterUtils.extractIsFiltered(fetchParameters);
    if (filter != null && isFiltered != null && isFiltered) {
        long start = filter.getStart();
        long end = filter.getEnd();
        IProgressMonitor nonNullMonitor = monitor != null ? monitor : new NullProgressMonitor();
        IStatistics<ISegment> statsForRange = fProvider.getStatsForRange(start, end, nonNullMonitor);
        if (statsForRange == null) {
            return new TmfModelResponse<>(null, Status.CANCELLED, CommonStatusMessage.TASK_CANCELLED);
        }
        long selectionId = getUniqueId(SELECTION_PREFIX);
        if (statsForRange.getNbElements() > 0) {
            list.add(new SegmentStoreStatisticsModel(selectionId, fTraceId, getCellLabels(Objects.requireNonNull(Messages.SegmentStoreStatisticsDataProvider_Selection), statsForRange), statsForRange));
            Map<String, IStatistics<ISegment>> selectionStats = fProvider.getStatsPerTypeForRange(start, end, nonNullMonitor);
            for (Entry<String, IStatistics<ISegment>> entry : selectionStats.entrySet()) {
                IStatistics<ISegment> statistics = entry.getValue();
                list.add(new SegmentStoreStatisticsModel(getUniqueId(SELECTION_PREFIX + entry.getKey()), selectionId, getCellLabels(entry.getKey(), statistics), statistics));
            }
        }
    }
    TmfTreeModel.Builder<SegmentStoreStatisticsModel> treeModelBuilder = new TmfTreeModel.Builder();
    treeModelBuilder.setColumnDescriptors(getColumnDescriptors());
    treeModelBuilder.setEntries(Collections.unmodifiableList(list));
    return new TmfModelResponse<>(treeModelBuilder.build(), Status.COMPLETED, CommonStatusMessage.COMPLETED);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SegmentStoreStatisticsModel(org.eclipse.tracecompass.analysis.timing.core.segmentstore.SegmentStoreStatisticsModel) ArrayList(java.util.ArrayList) IStatistics(org.eclipse.tracecompass.analysis.timing.core.statistics.IStatistics) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) FilterTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.FilterTimeQueryFilter) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 13 with TimeQueryFilter

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

the class XmlTimeGraphView method buildEntryList.

// ------------------------------------------------------------------------
// Internal
// ------------------------------------------------------------------------
@Override
protected void buildEntryList(ITmfTrace trace, ITmfTrace parentTrace, IProgressMonitor monitor) {
    /*
         * Get the view element from the XML file. If the element can't be found,
         * return.
         */
    Element viewElement = fViewInfo.getViewElement(TmfXmlStrings.TIME_GRAPH_VIEW);
    if (viewElement == null) {
        return;
    }
    // Empty the additional state values
    fStringValueMap.clear();
    ITimeGraphPresentationProvider pres = this.getPresentationProvider();
    if (pres instanceof XmlPresentationProvider) {
        /*
             * TODO: Each entry of a line could have their own states/color. That will
             * require an update to the presentation provider
             */
        ((XmlPresentationProvider) pres).loadNewStates(viewElement);
        Display.getDefault().asyncExec(() -> {
            TimeGraphViewer timeGraphViewer = getTimeGraphViewer();
            if (timeGraphViewer.getTimeGraphControl().isDisposed()) {
                return;
            }
            timeGraphViewer.getTimeGraphControl().colorSettingsChanged(timeGraphViewer.getTimeGraphProvider().getStateTable());
        });
    }
    String title = fViewInfo.getViewTitle(viewElement);
    setViewTitle(title != null ? title : Messages.XmlTimeGraphView_DefaultTitle);
    SubMonitor subMonitor = SubMonitor.convert(monitor);
    boolean complete = false;
    ITimeGraphDataProvider<@NonNull TimeGraphEntryModel> provider = XmlDataProviderManager.getInstance().getTimeGraphProvider(trace, viewElement);
    if (provider == null) {
        return;
    }
    while (!complete && !subMonitor.isCanceled()) {
        TmfModelResponse<TmfTreeModel<@NonNull TimeGraphEntryModel>> response = provider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), subMonitor);
        if (response.getStatus() == ITmfResponse.Status.FAILED) {
            // $NON-NLS-1$
            Activator.logError("XML Time Graph Data Provider failed: " + response.getStatusMessage());
            return;
        } else if (response.getStatus() == ITmfResponse.Status.CANCELLED) {
            return;
        }
        complete = response.getStatus() == ITmfResponse.Status.COMPLETED;
        TmfTreeModel<@NonNull TimeGraphEntryModel> model = response.getModel();
        if (model != null) {
            synchronized (fEntries) {
                /*
                     * Ensure that all the entries exist and are up to date.
                     */
                for (TimeGraphEntryModel entry : model.getEntries()) {
                    TimeGraphEntry tgEntry = fEntries.get(provider, entry.getId());
                    if (tgEntry == null) {
                        if (entry.getParentId() == -1) {
                            tgEntry = new TraceEntry(entry, trace, provider);
                            addToEntryList(parentTrace, Collections.singletonList(tgEntry));
                        } else {
                            tgEntry = new TimeGraphEntry(entry);
                        }
                        fEntries.put(provider, entry.getId(), tgEntry);
                    } else {
                        tgEntry.updateModel(entry);
                    }
                    if (entry.getParentId() == -1) {
                        setStartTime(Long.min(getStartTime(), entry.getStartTime()));
                        setEndTime(Long.max(getEndTime(), entry.getEndTime()));
                    }
                }
            }
            /*
                 * set the correct child / parent relation
                 */
            for (TimeGraphEntry child : fEntries.row(provider).values()) {
                TimeGraphEntry parent = fEntries.get(provider, child.getEntryModel().getParentId());
                if (parent != null) {
                    parent.addChild(child);
                }
            }
            long start = getStartTime();
            long end = getEndTime();
            final long resolution = Long.max(1, (end - start) / getDisplayWidth());
            zoomEntries(fEntries.row(provider).values(), start, end, resolution, subMonitor);
        }
        if (parentTrace.equals(getTrace())) {
            refresh();
        }
        subMonitor.worked(1);
        if (!complete) {
            try {
                Thread.sleep(BUILD_UPDATE_TIMEOUT);
            } catch (InterruptedException e) {
                // $NON-NLS-1$
                Activator.logError("Failed to wait for data provider", e);
            }
        }
    }
}
Also used : Element(org.w3c.dom.Element) SubMonitor(org.eclipse.core.runtime.SubMonitor) TimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeGraphEntry) ITimeGraphEntry(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry) ITimeGraphPresentationProvider(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.ITimeGraphPresentationProvider) TimeGraphEntryModel(org.eclipse.tracecompass.tmf.core.model.timegraph.TimeGraphEntryModel) NonNull(org.eclipse.jdt.annotation.NonNull) TimeGraphViewer(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer) TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)

Example 14 with TimeQueryFilter

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

the class FetchParametersTest method testSelectionTimeQuery.

/**
 * Test
 * {@link FetchParametersUtils#selectionTimeQueryToMap(SelectionTimeQueryFilter)}
 * and {@link FetchParametersUtils#createSelectionTimeQuery(Map)}
 */
@Test
public void testSelectionTimeQuery() {
    TimeQueryFilter selectionTimeQuery = FetchParametersUtils.createSelectionTimeQuery(fExpectedSelectionTimeQueryMap);
    assertNotNull(selectionTimeQuery);
    assertEquals(fExpectedSelectionTimeQuery, selectionTimeQuery);
    Map<String, Object> selectionTimeQueryMap = FetchParametersUtils.selectionTimeQueryToMap(fExpectedSelectionTimeQuery);
    assertFalse(selectionTimeQueryMap.isEmpty());
    assertEquals(fExpectedSelectionTimeQueryMap, selectionTimeQueryMap);
}
Also used : TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) SelectionTimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.SelectionTimeQueryFilter) Test(org.junit.Test)

Example 15 with TimeQueryFilter

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

the class TmfEventTableDataProviderTest method testDataProviderFetchColumn.

/**
 * Test columns returned by the provider.
 */
@Test
public void testDataProviderFetchColumn() {
    Long timestampColumnId = fColumns.get(TIMESTAMP_COLUMN_NAME);
    Long eventTypeColumnId = fColumns.get(EVENT_TYPE_COLUMN_NAME);
    Long contentsColumnId = fColumns.get(CONTENTS_COLUMN_NAME);
    Long timestampNsColumnId = fColumns.get(TIMESTAMP_NS_COLUMN_NAME);
    assertNotNull(timestampColumnId);
    assertNotNull(eventTypeColumnId);
    assertNotNull(contentsColumnId);
    assertNotNull(timestampNsColumnId);
    List<TmfEventTableColumnDataModel> expectedColumnEntries = Arrays.asList(new TmfEventTableColumnDataModel(timestampColumnId, -1, Collections.singletonList(TIMESTAMP_COLUMN_NAME), "", false), new TmfEventTableColumnDataModel(eventTypeColumnId, -1, Collections.singletonList(EVENT_TYPE_COLUMN_NAME), "The type of this event. This normally determines the field layout.", false), new TmfEventTableColumnDataModel(contentsColumnId, -1, Collections.singletonList(CONTENTS_COLUMN_NAME), "The fields (or payload) of this event", false), new TmfEventTableColumnDataModel(timestampNsColumnId, -1, Collections.singletonList(TIMESTAMP_NS_COLUMN_NAME), "Timestamp in nanoseconds, normalized and useful for calculations", true));
    TmfModelResponse<TmfTreeModel<TmfEventTableColumnDataModel>> response = fProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, 0, 1)), null);
    TmfTreeModel<TmfEventTableColumnDataModel> currentColumnModel = response.getModel();
    assertNotNull(currentColumnModel);
    List<TmfEventTableColumnDataModel> currentColumnEntries = currentColumnModel.getEntries();
    assertEquals(expectedColumnEntries, currentColumnEntries);
}
Also used : TmfTreeModel(org.eclipse.tracecompass.tmf.core.model.tree.TmfTreeModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) TmfEventTableColumnDataModel(org.eclipse.tracecompass.internal.provisional.tmf.core.model.events.TmfEventTableColumnDataModel) Test(org.junit.Test)

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