analysis: make statistics show standard deviation
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / internal / analysis / timing / ui / views / segmentstore / statistics / AbstractSegmentStoreStatisticsViewer.java
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.025251 seconds and 5 git commands to generate.