From e18d40d0604c06dbf62f0af4eeed910c28526c41 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Genevi=C3=A8ve=20Bastien?= Date: Wed, 26 Oct 2016 15:00:11 -0400 Subject: [PATCH] timing.ui: Add dirty conditions for SWTbot to scatter graph viewer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also remove a calls to update Change-Id: Ifbf37b3dda4f1ebcea065adfba08f2f2ab14f6c1 Signed-off-by: Geneviève Bastien Reviewed-on: https://git.eclipse.org/r/83964 Reviewed-by: Hudson CI Reviewed-by: Matthew Khouzam --- ...bstractSegmentStoreScatterGraphViewer.java | 94 ++++++++----- .../linecharts/TmfCommonXLineChartViewer.java | 123 ++++++++++-------- 2 files changed, 134 insertions(+), 83 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/scatter/AbstractSegmentStoreScatterGraphViewer.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/scatter/AbstractSegmentStoreScatterGraphViewer.java index 8322bed9ce..e55fbe0780 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/scatter/AbstractSegmentStoreScatterGraphViewer.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/scatter/AbstractSegmentStoreScatterGraphViewer.java @@ -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 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 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 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 intersectingElements = segStore.getIntersectingElements(startTime, endTime); - final List list = convertIterableToList(intersectingElements, statusMonitor); - final List displayData = (!list.isEmpty()) ? compactList(startTime, list, statusMonitor) : list; + final List list = convertIterableToList(intersectingElements, statusMonitor); + final List 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 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 diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java index a53bdf98a8..8f55d8be08 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/xycharts/linecharts/TmfCommonXLineChartViewer.java @@ -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 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 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); } } -- 2.34.1