Skip to content

Commit 1f99bb8

Browse files
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]>
1 parent 6b5cb85 commit 1f99bb8

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
7575
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;
7676

77+
import com.google.common.base.Objects;
78+
7779
/**
7880
* Re-usable histogram widget.
7981
*
@@ -678,7 +680,12 @@ public void modelUpdated() {
678680
return;
679681
}
680682
fDataModel.setSelection(fSelectionBegin, fSelectionEnd);
681-
fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
683+
HistogramScaledData scaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
684+
if (Objects.equal(scaledData, fScaledData)) {
685+
return;
686+
}
687+
fScaledData = scaledData;
688+
682689
try (TraceCompassLogUtils.FlowScopeLog fs1 = new TraceCompassLogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ui").setParentScope(fs).build()) { //$NON-NLS-1$
683690
synchronized (fDataModel) {
684691
if (fScaledData != null) {

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)