timing.ui: Add dirty conditions for SWTbot to scatter graph viewer
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Wed, 26 Oct 2016 19:00:11 +0000 (15:00 -0400)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 1 Nov 2016 16:45:18 +0000 (12:45 -0400)
Also remove a calls to update

Change-Id: Ifbf37b3dda4f1ebcea065adfba08f2f2ab14f6c1
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/83964
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/scatter/AbstractSegmentStoreScatterGraphViewer.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java

index 8322bed9ce1440fdfbae983efd76b6c50d437eca..e55fbe0780e7a09fec3144c9c7e3b988c6a592db 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -66,6 +67,8 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
 
     private static final Format FORMAT = new SubSecondTimeWithUnitFormat();
 
+    private final AtomicInteger fDirty = new AtomicInteger();
+
     private final class CompactingSegmentStoreQuery extends Job {
         private static final long MAX_POINTS = 1000;
         private final TmfTimeRange fCurrentRange;
@@ -78,52 +81,70 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
         @Override
         protected IStatus run(@Nullable IProgressMonitor monitor) {
             final IProgressMonitor statusMonitor = monitor;
-            if (statusMonitor == null) {
-                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Monitor is null"); //$NON-NLS-1$
-            }
+            try {
+                if (statusMonitor == null) {
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Monitor is null"); //$NON-NLS-1$
+                }
 
-            ISegmentStoreProvider segmentProvider = getSegmentProvider();
-            final long startTimeInNanos = fCurrentRange.getStartTime().toNanos();
-            final long endTimeInNanos = fCurrentRange.getEndTime().toNanos();
-            if (segmentProvider == null) {
-                setWindowRange(startTimeInNanos, endTimeInNanos);
-                redraw(statusMonitor, startTimeInNanos, startTimeInNanos, Collections.EMPTY_LIST);
-                return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "segment provider not available"); //$NON-NLS-1$
-            }
+                ISegmentStoreProvider segmentProvider = getSegmentProvider();
+                final long startTimeInNanos = fCurrentRange.getStartTime().toNanos();
+                final long endTimeInNanos = fCurrentRange.getEndTime().toNanos();
+                if (segmentProvider == null) {
+                    setWindowRange(startTimeInNanos, endTimeInNanos);
+                    redraw(statusMonitor, startTimeInNanos, startTimeInNanos, Collections.EMPTY_LIST);
+                    return new Status(IStatus.WARNING, Activator.PLUGIN_ID, "segment provider not available"); //$NON-NLS-1$
+                }
 
-            final ISegmentStore<ISegment> segStore = segmentProvider.getSegmentStore();
-            if (segStore == null) {
-                setWindowRange(startTimeInNanos, endTimeInNanos);
-                redraw(statusMonitor, startTimeInNanos, startTimeInNanos, Collections.EMPTY_LIST);
-                return new Status(IStatus.INFO, Activator.PLUGIN_ID, "Segment provider does not have segments"); //$NON-NLS-1$
-            }
+                final ISegmentStore<ISegment> segStore = segmentProvider.getSegmentStore();
+                if (segStore == null) {
+                    setWindowRange(startTimeInNanos, endTimeInNanos);
+                    redraw(statusMonitor, startTimeInNanos, startTimeInNanos, Collections.EMPTY_LIST);
+                    return new Status(IStatus.INFO, Activator.PLUGIN_ID, "Segment provider does not have segments"); //$NON-NLS-1$
+                }
 
-            final long startTime = fCurrentRange.getStartTime().getValue();
-            final long endTime = fCurrentRange.getEndTime().getValue();
-            fPixelStart = startTime;
-            fPixelSize = Math.max(1, (endTime - startTime) / MAX_POINTS);
-            final Iterable<ISegment> intersectingElements = segStore.getIntersectingElements(startTime, endTime);
+                final long startTime = fCurrentRange.getStartTime().getValue();
+                final long endTime = fCurrentRange.getEndTime().getValue();
+                fPixelStart = startTime;
+                fPixelSize = Math.max(1, (endTime - startTime) / MAX_POINTS);
+                final Iterable<ISegment> intersectingElements = segStore.getIntersectingElements(startTime, endTime);
 
-            final List<ISegment> list = convertIterableToList(intersectingElements, statusMonitor);
-            final List<ISegment> displayData = (!list.isEmpty()) ? compactList(startTime, list, statusMonitor) : list;
+                final List<ISegment> list = convertIterableToList(intersectingElements, statusMonitor);
+                final List<ISegment> displayData = (!list.isEmpty()) ? compactList(startTime, list, statusMonitor) : list;
 
-            setWindowRange(startTimeInNanos, endTimeInNanos);
-            redraw(statusMonitor, startTime, endTime, displayData);
+                setWindowRange(startTimeInNanos, endTimeInNanos);
+                redraw(statusMonitor, startTime, endTime, displayData);
 
-            if (statusMonitor.isCanceled()) {
-                return Status.CANCEL_STATUS;
+                if (statusMonitor.isCanceled()) {
+                    return Status.CANCEL_STATUS;
+                }
+                return Status.OK_STATUS;
+            } finally {
+                /*
+                 * fDirty should have been incremented before creating a job, so
+                 * we decrement it once the job is done
+                 */
+                fDirty.decrementAndGet();
             }
-            return Status.OK_STATUS;
 
         }
 
         private void redraw(final IProgressMonitor statusMonitor, final long startTime, final long endTime, final List<ISegment> displayData) {
             fDisplayData = displayData;
+            /*
+             * Increment at every redraw, since the content of the view is not
+             * current
+             */
+            fDirty.incrementAndGet();
             Display.getDefault().asyncExec(new Runnable() {
 
                 @Override
                 public void run() {
-                    updateData(startTime, endTime, displayData.size(), statusMonitor);
+                    try {
+                        updateData(startTime, endTime, displayData.size(), statusMonitor);
+                    } finally {
+                        /* Decrement once the redraw is done */
+                        fDirty.decrementAndGet();
+                    }
                 }
             });
         }
@@ -195,7 +216,6 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
             // Only update the model if trace that was analyzed is active trace
             if (segmentProvider.equals(getSegmentProvider())) {
                 updateModel(segmentStore);
-                updateRange(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange());
             }
         }
     }
