Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmf.ui: instrument histogram #181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +51,9 @@
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.common.core.log.TraceCompassLogUtils;
import org.eclipse.tracecompass.common.core.log.TraceCompassLogUtils.ScopeLog;
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;
Expand All @@ -68,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 @@ -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

Expand Down Expand Up @@ -250,7 +259,6 @@ public abstract class Histogram implements ControlListener, PaintListener, KeyLi
*/
static boolean showTraces = true;


private boolean fSendTimeAlignSignals = false;

private IStatusLineManager fStatusLineManager;
Expand Down Expand Up @@ -655,17 +663,30 @@ 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 (TraceCompassLogUtils.FlowScopeLog fs = new TraceCompassLogUtils.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 (TraceCompassLogUtils.FlowScopeLog fs1 = new TraceCompassLogUtils.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;
}
fDataModel.setSelection(fSelectionBegin, fSelectionEnd);
fScaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
}

if (canvasHeight <= 0 || canvasWidth <= 0) {
return;
}
fDataModel.setSelection(fSelectionBegin, fSelectionEnd);
HistogramScaledData scaledData = fDataModel.scaleTo(canvasWidth, canvasHeight, 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be traced as well?

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) {
fCanvas.redraw();
Expand All @@ -679,16 +700,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();
}
}
});
}
});
}
}
}

Expand Down Expand Up @@ -786,7 +807,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
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;
}
}
Loading