analysis: make statistics show standard deviation
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 7 Jan 2016 21:05:36 +0000 (16:05 -0500)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 13 Jan 2016 22:10:14 +0000 (17:10 -0500)
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 <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/63788
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/latency/statistics/Messages.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/analysis/timing/ui/views/segmentstore/SubSecondTimeWithUnitFormat.java
analysis/org.eclipse.tracecompass.analysis.timing.ui/src/org/eclipse/tracecompass/internal/analysis/timing/ui/views/segmentstore/statistics/AbstractSegmentStoreStatisticsViewer.java

index 7b00ec3de95303d7ebf46ab95ee4a3f694fb0c2b..be973d1826610de661073ae1f6cbe336de6b6296 100644 (file)
@@ -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 */
index 5631c26196347bafc313f69aeca5c171786265d1..a04a3ea3ffc5dfc673080122ddc5d8077619b45f 100644 (file)
@@ -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();
index d0d2911ed2fd378be9b66d003df42ab269c03818..7a76933128928165695f8758a05d19d8984b290a 100644 (file)
@@ -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;
     }
This page took 0.02825 seconds and 5 git commands to generate.