Search in sources :

Example 1 with ISegmentStore

use of org.eclipse.tracecompass.segmentstore.core.ISegmentStore in project tracecompass by tracecompass.

the class AbstractSegmentStoreTableViewer method setData.

/**
 * Set the data into the viewer. It will update the model. If the provider
 * is an analysis, the analysis will be scheduled.
 *
 * @param provider
 *            segment store provider
 */
public synchronized void setData(@Nullable ISegmentStoreProvider provider) {
    // Set the current segment store provider
    fSegmentProvider = provider;
    if (provider == null) {
        updateModel(null);
        return;
    }
    createProviderColumns();
    /*
         * If the listener is null then the table is updated from another viewer.
         * Otherwise this class is responsible to load the trace.
         */
    SegmentStoreProviderProgressListener listener = fListener;
    if (listener == null) {
        return;
    }
    ISegmentStore<ISegment> segStore = provider.getSegmentStore();
    // If results are not null, then the segment of the provider is ready
    // and model can be updated
    // FIXME Filtering should be done at the data provider level
    Map<@NonNull Integer, @NonNull Predicate<@NonNull Multimap<@NonNull String, @NonNull Object>>> predicates = generateRegexPredicate();
    Predicate<ISegment> predicate = (segment) -> {
        // Get the filter external input data
        Multimap<@NonNull String, @NonNull Object> input = ISegmentStoreProvider.getFilterInput(provider, segment);
        /*
             * Test each predicates and set the status of the property
             * associated to the predicate
             */
        boolean activateProperty = false;
        for (Map.Entry<Integer, Predicate<Multimap<String, Object>>> mapEntry : predicates.entrySet()) {
            Integer property = Objects.requireNonNull(mapEntry.getKey());
            Predicate<Multimap<String, Object>> value = Objects.requireNonNull(mapEntry.getValue());
            if (property == CoreFilterProperty.DIMMED || property == CoreFilterProperty.EXCLUDE) {
                boolean status = value.test(input);
                activateProperty |= status;
            }
        }
        return activateProperty;
    };
    if (segStore != null) {
        // Cancel the current filtering job
        Job job = fFilteringJob;
        if (job != null) {
            job.cancel();
        }
        if (predicates.isEmpty()) {
            updateModel(segStore);
            return;
        }
        job = new Job(Messages.SegmentStoreTableViewer_FilteringData) {

            @Override
            protected IStatus run(@Nullable IProgressMonitor monitor) {
                try (ScopeLog log = new ScopeLog(LOGGER, Level.FINE, "SegmentStoreTable:Filtering")) {
                    // $NON-NLS-1$
                    SubMonitor subMonitor = SubMonitor.convert(monitor);
                    ISegmentStore<ISegment> filteredStore = new ArrayListStore<>();
                    for (ISegment segment : segStore) {
                        if (subMonitor.isCanceled()) {
                            return Status.CANCEL_STATUS;
                        }
                        if (predicate.test(segment)) {
                            filteredStore.add(segment);
                        }
                    }
                    if (subMonitor.isCanceled()) {
                        return Status.CANCEL_STATUS;
                    }
                    updateModel(filteredStore);
                    return Status.OK_STATUS;
                }
            }
        };
        fFilteringJob = job;
        job.schedule();
        return;
    }
    // If results are null, then add completion listener and if the provider
    // is an analysis, run the analysis
    updateModel(null);
    provider.addListener(listener);
    if (provider instanceof IAnalysisModule) {
        ((IAnalysisModule) provider).schedule();
    }
}
Also used : TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) Format(java.text.Format) TmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp) TableViewer(org.eclipse.jface.viewers.TableViewer) IAction(org.eclipse.jface.action.IAction) TableColumn(org.eclipse.swt.widgets.TableColumn) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) TmfSelectionRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal) IStatus(org.eclipse.core.runtime.IStatus) HashMultimap(com.google.common.collect.HashMultimap) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) TmfStrings(org.eclipse.tracecompass.tmf.core.TmfStrings) ArrayListStore(org.eclipse.tracecompass.internal.segmentstore.core.arraylist.ArrayListStore) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) TmfFilterAppliedSignal(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.TmfFilterAppliedSignal) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISegmentStore(org.eclipse.tracecompass.segmentstore.core.ISegmentStore) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) ImmutableSet(com.google.common.collect.ImmutableSet) ISegmentAspect(org.eclipse.tracecompass.tmf.core.segment.ISegmentAspect) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) Display(org.eclipse.swt.widgets.Display) Logger(java.util.logging.Logger) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TraceCompassLog(org.eclipse.tracecompass.common.core.log.TraceCompassLog) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Objects(java.util.Objects) ITmfTimestamp(org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) ISelection(org.eclipse.jface.viewers.ISelection) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog) Builder(com.google.common.collect.ImmutableMultimap.Builder) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TmfSignalManager(org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager) NonNull(org.eclipse.jdt.annotation.NonNull) TmfTimestampFormat(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat) Activator(org.eclipse.tracecompass.internal.analysis.timing.ui.Activator) SubMonitor(org.eclipse.core.runtime.SubMonitor) HashMap(java.util.HashMap) ITmfSourceLookup(org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup) Table(org.eclipse.swt.widgets.Table) Multimap(com.google.common.collect.Multimap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Event(org.eclipse.swt.widgets.Event) SegmentStoreContentProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider) Level(java.util.logging.Level) NonNullUtils(org.eclipse.tracecompass.common.core.NonNullUtils) TraceCompassLogUtils(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils) TmfDataModelSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfDataModelSelectedSignal) TmfSimpleTableViewer(org.eclipse.tracecompass.tmf.ui.viewers.table.TmfSimpleTableViewer) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) Messages(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.Messages) Listener(org.eclipse.swt.widgets.Listener) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) TraceCompassFilter(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filters.TraceCompassFilter) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) IAnalysisProgressListener(org.eclipse.tracecompass.analysis.timing.core.segmentstore.IAnalysisProgressListener) Job(org.eclipse.core.runtime.jobs.Job) IFilterStrings(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.IFilterStrings) IElementResolver(org.eclipse.tracecompass.tmf.core.model.timegraph.IElementResolver) DecimalFormat(java.text.DecimalFormat) FilterCu(org.eclipse.tracecompass.internal.provisional.tmf.core.model.filter.parser.FilterCu) Action(org.eclipse.jface.action.Action) OpenSourceCodeAction(org.eclipse.tracecompass.tmf.ui.actions.OpenSourceCodeAction) IMenuManager(org.eclipse.jface.action.IMenuManager) IContributionItem(org.eclipse.jface.action.IContributionItem) SelectionEvent(org.eclipse.swt.events.SelectionEvent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) CoreFilterProperty(org.eclipse.tracecompass.tmf.core.model.CoreFilterProperty) Collections(java.util.Collections) IStatus(org.eclipse.core.runtime.IStatus) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISegmentStore(org.eclipse.tracecompass.segmentstore.core.ISegmentStore) Predicate(java.util.function.Predicate) HashMultimap(com.google.common.collect.HashMultimap) Multimap(com.google.common.collect.Multimap) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Entry(java.util.Map.Entry) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) NonNull(org.eclipse.jdt.annotation.NonNull) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) Job(org.eclipse.core.runtime.jobs.Job) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog)

