Skip to content

Commit d78e522

Browse files
MatthewKhouzamarfio
authored andcommitted
tmf.ui: Add early exit to Histogram
Speed up histogram by not redrawing when the data is unchanged. Change-Id: Iea05f628da6e1baea4fd0be3b6071f363099c9bb Signed-off-by: Matthew Khouzam <[email protected]> Signed-off-by: Arnaud Fiorini <[email protected]>
1 parent f90eaea commit d78e522

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/Histogram.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import org.eclipse.swt.widgets.Display;
5353
import org.eclipse.swt.widgets.Label;
5454
import org.eclipse.tracecompass.common.core.log.TraceCompassLog;
55-
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils;
56-
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog;
5755
import org.eclipse.tracecompass.internal.tmf.ui.views.histogram.HistogramTimeAdapter;
5856
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
5957
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager;
@@ -73,6 +71,10 @@
7371
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.ITimeDataProvider;
7472
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
7573
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
74+
import org.eclipse.tracecompass.traceeventlogger.LogUtils;
75+
import org.eclipse.tracecompass.traceeventlogger.LogUtils.ScopeLog;
76+
77+
import com.google.common.base.Objects;
7678

7779
/**
7880
* Re-usable histogram widget.
@@ -661,12 +663,12 @@ protected void moveCursor(final int keyCode) {
661663
*/
662664
@Override
663665
public void modelUpdated() {
664-
try (TraceCompassLogUtils.FlowScopeLog fs = new TraceCompassLogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ModelUpdated").setCategory("Histogram").build()) { //$NON-NLS-1$ //$NON-NLS-2$
666+
try (LogUtils.FlowScopeLog fs = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ModelUpdated").setCategory("Histogram").build()) { //$NON-NLS-1$ //$NON-NLS-2$
665667
if (!fCanvas.isDisposed() && fCanvas.getDisplay() != null) {
666668
fCanvas.getDisplay().asyncExec(() -> {
667669
int canvasWidth = -1;
668670
int canvasHeight = -1;
669-
try (TraceCompassLogUtils.FlowScopeLog fs1 = new TraceCompassLogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:getbounds").setParentScope(fs).build()) { //$NON-NLS-1$
671+
try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:getBounds").setParentScope(fs).build()) { //$NON-NLS-1$
670672
if (!fCanvas.isDisposed()) {
671673
// Retrieve and normalize the data
672674
canvasWidth = fCanvas.getBounds().width;
@@ -678,8 +680,14 @@ public void modelUpdated() {
678680
return;
679681
}
680682
fDataModel.setSelection(fSelectionBegin, fSelectionEnd);
681-
fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
682-
try (TraceCompassLogUtils.FlowScopeLog fs1 = new TraceCompassLogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ui").setParentScope(fs).build()) { //$NON-NLS-1$
683+
try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:scaleData").setParentScope(fs).build()) { //$NON-NLS-1$
684+
HistogramScaledData scaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
685+
if (Objects.equal(scaledData, fScaledData)) {
686+
return;
687+
}
688+
fScaledData = scaledData;
689+
}
690+
try (LogUtils.FlowScopeLog fs1 = new LogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:redraw").setParentScope(fs).build()) { //$NON-NLS-1$
683691
synchronized (fDataModel) {
684692
if (fScaledData != null) {
685693
fCanvas.redraw();

tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/views/histogram/HistogramScaledData.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.eclipse.tracecompass.tmf.ui.views.histogram;
2121

2222
import java.util.Arrays;
23+
import java.util.Objects;
2324

2425
/**
2526
* Convenience class/struct for scaled histogram data.
@@ -232,4 +233,33 @@ private int getOffsetIndex(int index) {
232233
public long getBucketEndTime(int index) {
233234
return getBucketStartTime(index + 1);
234235
}
236+
237+
@Override
238+
public int hashCode() {
239+
final int prime = 31;
240+
int result = 1;
241+
result = prime * result + Arrays.hashCode(fData);
242+
result = prime * result + Arrays.hashCode(fLostEventsData);
243+
result = prime * result
244+
+ Objects.hash(fBarWidth, fBucketDuration, fFirstBucketTime, fFirstEventTime, fHeight, fLastBucket, fMaxCombinedValue, fMaxValue, fScalingFactor, fScalingFactorCombined, fSelectionBeginBucket, fSelectionEndBucket, fWidth);
245+
return result;
246+
}
247+
248+
@Override
249+
public boolean equals(Object obj) {
250+
if (this == obj) {
251+
return true;
252+
}
253+
if (obj == null) {
254+
return false;
255+
}
256+
if (getClass() != obj.getClass()) {
257+
return false;
258+
}
259+
HistogramScaledData other = (HistogramScaledData) obj;
260+
return fBarWidth == other.fBarWidth && Double.doubleToLongBits(fBucketDuration) == Double.doubleToLongBits(other.fBucketDuration) && Arrays.equals(fData, other.fData) && fFirstBucketTime == other.fFirstBucketTime
261+
&& fFirstEventTime == other.fFirstEventTime && fHeight == other.fHeight && fLastBucket == other.fLastBucket && Arrays.equals(fLostEventsData, other.fLostEventsData) && fMaxCombinedValue == other.fMaxCombinedValue
262+
&& fMaxValue == other.fMaxValue && Double.doubleToLongBits(fScalingFactor) == Double.doubleToLongBits(other.fScalingFactor) && Double.doubleToLongBits(fScalingFactorCombined) == Double.doubleToLongBits(other.fScalingFactorCombined)
263+
&& fSelectionBeginBucket == other.fSelectionBeginBucket && fSelectionEndBucket == other.fSelectionEndBucket && fWidth == other.fWidth;
264+
}
235265
}

0 commit comments

Comments
 (0)