tmf: Support live-reading in the Statistics View
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 29 Jan 2014 20:59:42 +0000 (15:59 -0500)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 4 Feb 2014 20:09:59 +0000 (15:09 -0500)
Change-Id: If73fecccc2a889308343d7222f93e6b0bd3b4512
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/21417
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
IP-Clean: Matthew Khouzam <matthew.khouzam@ericsson.com>

org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java

index 4ddecf723dbb18b46dcb1368a3f58ad3c181eb58..3cec1efc979a258300927514fa04396e592447be 100644 (file)
@@ -133,7 +133,6 @@ public class TmfStateStatistics implements ITmfStatistics {
         final List<Long> list = new LinkedList<>();
         final long increment = (end - start) / nb;
 
-        totalsStats.waitUntilBuilt();
         if (totalsStats.isCancelled()) {
             return list;
         }
@@ -168,9 +167,6 @@ public class TmfStateStatistics implements ITmfStatistics {
 
     @Override
     public long getEventsTotal() {
-        /* We need the complete state history to be built to answer this. */
-        totalsStats.waitUntilBuilt();
-
         long endTime = totalsStats.getCurrentEndTime();
         int count = 0;
 
@@ -181,11 +177,7 @@ public class TmfStateStatistics implements ITmfStatistics {
         } catch (TimeRangeException e) {
             /* Assume there is no events for that range */
             return 0;
-        } catch (AttributeNotFoundException e) {
-            e.printStackTrace();
-        } catch (StateValueTypeException e) {
-            e.printStackTrace();
-        } catch (StateSystemDisposedException e) {
+        } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) {
             e.printStackTrace();
         }
 
@@ -194,10 +186,7 @@ public class TmfStateStatistics implements ITmfStatistics {
 
     @Override
     public Map<String, Long> getEventTypesTotal() {
-        /* We need the complete state history to be built to answer this. */
-        typesStats.waitUntilBuilt();
-
-        Map<String, Long> map = new HashMap<>();
+        final Map<String, Long> map = new HashMap<>();
         long endTime = typesStats.getCurrentEndTime();
 
         try {
@@ -226,10 +215,6 @@ public class TmfStateStatistics implements ITmfStatistics {
 
     @Override
     public long getEventsInRange(long start, long end) {
-        // FIXME Instead of waiting until the end, we could check the current
-        // end time, and answer as soon as possible...
-        totalsStats.waitUntilBuilt();
-
         long startCount;
         if (start == totalsStats.getStartTime()) {
             startCount = 0;
@@ -247,11 +232,8 @@ public class TmfStateStatistics implements ITmfStatistics {
 
     @Override
     public Map<String, Long> getEventTypesInRange(long start, long end) {
-        // FIXME Instead of waiting until the end, we could check the current
-        // end time, and answer as soon as possible...
-        typesStats.waitUntilBuilt();
-
-        Map<String, Long> map = new HashMap<>();
+        final Map<String, Long> map = new HashMap<>();
+        List<Integer> quarks;
 
         /* Make sure the start/end times are within the state history, so we
          * don't get TimeRange exceptions.
@@ -262,18 +244,24 @@ public class TmfStateStatistics implements ITmfStatistics {
         try {
             /* Get the list of quarks, one for each even type in the database */
             int quark = typesStats.getQuarkAbsolute(Attributes.EVENT_TYPES);
-            List<Integer> quarks = typesStats.getSubAttributes(quark, false);
+            quarks = typesStats.getSubAttributes(quark, false);
+        } catch (AttributeNotFoundException e) {
+            /*
+             * The state system does not (yet?) have the needed attributes, it
+             * probably means there are no events counted yet. Return the empty
+             * map.
+             */
+            return map;
+        }
 
+        try {
             List<ITmfStateInterval> endState = typesStats.queryFullState(endTime);
 
-            String curEventName;
-            long countAtStart, countAtEnd, eventCount;
-
             if (startTime == typesStats.getStartTime()) {
                 /* Only use the values picked up at the end time */
                 for (int typeQuark : quarks) {
-                    curEventName = typesStats.getAttributeName(typeQuark);
-                    eventCount = endState.get(typeQuark).getStateValue().unboxInt();
+                    String curEventName = typesStats.getAttributeName(typeQuark);
+                    long eventCount = endState.get(typeQuark).getStateValue().unboxInt();
                     if (eventCount == -1) {
                         eventCount = 0;
                     }
@@ -286,9 +274,9 @@ public class TmfStateStatistics implements ITmfStatistics {
                  */
                 List<ITmfStateInterval> startState = typesStats.queryFullState(startTime - 1);
                 for (int typeQuark : quarks) {
-                    curEventName = typesStats.getAttributeName(typeQuark);
-                    countAtStart = startState.get(typeQuark).getStateValue().unboxInt();
-                    countAtEnd = endState.get(typeQuark).getStateValue().unboxInt();
+                    String curEventName = typesStats.getAttributeName(typeQuark);
+                    long countAtStart = startState.get(typeQuark).getStateValue().unboxInt();
+                    long countAtEnd = endState.get(typeQuark).getStateValue().unboxInt();
 
                     if (countAtStart == -1) {
                         countAtStart = 0;
@@ -296,19 +284,19 @@ public class TmfStateStatistics implements ITmfStatistics {
                     if (countAtEnd == -1) {
                         countAtEnd = 0;
                     }
-                    eventCount = countAtEnd - countAtStart;
+                    long eventCount = countAtEnd - countAtStart;
                     map.put(curEventName, eventCount);
                 }
             }
 
-        } catch (TimeRangeException e) {
-            /* Assume there is no events, nothing will be put in the map. */
-        } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) {
+        } catch (TimeRangeException | StateSystemDisposedException e) {
+            /* Assume there is no (more) events, nothing will be put in the map. */
+        } catch (StateValueTypeException e) {
             /*
-             * These other exception types would show a logic problem however,
+             * This exception type would show a logic problem however,
              * so they should not happen.
              */
-            e.printStackTrace();
+            throw new IllegalStateException();
         }
         return map;
     }
index 6260eeb19d6e3fd9ea520387ee848ff246effcae..6ac6f1757d599f9ceae60c4b1d78555e02d6db94 100644 (file)
@@ -12,6 +12,7 @@
 
 package org.eclipse.linuxtools.tmf.core.statistics;
 
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
 import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
@@ -39,6 +40,7 @@ public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule
     /**
      * The ID of this analysis module (which is also the ID of the state system)
      */
+    @NonNull
     public static final String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
 
     private static final String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$
index 52d782a0fbbf3cc2189cc5f76dae4cfda1932bc6..2d5051f64d8f5dad1435ace72b9f612de102c362 100644 (file)
@@ -17,7 +17,6 @@ package org.eclipse.linuxtools.tmf.ui.viewers.statistics;
 import java.util.List;
 import java.util.Map;
 
-import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.viewers.TreeViewer;
 import org.eclipse.jface.viewers.TreeViewerColumn;
 import org.eclipse.jface.viewers.Viewer;
@@ -28,7 +27,9 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal;
+import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
+import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsEventTypesModule;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
@@ -80,6 +81,11 @@ public class TmfStatisticsViewer extends TmfViewer {
      */
     protected final Long STATS_INPUT_CHANGED_REFRESH = 5000L;
 
+    /**
+     * The delay (in ms) between each update in live-reading mode
+     */
+    private static final long LIVE_UPDATE_DELAY = 1000;
+
     /**
      * The actual tree viewer to display
      */
@@ -688,15 +694,12 @@ public class TmfStatisticsViewer extends TmfViewer {
                 Thread statsThread = new Thread("Statistics update") { //$NON-NLS-1$
                     @Override
                     public void run() {
-                        /* Wait until the analysis is ready */
-                        if (!statsMod.waitForCompletion(new NullProgressMonitor())) {
-                            return;
-                        }
-
+                        /* Wait until the analysis is ready to be queried */
+                        statsMod.waitForInitialization();
                         ITmfStatistics stats = statsMod.getStatistics();
                         if (stats == null) {
                             /* It should have worked, but didn't */
-                            return;
+                            throw new IllegalStateException();
                         }
 
                         /*
@@ -706,6 +709,29 @@ public class TmfStatisticsViewer extends TmfViewer {
                         long start = timeRange.getStartTime().normalize(0, TIME_SCALE).getValue();
                         long end = timeRange.getEndTime().normalize(0, TIME_SCALE).getValue();
 
+                        /*
+                         * Wait on the state system object we are going to query.
+                         *
+                         * TODO Eventually this could be exposed through the
+                         * TmfStateSystemAnalysisModule directly.
+                         */
+                        ITmfStateSystem ss = statsMod.getStateSystem(TmfStatisticsEventTypesModule.ID);
+                        if (ss == null) {
+                            /* It should be instantiated after the
+                             * statsMod.waitForInitialization() above. */
+                            throw new IllegalStateException();
+                        }
+
+                        /*
+                         * Periodically update the statistics while they are
+                         * being built (or, if the back-end is already completely
+                         * built, it will skip over the while() immediately.
+                         */
+                        while(!ss.waitUntilBuilt(LIVE_UPDATE_DELAY)) {
+                            Map<String, Long> map = stats.getEventTypesInRange(start, end);
+                            updateStats(isGlobal, map);
+                        }
+                        /* Query one last time for the final values */
                         Map<String, Long> map = stats.getEventTypesInRange(start, end);
                         updateStats(isGlobal, map);
                     }
@@ -727,6 +753,11 @@ public class TmfStatisticsViewer extends TmfViewer {
     private void updateStats(boolean isGlobal, Map<String, Long> eventsPerType) {
 
         final TmfStatisticsTree statsData = TmfStatisticsTreeManager.getStatTree(getTreeID());
+        if (statsData == null) {
+            /* The stat tree  has been disposed, abort mission. */
+            return;
+        }
+
         Map<String, Long> map = eventsPerType;
         String name = fTrace.getName();
 
This page took 0.029856 seconds and 5 git commands to generate.