From 1f99bb842773e8852afded85d35586bbf13fa825 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Tue, 19 Nov 2024 10:47:23 -0500 Subject: [PATCH] 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 --- .../tmf/ui/views/histogram/Histogram.java | 9 +++++- .../views/histogram/HistogramScaledData.java | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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 6652409ffe..975a09cb2e 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 @@ -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. * @@ -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) { 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; + } }