@@ -252,7 +272,6 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
             if (segmentStoreProvider != null) {
                 segmentStoreProvider.addListener(fListener);
                 setData(segmentStoreProvider);
-                updateRange(TmfTraceManager.getInstance().getCurrentTraceContext().getWindowRange());
             }
         }
     }
@@ -436,6 +455,11 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
     }
 
     private void updateRange(final @Nullable TmfTimeRange timeRange) {
+        /*
+         * Update is request, content is not up to date, fDirty will be
+         * decremented in the compacting job
+         */
+        fDirty.incrementAndGet();
         Job compactingJob = fCompactingJob;
         if (compactingJob != null && compactingJob.getState() == Job.RUNNING) {
             compactingJob.cancel();
@@ -492,4 +516,10 @@ public abstract class AbstractSegmentStoreScatterGraphViewer extends TmfCommonXL
     private void setSegmentProvider(ISegmentStoreProvider provider) {
         fSegmentProvider = provider;
     }
+
+    @Override
+    public boolean isDirty() {
+        /* Check the parent's or this view's own dirtiness */
+        return super.isDirty() || (fDirty.get() != 0);
+    }
 }
\ No newline at end of file
index a53bdf98a87b95ef259d1415443f78737a71f78e..8f55d8be08a65a1c0301a247b622545f7bd6fd33 100644 (file)
@@ -73,7 +73,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     private UpdateThread fUpdateThread;
 
-    private volatile AtomicInteger fDirty = new AtomicInteger();
+    private final AtomicInteger fDirty = new AtomicInteger();
 
     /**
      * Constructor
@@ -137,6 +137,7 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
      */
     protected void reinitialize() {
         fSeriesValues.clear();
+        /* Initializing data: the content is not current */
         fDirty.incrementAndGet();
         Thread thread = new Thread() {
             // Don't use TmfUiRefreshHandler (bug 467751)
@@ -150,9 +151,13 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                         public void run() {
                             if (!getSwtChart().isDisposed()) {
                                 /* Delete the old series */
-                                clearContent();
-                                createSeries();
-                                fDirty.decrementAndGet();
+                                try {
+                                    clearContent();
+                                    createSeries();
+                                } finally {
+                                    /* View is cleared, decrement fDirty */
+                                    fDirty.decrementAndGet();
+                                }
                             }
                         }
                     });
@@ -189,9 +194,16 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
                 @Override
                 public void run() {
                     LOGGER.info(() -> getLogMessage("UpdateDataStart", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
-                    updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
-                    fDirty.decrementAndGet();
-                    LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
+                    try {
+                        updateData(getWindowStartTime(), getWindowEndTime(), fNumRequests, fMonitor);
+                    } finally {
+                        /*
+                         * fDirty should have been incremented before creating
+                         * the thread, so we decrement it once it is finished
+                         */
+                        fDirty.decrementAndGet();
+                        LOGGER.info(() -> getLogMessage("UpdateDataEnd", "tid=" + getId())); //$NON-NLS-1$ //$NON-NLS-2$
+                    }
                 }
             });
             updateThreadFinished(this);
@@ -233,6 +245,10 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     @Override
     protected void updateContent() {
+        /*
+         * Content is not up to date, so we increment fDirty. It will be
+         * decremented at the end of the update thread
+         */
         fDirty.incrementAndGet();
         getDisplay().asyncExec(new Runnable() {
             @Override
@@ -375,52 +391,63 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
      * Update the chart's values before refreshing the viewer
      */
     protected void updateDisplay() {
+        /* Content is not up to date, increment dirtiness */
+        fDirty.incrementAndGet();
         Display.getDefault().asyncExec(new Runnable() {
             final TmfChartTimeStampFormat tmfChartTimeStampFormat = new TmfChartTimeStampFormat(getTimeOffset());
 
             @Override
             public void run() {
-                if (!getSwtChart().isDisposed()) {
-                    double[] xValues = fXValues;
-                    double maxy = DEFAULT_MAXY;
-                    double miny = DEFAULT_MINY;
-                    for (Entry<String, double[]> entry : fSeriesValues.entrySet()) {
-                        ILineSeries series = (ILineSeries) getSwtChart().getSeriesSet().getSeries(entry.getKey());
-                        if (series == null) {
-                            series = addSeries(entry.getKey());
+                try {
+                    if (!getSwtChart().isDisposed()) {
+                        double[] xValues = fXValues;
+                        double maxy = DEFAULT_MAXY;
+                        double miny = DEFAULT_MINY;
+                        for (Entry<String, double[]> entry : fSeriesValues.entrySet()) {
+                            ILineSeries series = (ILineSeries) getSwtChart().getSeriesSet().getSeries(entry.getKey());
+                            if (series == null) {
+                                series = addSeries(entry.getKey());
+                            }
+                            series.setXSeries(xValues);
+                            /*
+                             * Find the minimal and maximum values in this
+                             * series
+                             */
+                            for (double value : entry.getValue()) {
+                                maxy = Math.max(maxy, value);
+                                miny = Math.min(miny, value);
+                            }
+                            series.setYSeries(entry.getValue());
                         }
-                        series.setXSeries(xValues);
-                        /* Find the minimal and maximum values in this series */
-                        for (double value : entry.getValue()) {
-                            maxy = Math.max(maxy, value);
-                            miny = Math.min(miny, value);
+                        if (maxy == DEFAULT_MAXY) {
+                            maxy = 1.0;
                         }
-                        series.setYSeries(entry.getValue());
-                    }
-                    if (maxy == DEFAULT_MAXY) {
-                        maxy = 1.0;
-                    }
 
-                    IAxisTick xTick = getSwtChart().getAxisSet().getXAxis(0).getTick();
-                    xTick.setFormat(tmfChartTimeStampFormat);
+                        IAxisTick xTick = getSwtChart().getAxisSet().getXAxis(0).getTick();
+                        xTick.setFormat(tmfChartTimeStampFormat);
 
-                    final double start = 0.0;
-                    double end = getWindowEndTime() - getWindowStartTime();
-                    getSwtChart().getAxisSet().getXAxis(0).setRange(new Range(start, end));
-                    if (maxy > miny) {
-                        getSwtChart().getAxisSet().getYAxis(0).setRange(new Range(miny, maxy));
-                    }
-                    getSwtChart().redraw();
-
-                    if (isSendTimeAlignSignals()) {
-                        // The width of the chart might have changed and its
-                        // time axis might be misaligned with the other views
-                        Point viewPos = TmfCommonXLineChartViewer.this.getParent().getParent().toDisplay(0, 0);
-                        int axisPos = getSwtChart().toDisplay(0, 0).x + getPointAreaOffset();
-                        int timeAxisOffset = axisPos - viewPos.x;
-                        TmfTimeViewAlignmentInfo timeAlignmentInfo = new TmfTimeViewAlignmentInfo(getControl().getShell(), viewPos, timeAxisOffset);
-                        TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(TmfCommonXLineChartViewer.this, timeAlignmentInfo, true));
+                        final double start = 0.0;
+                        double end = getWindowEndTime() - getWindowStartTime();
+                        getSwtChart().getAxisSet().getXAxis(0).setRange(new Range(start, end));
+                        if (maxy > miny) {
+                            getSwtChart().getAxisSet().getYAxis(0).setRange(new Range(miny, maxy));
+                        }
+                        getSwtChart().redraw();
+
+                        if (isSendTimeAlignSignals()) {
+                            // The width of the chart might have changed and its
+                            // time axis might be misaligned with the other
+                            // views
+                            Point viewPos = TmfCommonXLineChartViewer.this.getParent().getParent().toDisplay(0, 0);
+                            int axisPos = getSwtChart().toDisplay(0, 0).x + getPointAreaOffset();
+                            int timeAxisOffset = axisPos - viewPos.x;
+                            TmfTimeViewAlignmentInfo timeAlignmentInfo = new TmfTimeViewAlignmentInfo(getControl().getShell(), viewPos, timeAxisOffset);
+                            TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(TmfCommonXLineChartViewer.this, timeAlignmentInfo, true));
+                        }
                     }
+                } finally {
+                    /* Content has been updated, decrement dirtiness */
+                    fDirty.decrementAndGet();
                 }
             }
         });
@@ -444,14 +471,8 @@ public abstract class TmfCommonXLineChartViewer extends TmfXYChartViewer {
 
     @Override
     public boolean isDirty() {
-        boolean dirty = super.isDirty();
-
-        if (dirty) {
-            return dirty;
-        }
-
-        // Check the specific dirtiness of this view
-        return fDirty.get() != 0;
+        /* Check the parent's or this view's own dirtiness */
+        return super.isDirty() || (fDirty.get() != 0);
     }
 
 }
This page took 0.031683 seconds and 5 git commands to generate.