tmf: Bug 494767: Events in selection not updated in Statistics view
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / tracecompass / internal / tmf / ui / viewers / statistics / StatisticsUpdateJob.java
index 293128d2d1f680b51fb0bc6a7a3db36a5b1caa0d..ed2e010a55180bda042a790a2be1229e2684b808 100644 (file)
@@ -22,11 +22,11 @@ import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.tracecompass.internal.tmf.ui.viewers.piecharts.model.TmfPieChartStatisticsModel;
 import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTree;
 import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager;
+import org.eclipse.tracecompass.internal.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode;
 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
 import org.eclipse.tracecompass.tmf.core.statistics.ITmfStatistics;
 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsEventTypesModule;
 import org.eclipse.tracecompass.tmf.core.statistics.TmfStatisticsModule;
-import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
 import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimeRange;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
 
@@ -48,10 +48,6 @@ class StatisticsUpdateJob extends Job {
      */
     private static final long LIVE_UPDATE_DELAY = 1000;
 
-    /**
-     * Timestamp scale used for all statistics (nanosecond)
-     */
-    private static final byte TIME_SCALE = ITmfTimestamp.NANOSECOND_SCALE;
     private TmfTimeRange fTimerange;
 
     /**
@@ -82,7 +78,9 @@ class StatisticsUpdateJob extends Job {
     protected IStatus run(IProgressMonitor monitor) {
 
         /* Wait until the analysis is ready to be queried */
-        fStatsMod.waitForInitialization();
+        if (!fStatsMod.waitForInitialization()) {
+            return Status.CANCEL_STATUS;
+        }
         ITmfStatistics stats = fStatsMod.getStatistics();
         if (stats == null) {
             /* It should have worked, but didn't */
@@ -122,8 +120,8 @@ class StatisticsUpdateJob extends Job {
              * The generic statistics are stored in nanoseconds, so we must make
              * sure the time range is scaled correctly.
              */
-            start = localtimeRange.getStartTime().normalize(0, TIME_SCALE).getValue();
-            end = localtimeRange.getEndTime().normalize(0, TIME_SCALE).getValue();
+            start = localtimeRange.getStartTime().toNanos();
+            end = localtimeRange.getEndTime().toNanos();
 
             Map<String, Long> map = stats.getEventTypesInRange(start, end);
             updateStats(map);
@@ -178,9 +176,17 @@ class StatisticsUpdateJob extends Job {
          * </pre>
          */
 
-        /* Fill in an the event counts (either cells C or D) */
-        for (Map.Entry<String, Long> entry : map.entrySet()) {
-            statsData.setTypeCount(name, entry.getKey(), fIsGlobal, entry.getValue());
+        if (map.isEmpty() && !fIsGlobal) {
+            /* Reset all time range event counts (cells D) */
+            TmfStatisticsTreeNode eventTypeNode = statsData.getNode(name, TmfStatisticsTree.HEADER_EVENT_TYPES);
+            if (eventTypeNode != null) {
+                eventTypeNode.resetTimeRangeValue();
+            }
+        } else {
+            /* Fill in the event counts (either cells C or D) */
+            for (Map.Entry<String, Long> entry : map.entrySet()) {
+                statsData.setTypeCount(name, entry.getKey(), fIsGlobal, entry.getValue());
+            }
         }
 
         /*
This page took 0.029351 seconds and 5 git commands to generate.