Example 2 with ISegmentStore

use of org.eclipse.tracecompass.segmentstore.core.ISegmentStore in project tracecompass by tracecompass.

the class AbstractSegmentStoreDensityViewer method computeData.

@Nullable
private Map<String, SegmentStoreWithRange<ISegment>> computeData(final TmfTimeRange timeRange, final AxisRange durationRange) {
    Map<String, SegmentStoreWithRange<ISegment>> retVal = new HashMap<>();
    for (Entry<String, ISegmentStoreProvider> entry : fSegmentStoreProviders.entrySet()) {
        final ISegmentStoreProvider segmentProvider = Objects.requireNonNull(entry.getValue());
        final ISegmentStore<ISegment> segStore = segmentProvider.getSegmentStore();
        if (segStore == null) {
            continue;
        }
        // Filter on the segment duration if necessary
        if (durationRange.getLower() > Double.MIN_VALUE || durationRange.getUpper() < Double.MAX_VALUE) {
            Predicate<ISegment> predicate = segment -> segment.getLength() >= durationRange.getLower() && segment.getLength() <= durationRange.getUpper();
            retVal.put(entry.getKey(), new SegmentStoreWithRange<>(segStore, timeRange, predicate));
        } else {
            retVal.put(entry.getKey(), new SegmentStoreWithRange<>(segStore, timeRange));
        }
    }
    return retVal;
}
Also used : TmfViewer(org.eclipse.tracecompass.tmf.ui.viewers.TmfViewer) PlotSymbolType(org.eclipse.swtchart.ILineSeries.PlotSymbolType) SimpleTooltipProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density2.SimpleTooltipProvider) TmfTraceOpenedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal) Arrays(java.util.Arrays) ILineSeries(org.eclipse.swtchart.ILineSeries) Format(java.text.Format) Type(org.eclipse.tracecompass.tmf.core.presentation.IYAppearance.Type) TmfTraceClosedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal) TmfTraceContext(org.eclipse.tracecompass.tmf.core.trace.TmfTraceContext) Nullable(org.eclipse.jdt.annotation.Nullable) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) ISeriesSet(org.eclipse.swtchart.ISeriesSet) TmfTraceManager(org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager) ColorRegistry(org.eclipse.jface.resource.ColorRegistry) MouseSelectionProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density2.MouseSelectionProvider) TmfTraceSelectedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal) ISegmentStore(org.eclipse.tracecompass.segmentstore.core.ISegmentStore) TmfSignalHandler(org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler) ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) Predicate(java.util.function.Predicate) NonNullUtils.nullToEmptyString(org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString) Set(java.util.Set) Display(org.eclipse.swt.widgets.Display) Objects(java.util.Objects) SubSecondTimeWithUnitFormat(org.eclipse.tracecompass.common.core.format.SubSecondTimeWithUnitFormat) List(java.util.List) Range(org.eclipse.swtchart.Range) SWT(org.eclipse.swt.SWT) Entry(java.util.Map.Entry) IYAppearance(org.eclipse.tracecompass.tmf.core.presentation.IYAppearance) Optional(java.util.Optional) SeriesType(org.eclipse.swtchart.ISeries.SeriesType) TmfTimeRange(org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange) NonNull(org.eclipse.jdt.annotation.NonNull) LineStyle(org.eclipse.swtchart.LineStyle) SegmentComparators(org.eclipse.tracecompass.segmentstore.core.SegmentComparators) SegmentStoreWithRange(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange) Chart(org.eclipse.swtchart.Chart) MouseDragZoomProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.density2.MouseDragZoomProvider) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) NonNullUtils(org.eclipse.tracecompass.common.core.NonNullUtils) HashSet(java.util.HashSet) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) IAxis(org.eclipse.swtchart.IAxis) ILegend(org.eclipse.swtchart.ILegend) IAnalysisModule(org.eclipse.tracecompass.tmf.core.analysis.IAnalysisModule) RotatingPaletteProvider(org.eclipse.tracecompass.tmf.core.presentation.RotatingPaletteProvider) RGB(org.eclipse.swt.graphics.RGB) StreamSupport(java.util.stream.StreamSupport) TimeGraphColorScheme(org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme) IAnalysisProgressListener(org.eclipse.tracecompass.analysis.timing.core.segmentstore.IAnalysisProgressListener) IBarSeries(org.eclipse.swtchart.IBarSeries) ISeries(org.eclipse.swtchart.ISeries) AxisRange(org.eclipse.tracecompass.tmf.ui.viewers.xychart.AxisRange) IImageSave(org.eclipse.tracecompass.tmf.ui.viewers.IImageSave) DoubleArraySeriesModel(org.eclipse.swtchart.model.DoubleArraySeriesModel) Color(org.eclipse.swt.graphics.Color) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) TmfWindowRangeUpdatedSignal(org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal) RGBAUtil(org.eclipse.tracecompass.tmf.ui.colors.RGBAUtil) HashMap(java.util.HashMap) ISegmentStoreProvider(org.eclipse.tracecompass.analysis.timing.core.segmentstore.ISegmentStoreProvider) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) NonNullUtils.nullToEmptyString(org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString) SegmentStoreWithRange(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider.SegmentStoreWithRange) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 3 with ISegmentStore

