Skip to content

Commit

Permalink
tmf.ui: Add early exit to Histogram
Browse files Browse the repository at this point in the history
Speed up histogram by not redrawing when the data is unchanged.

Change-Id: Iea05f628da6e1baea4fd0be3b6071f363099c9bb
Signed-off-by: Matthew Khouzam <[email protected]>
  • Loading branch information
MatthewKhouzam committed Nov 19, 2024
1 parent 6b5cb85 commit 1f99bb8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphColorScheme;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.TimeGraphScale;

import com.google.common.base.Objects;

/**
* Re-usable histogram widget.
*
Expand Down Expand Up @@ -678,7 +680,12 @@ public void modelUpdated() {
return;
}
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 (TraceCompassLogUtils.FlowScopeLog fs1 = new TraceCompassLogUtils.FlowScopeLogBuilder(LOGGER, Level.FINER, "Histogram:ui").setParentScope(fs).build()) { //$NON-NLS-1$
synchronized (fDataModel) {
if (fScaledData != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 1f99bb8

Please sign in to comment.