From a0acb04438cd5357bae1e9746f07fc60df060981 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Thu, 7 Jan 2016 16:05:36 -0500 Subject: [PATCH] analysis: make statistics show standard deviation Also format time in a readable manner. Warning, this changes the behavior of HumanReadibleTimeFormat. It now shows its decimals all the time. Change-Id: If810ed09462fdaa09924945a2e5930debd7990e5 Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/63788 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- .../ui/views/latency/statistics/Messages.java | 1 - .../SubSecondTimeWithUnitFormat.java | 8 ++-- .../AbstractSegmentStoreStatisticsViewer.java | 47 +++++++++++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java index 7b00ec3de9..be973d1826 100644 --- a/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java +++ b/analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java @@ -23,7 +23,6 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.tracecompass.internal.analysis.os.linux.ui.views.latency.statistics.messages"; //$NON-NLS-1$ - /** Name of the system call level in statistics tree */ public static String LatencyStatistics_SyscallLevelName; /** Name of Total statistics */ diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/SubSecondTimeWithUnitFormat.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/SubSecondTimeWithUnitFormat.java index 5631c26196..a04a3ea3ff 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/SubSecondTimeWithUnitFormat.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/SubSecondTimeWithUnitFormat.java @@ -31,7 +31,6 @@ import org.eclipse.tracecompass.common.core.NonNullUtils; */ public final class SubSecondTimeWithUnitFormat extends Format { - private static final long serialVersionUID = -5147827135781459548L; private static final String SECONDS = "s"; //$NON-NLS-1$ @@ -43,7 +42,7 @@ public final class SubSecondTimeWithUnitFormat extends Format { private static final int NANOS_PER_MILLI = 1000000; private static final int NANOS_PER_MICRO = 1000; - private final DecimalFormat fDecimalFormat = new DecimalFormat("#.###"); //$NON-NLS-1$ + private final DecimalFormat fDecimalFormat = new DecimalFormat("#.000"); //$NON-NLS-1$ @Override public Object parseObject(@Nullable String source, @Nullable ParsePosition pos) { @@ -55,6 +54,9 @@ public final class SubSecondTimeWithUnitFormat extends Format { final @Nullable StringBuffer appender = toAppendTo; if ((obj != null) && (obj instanceof Double || obj instanceof Long)) { double formattedTime = obj instanceof Long ? ((Long) obj).doubleValue() : ((Double) obj).doubleValue(); + if (Double.isNaN(formattedTime)) { + return appender == null ? new StringBuffer() : NonNullUtils.checkNotNull(appender.append("---")); //$NON-NLS-1$ + } String unit = NANOSECONDS; if (formattedTime > NANOS_PER_SEC) { unit = SECONDS; @@ -66,7 +68,7 @@ public final class SubSecondTimeWithUnitFormat extends Format { unit = MICROSECONDS; formattedTime /= NANOS_PER_MICRO; } - String timeString = fDecimalFormat.format(formattedTime); + String timeString = unit.equals(NANOSECONDS) ? Long.toString((long) formattedTime) : fDecimalFormat.format(formattedTime); return appender == null ? new StringBuffer() : NonNullUtils.checkNotNull(appender.append(timeString).append(' ').append(unit)); } return new StringBuffer(); diff --git a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java index d0d2911ed2..7a76933128 100644 --- a/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java +++ b/analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java @@ -20,6 +20,7 @@ import java.util.List; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.tracecompass.analysis.timing.ui.views.segmentstore.SubSecondTimeWithUnitFormat; import org.eclipse.tracecompass.internal.analysis.timing.core.segmentstore.statistics.SegmentStoreStatistics; @@ -33,7 +34,8 @@ import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeColumnData; import org.eclipse.tracecompass.tmf.ui.viewers.tree.TmfTreeViewerEntry; /** - * An abstract tree viewer implementation for displaying segment store statistics + * An abstract tree viewer implementation for displaying segment store + * statistics * * @author Bernd Hufmann * @@ -42,13 +44,15 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr private static final Format FORMATTER = new SubSecondTimeWithUnitFormat(); - @Nullable private TmfAbstractAnalysisModule fModule; + @Nullable + private TmfAbstractAnalysisModule fModule; private static final String[] COLUMN_NAMES = new String[] { checkNotNull(Messages.SegmentStoreStatistics_LevelLabel), checkNotNull(Messages.SegmentStoreStatistics_Statistics_MinLabel), checkNotNull(Messages.SegmentStoreStatistics_MaxLabel), - checkNotNull(Messages.SegmentStoreStatistics_AverageLabel) + checkNotNull(Messages.SegmentStoreStatistics_AverageLabel), + checkNotNull(Messages.SegmentStoreStatisticsViewer_StandardDeviation) }; /** @@ -67,7 +71,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr @Override public String getColumnText(@Nullable Object element, int columnIndex) { - String value = ""; //$NON-NLS-1$ + String value = ""; //$NON-NLS-1$ if (element instanceof HiddenTreeViewerEntry) { if (columnIndex == 0) { value = ((HiddenTreeViewerEntry) element).getName(); @@ -84,6 +88,8 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr value = String.valueOf(toFormattedString(entry.getEntry().getMax())); } else if (columnIndex == 3) { value = String.valueOf(toFormattedString(entry.getEntry().getAverage())); + } else if (columnIndex == 4) { + value = String.valueOf(toFormattedString(entry.getEntry().getStdDev())); } } } @@ -96,13 +102,16 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr * * @return the statistics analysis module */ - @Nullable protected abstract TmfAbstractAnalysisModule createStatisticsAnalysiModule(); + @Nullable + protected abstract TmfAbstractAnalysisModule createStatisticsAnalysiModule(); /** * Gets the statistics analysis module + * * @return the statistics analysis module */ - @Nullable public TmfAbstractAnalysisModule getStatisticsAnalysisModule() { + @Nullable + public TmfAbstractAnalysisModule getStatisticsAnalysisModule() { return fModule; } @@ -115,6 +124,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr /* All columns are sortable */ List<@Nullable TmfTreeColumnData> columns = new ArrayList<>(); TmfTreeColumnData column = new TmfTreeColumnData(COLUMN_NAMES[0]); + column.setAlignment(SWT.RIGHT); column.setComparator(new ViewerComparator() { @Override public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { @@ -131,6 +141,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr }); columns.add(column); column = new TmfTreeColumnData(COLUMN_NAMES[1]); + column.setAlignment(SWT.RIGHT); column.setComparator(new ViewerComparator() { @Override public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { @@ -147,6 +158,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr }); columns.add(column); column = new TmfTreeColumnData(COLUMN_NAMES[2]); + column.setAlignment(SWT.RIGHT); column.setComparator(new ViewerComparator() { @Override public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { @@ -163,6 +175,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr }); columns.add(column); column = new TmfTreeColumnData(COLUMN_NAMES[3]); + column.setAlignment(SWT.RIGHT); column.setComparator(new ViewerComparator() { @Override public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { @@ -178,14 +191,31 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr } }); columns.add(column); + column = new TmfTreeColumnData(COLUMN_NAMES[4]); + column.setAlignment(SWT.RIGHT); + column.setComparator(new ViewerComparator() { + @Override + public int compare(@Nullable Viewer viewer, @Nullable Object e1, @Nullable Object e2) { + if ((e1 == null) || (e2 == null)) { + return 0; + } + + SegmentStoreStatisticsEntry n1 = (SegmentStoreStatisticsEntry) e1; + SegmentStoreStatisticsEntry n2 = (SegmentStoreStatisticsEntry) e2; + return Double.compare(n1.getEntry().getStdDev(), n2.getEntry().getStdDev()); + + } + }); + columns.add(column); + column = new TmfTreeColumnData(""); //$NON-NLS-1$ + columns.add(column); return columns; } }; } - @Override public void initializeDataSource() { /* Should not be called while trace is still null */ @@ -211,7 +241,8 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr * @return formatted value */ protected static String toFormattedString(double value) { - // The cast to long is needed because the formatter cannot truncate the number. + // The cast to long is needed because the formatter cannot truncate the + // number. String percentageString = checkNotNull(String.format("%s", FORMATTER.format(value))); //$NON-NLS-1$ return percentageString; } -- 2.34.1