use of org.eclipse.tracecompass.segmentstore.core.ISegmentStore in project tracecompass by tracecompass.

the class AbstractSegmentStoreTableViewer method updateModel.

/**
 * Update the data in the table viewer
 *
 * @param dataInput
 *            New data input
 */
public void updateModel(@Nullable final Object dataInput) {
    final TableViewer tableViewer = getTableViewer();
    Display.getDefault().asyncExec(() -> {
        try (ScopeLog sl = new ScopeLog(LOGGER, Level.FINE, "updateModel")) {
            // $NON-NLS-1$
            if (!tableViewer.getTable().isDisposed()) {
                // Go to the top of the table
                tableViewer.getTable().setTopIndex(0);
                ISelection selection = tableViewer.getSelection();
                ISegment selected = null;
                if (!selection.isEmpty() && selection instanceof StructuredSelection) {
                    Object firstElement = ((StructuredSelection) selection).getFirstElement();
                    if (firstElement instanceof ISegment) {
                        selected = (ISegment) firstElement;
                    }
                }
                // Reset selected row
                if (dataInput == null) {
                    tableViewer.setSelection(StructuredSelection.EMPTY);
                    tableViewer.setInput(null);
                    tableViewer.setItemCount(0);
                    return;
                }
                addPackListener();
                tableViewer.setInput(dataInput);
                SegmentStoreContentProvider contentProvider = (SegmentStoreContentProvider) getTableViewer().getContentProvider();
                long segmentCount = contentProvider.getSegmentCount();
                String contentProviderName = contentProvider.getClass().getSimpleName();
                // $NON-NLS-1$
                TraceCompassLogUtils.traceCounter(LOGGER, Level.FINE, "SegmentStoreTableViewer#updateModel", contentProviderName, segmentCount);
                if (segmentCount > MAX_ITEMS) {
                    tableViewer.setItemCount(MAX_ITEMS);
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    Activator.getDefault().logWarning("Too many items to display for " + contentProviderName + ". Cannot display " + segmentCount + " in a reasonable timeframe.");
                } else {
                    tableViewer.setItemCount((int) segmentCount);
                }
                boolean found = false;
                if (selected != null && dataInput instanceof ISegmentStore<?>) {
                    ISegmentStore<?> store = (ISegmentStore<?>) dataInput;
                    for (ISegment segment : store.getIntersectingElements(selected.getEnd())) {
                        if (isSameish(segment, selected)) {
                            selection = new StructuredSelection(segment);
                            tableViewer.setSelection(selection, true);
                            found = true;
                            break;
                        }
                    }
                }
                if (!found) {
                    tableViewer.setSelection(StructuredSelection.EMPTY);
                }
            }
        }
    });
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ISegment(org.eclipse.tracecompass.segmentstore.core.ISegment) ISegmentStore(org.eclipse.tracecompass.segmentstore.core.ISegmentStore) TableViewer(org.eclipse.jface.viewers.TableViewer) TmfSimpleTableViewer(org.eclipse.tracecompass.tmf.ui.viewers.table.TmfSimpleTableViewer) ScopeLog(org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog) SegmentStoreContentProvider(org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.table.SegmentStoreContentProvider)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Format (java.text.Format)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2 NonNull (org.eclipse.jdt.annotation.NonNull)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 SWT (org.eclipse.swt.SWT)2 Display (org.eclipse.swt.widgets.Display)2 ISegment (org.eclipse.tracecompass.segmentstore.core.ISegment)2 ISegmentStore (org.eclipse.tracecompass.segmentstore.core.ISegmentStore)2 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1