diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/Histogram.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/Histogram.java index aacc606509..0ef524eff4 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/Histogram.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/Histogram.java @@ -18,6 +18,9 @@ package org.eclipse.tracecompass.tmf.ui.views.histogram; +import java.util.logging.Level; +import java.util.logging.Logger; + import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jface.action.IStatusLineManager; import org.eclipse.jface.layout.GridDataFactory; @@ -48,6 +51,7 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; +import org.eclipse.tracecompass.common.core.log.TraceCompassLog; import org.eclipse.tracecompass.internal.tmf.ui.views.histogram.HistogramTimeAdapter; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; @@ -67,6 +71,10 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider; import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme; import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale; +import org.eclipse.tracecompass.traceeventlogger.LogUtils; +import org.eclipse.tracecompass.traceeventlogger.LogUtils.ScopeLog; + +import com.google.common.base.Objects; /** * Re-usable histogram widget. @@ -110,6 +118,7 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi // ------------------------------------------------------------------------ private static final int TIME_SCALE_HEIGHT = 27; + private static final Logger LOGGER = TraceCompassLog.getLogger(Histogram.class); // Histogram colors @@ -250,7 +259,6 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi */ static boolean showTraces = true; - private boolean fSendTimeAlignSignals = false; private IStatusLineManager fStatusLineManager; @@ -655,17 +663,31 @@ protected void moveCursor(final int keyCode) { */ @Override public void modelUpdated() { - if (!fCanvas.isDisposed() && fCanvas.getDisplay() != null) { - fCanvas.getDisplay().asyncExec(() -> { - if (!fCanvas.isDisposed()) { - // Retrieve and normalize the data - final int canvasWidth = fCanvas.getBounds().width; - final int canvasHeight = fCanvas.getBounds().height; - if (canvasWidth <= 0 || canvasHeight <= 0) { - return; + try (LogUtils.FlowScopeLog fs = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ModelUpdated").setCategory("Histogram").build()) { //$NON-NLS-1$ //$NON-NLS-2$ + if (!fCanvas.isDisposed() && fCanvas.getDisplay() != null) { + fCanvas.getDisplay().asyncExec(() -> { + int canvasWidth = -1; + int canvasHeight = -1; + try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:getBounds").setParentScope(fs).build()) { //$NON-NLS-1$ + if (!fCanvas.isDisposed()) { + // Retrieve and normalize the data + canvasWidth = fCanvas.getBounds().width; + canvasHeight = fCanvas.getBounds().height; } + } + + if (canvasHeight <= 0 || canvasWidth <= 0) { + return; + } + try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:scaleData").setParentScope(fs).build()) { //$NON-NLS-1$ fDataModel.setSelection(fSelectionBegin, fSelectionEnd); - fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1); + HistogramScaledData scaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1); + if (Objects.equal(scaledData, fScaledData)) { + return; + } + fScaledData = scaledData; + } + try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:redraw").setParentScope(fs).build()) { //$NON-NLS-1$ synchronized (fDataModel) { if (fScaledData != null) { fCanvas.redraw(); @@ -679,16 +701,16 @@ public void modelUpdated() { GridData gd = (GridData) fMaxNbEventsLabel.getLayoutData(); gd.widthHint = Math.max(gd.widthHint, fMaxNbEventsLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x); fMaxNbEventsLabel.getParent().layout(); - if (old.length() < fMaxNbEventsLabel.getText().length()) { - if ((fSendTimeAlignSignals) && (fParentView instanceof ITmfTimeAligned)) { - TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(this, ((ITmfTimeAligned) fParentView).getTimeViewAlignmentInfo(), true)); - } + if (old.length() < fMaxNbEventsLabel.getText().length() && (fSendTimeAlignSignals) && (fParentView instanceof ITmfTimeAligned)) { + TmfSignalManager.dispatchSignal(new TmfTimeViewAlignmentSignal(this, ((ITmfTimeAligned) fParentView).getTimeViewAlignmentInfo(), true)); } + } fTimeLineScale.redraw(); } - } - }); + } + }); + } } } @@ -786,7 +808,7 @@ private void formatImage(final GC imageGC, final Image image) { final HistogramScaledData scaledData = new HistogramScaledData(fScaledData); - try { + try (ScopeLog sl = new ScopeLog(LOGGER, Level.FINER, "Histogram:FmtImg")) { //$NON-NLS-1$ final int height = image.getBounds().height; // Clear the drawing area diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramScaledData.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramScaledData.java index 9b232de374..8908e55961 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramScaledData.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramScaledData.java @@ -20,6 +20,7 @@ package org.eclipse.tracecompass.tmf.ui.views.histogram; import java.util.Arrays; +import java.util.Objects; /** * Convenience class/struct for scaled histogram data. @@ -232,4 +233,33 @@ private int getOffsetIndex(int index) { public long getBucketEndTime(int index) { return getBucketStartTime(index + 1); } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Arrays.hashCode(fData); + result = prime * result + Arrays.hashCode(fLostEventsData); + result = prime * result + + Objects.hash(fBarWidth, fBucketDuration, fFirstBucketTime, fFirstEventTime, fHeight, fLastBucket, fMaxCombinedValue, fMaxValue, fScalingFactor, fScalingFactorCombined, fSelectionBeginBucket, fSelectionEndBucket, fWidth); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + HistogramScaledData other = (HistogramScaledData) obj; + return fBarWidth == other.fBarWidth && Double.doubleToLongBits(fBucketDuration) == Double.doubleToLongBits(other.fBucketDuration) && Arrays.equals(fData, other.fData) && fFirstBucketTime == other.fFirstBucketTime + && fFirstEventTime == other.fFirstEventTime && fHeight == other.fHeight && fLastBucket == other.fLastBucket && Arrays.equals(fLostEventsData, other.fLostEventsData) && fMaxCombinedValue == other.fMaxCombinedValue + && fMaxValue == other.fMaxValue && Double.doubleToLongBits(fScalingFactor) == Double.doubleToLongBits(other.fScalingFactor) && Double.doubleToLongBits(fScalingFactorCombined) == Double.doubleToLongBits(other.fScalingFactorCombined) + && fSelectionBeginBucket == other.fSelectionBeginBucket && fSelectionEndBucket == other.fSelectionEndBucket && fWidth == other.fWidth; + } }