timing.core: Add local statistics to the latency statistics
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.timing.ui / src / org / eclipse / tracecompass / analysis / timing / ui / views / segmentstore / statistics / AbstractSegmentStoreStatisticsViewer.java
index 5bb0544cf0529cb2a1d124d4250f50803f4b891d..4bf0f3a4608c89fb429a2e16678418112d99aa1c 100644 (file)
@@ -19,6 +19,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
@@ -40,6 +43,8 @@ import org.eclipse.tracecompass.internal.analysis.timing.ui.views.segmentstore.s
 import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfAnalysisException;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
+import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.tracecompass.tmf.core.signal.TmfWindowRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 import org.eclipse.tracecompass.tmf.ui.viewers.tree.AbstractTmfTreeViewer;
@@ -59,8 +64,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
 
     private static final Format FORMATTER = new SubSecondTimeWithUnitFormat();
 
-    @Nullable
-    private TmfAbstractAnalysisModule fModule;
+    private @Nullable TmfAbstractAnalysisModule fModule;
     private MenuManager fTablePopupMenuManager;
 
     private static final String[] COLUMN_NAMES = new String[] {
@@ -322,6 +326,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
                     long start = segment.getEntry().getMinSegment().getStart();
                     long end = segment.getEntry().getMinSegment().getEnd();
                     broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+                    updateContent(start, end, true);
                 }
             };
 
@@ -331,6 +336,7 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
                     long start = segment.getEntry().getMaxSegment().getStart();
                     long end = segment.getEntry().getMaxSegment().getEnd();
                     broadcast(new TmfSelectionRangeUpdatedSignal(AbstractSegmentStoreStatisticsViewer.this, TmfTimestamp.fromNanos(start), TmfTimestamp.fromNanos(end)));
+                    updateContent(start, end, true);
                 }
             };
 
@@ -387,9 +393,6 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
 
     @Override
     protected @Nullable ITmfTreeViewerEntry updateElements(long start, long end, boolean isSelection) {
-        if (isSelection || (start == end)) {
-            return null;
-        }
 
         TmfAbstractAnalysisModule analysisModule = getStatisticsAnalysisModule();
 
@@ -402,24 +405,41 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
         module.waitForCompletion();
 
         TmfTreeViewerEntry root = new TmfTreeViewerEntry(""); //$NON-NLS-1$
-        final SegmentStoreStatistics entry = module.getTotalStats();
-        if (entry != null) {
+        List<ITmfTreeViewerEntry> entryList = root.getChildren();
 
-            List<ITmfTreeViewerEntry> entryList = root.getChildren();
+        if (isSelection) {
+            setStats(start, end, entryList, module, true, new NullProgressMonitor());
+        }
+        setStats(start, end, entryList, module, false, new NullProgressMonitor());
+        return root;
+    }
+
+    private void setStats(long start, long end, List<ITmfTreeViewerEntry> entryList, AbstractSegmentStatisticsAnalysis module, boolean isSelection, IProgressMonitor monitor) {
+        String label = isSelection ? getSelectionLabel() : getTotalLabel();
+        final SegmentStoreStatistics entry = isSelection ? module.getTotalStatsForRange(start, end, monitor) : module.getTotalStats();
+        if (entry != null) {
 
-            TmfTreeViewerEntry aggregateEntry = new SegmentStoreStatisticsEntry(getTotalLabel(), entry);
-            entryList.add(aggregateEntry);
-            HiddenTreeViewerEntry category = new HiddenTreeViewerEntry(getTypeLabel());
-            aggregateEntry.addChild(category);
+            if (entry.getNbSegments() == 0) {
+                return;
+            }
+            TmfTreeViewerEntry child = new SegmentStoreStatisticsEntry(checkNotNull(label), entry);
+            entryList.add(child);
 
-            Map<String, SegmentStoreStatistics> perSegmentStats = module.getPerSegmentTypeStats();
-            if (perSegmentStats != null) {
-                for (Entry<String, SegmentStoreStatistics> statsEntry : perSegmentStats.entrySet()) {
-                    category.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
+            final Map<@NonNull String, @NonNull SegmentStoreStatistics> perTypeStats = isSelection? module.getPerSegmentTypeStatsForRange(start, end, monitor) : module.getPerSegmentTypeStats();
+            if (perTypeStats != null) {
+                for (Entry<@NonNull String, @NonNull SegmentStoreStatistics> statsEntry : perTypeStats.entrySet()) {
+                    child.addChild(new SegmentStoreStatisticsEntry(statsEntry.getKey(), statsEntry.getValue()));
                 }
             }
         }
-        return root;
+    }
+
+    @Override
+    @TmfSignalHandler
+    public void windowRangeUpdated(@Nullable TmfWindowRangeUpdatedSignal signal) {
+        // Do nothing. We do not want to update the view and lose the selection
+        // if the window range is updated with current selection outside of this
+        // new range.
     }
 
     /**
@@ -442,6 +462,16 @@ public abstract class AbstractSegmentStoreStatisticsViewer extends AbstractTmfTr
         return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_total);
     }
 
+    /**
+     * Get the selection column label
+     *
+     * @return The selection column label
+     * @since 1.2
+     */
+    protected String getSelectionLabel() {
+        return checkNotNull(Messages.AbstractSegmentStoreStatisticsViewer_selection);
+    }
+
     /**
      * Class to define a level in the tree that doesn't have any values.
      */
This page took 0.02565 seconds and 5 git commands to generate.