tmf: Improve histogram responsiveness
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 26 Mar 2013 21:49:08 +0000 (17:49 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 28 Mar 2013 14:56:41 +0000 (10:56 -0400)
The Histogram had its own kind of throttling TimeRangeSynch signals,
but simply freezing itself for ~100 ms, which would of course imply
no other time range could be selected.

Replace this with the fancy new signal throttlers. Now the
histogram display gets updated right away, while the background
time range updates and queries only happen after a short time
without any new time range selection.

The user experience should increase a great deal!

Change-Id: I89a872d9d829d5522523912f73dca2c31f48e64c
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-on: https://git.eclipse.org/r/11503
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bhufmann@gmail.com>
IP-Clean: Bernd Hufmann <bhufmann@gmail.com>
Tested-by: Bernd Hufmann <bhufmann@gmail.com>
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/FullTraceHistogram.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramView.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/HistogramZoom.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/histogram/TimeRangeHistogram.java

index 4417dfd22170f0ade683745d236c08bfb90daca6..829e82ca1452df67dfb7bffd627cdf921ee5a70c 100644 (file)
@@ -85,7 +85,6 @@ public class FullTraceHistogram extends Histogram implements MouseMoveListener {
         if (fZoom != null) {
             fZoom.setFullRange(0L, 0L);
             fZoom.setNewRange(0L, 0L);
-            fZoom.stop();
         }
         super.clear();
     }
index 64202fc771f39f13484166976382571bd04f77d2..7b7ed1465853a1edc8b9db26b22bd826cd1c7b2f 100644 (file)
@@ -22,7 +22,7 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest.ExecutionType;
 import org.eclipse.linuxtools.tmf.core.request.TmfDataRequest;
 import org.eclipse.linuxtools.tmf.core.signal.TmfRangeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
-import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalThrottler;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTimeSynchSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
 import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
@@ -97,6 +97,10 @@ public class HistogramView extends TmfView {
     private static TimeRangeHistogram fTimeRangeHistogram;
     private HistogramRequest fTimeRangeRequest;
 
+    // Throttlers for the time sync and time-range sync signals
+    private final TmfSignalThrottler fTimeSyncThrottle;
+    private final TmfSignalThrottler fTimeRangeSyncThrottle;
+
     // ------------------------------------------------------------------------
     // Constructor
     // ------------------------------------------------------------------------
@@ -106,6 +110,8 @@ public class HistogramView extends TmfView {
      */
     public HistogramView() {
         super(ID);
+        fTimeSyncThrottle = new TmfSignalThrottler(this, 200);
+        fTimeRangeSyncThrottle = new TmfSignalThrottler(this, 200);
     }
 
     @Override
@@ -300,8 +306,10 @@ public class HistogramView extends TmfView {
                 @Override
                 public void handleData(ITmfEvent event) {
                     if (event != null) {
-                        TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, event.getTimestamp());
-                        TmfSignalManager.dispatchSignal(signal);
+                        ITmfTimestamp ts = event.getTimestamp();
+                        updateDisplayedCurrentTime(ts.normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
+                        TmfTimeSynchSignal signal = new TmfTimeSynchSignal(this, ts);
+                        fTimeSyncThrottle.queue(signal);
                     }
                 }
             };
@@ -323,9 +331,11 @@ public class HistogramView extends TmfView {
             ITmfTimestamp currentTime = new TmfTimestamp(fCurrentTimestamp, ITmfTimestamp.NANOSECOND_SCALE);
             fTimeSpanControl.setValue(endTime - startTime);
 
+            updateDisplayedTimeRange(startTime, endTime);
+
             // Send the FW signal
             TmfRangeSynchSignal signal = new TmfRangeSynchSignal(this, timeRange, currentTime);
-            TmfSignalManager.dispatchSignal(signal);
+            fTimeRangeSyncThrottle.queue(signal);
         }
     }
 
@@ -498,12 +508,7 @@ public class HistogramView extends TmfView {
 
         // Update the selected event time
         ITmfTimestamp currentTime = signal.getCurrentTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE);
-        fCurrentTimestamp = currentTime.getValue();
-
-        // Notify the relevant widgets
-        fFullTraceHistogram.setCurrentEvent(fCurrentTimestamp);
-        fTimeRangeHistogram.setCurrentEvent(fCurrentTimestamp);
-        fCurrentEventTimeControl.setValue(fCurrentTimestamp);
+        updateDisplayedCurrentTime(currentTime.getValue());
     }
 
     /**
@@ -522,14 +527,12 @@ public class HistogramView extends TmfView {
                 return;
             }
 
-            // Update the time range
-            fWindowStartTime = range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-            fWindowEndTime = range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
-            fWindowSpan = fWindowEndTime - fWindowStartTime;
+            updateDisplayedTimeRange(
+                    range.getStartTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(),
+                    range.getEndTime().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue());
 
-            // Notify the relevant widgets
+            // Send the event request to populate the small histogram
             sendTimeRangeRequest(fWindowStartTime, fWindowEndTime);
-            fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan);
 
             fTimeSpanControl.setValue(fWindowSpan);
         }
@@ -576,6 +579,21 @@ public class HistogramView extends TmfView {
         }
     }
 
+    private void updateDisplayedCurrentTime(long time) {
+        fCurrentTimestamp = time;
+
+        fFullTraceHistogram.setCurrentEvent(fCurrentTimestamp);
+        fTimeRangeHistogram.setCurrentEvent(fCurrentTimestamp);
+        fCurrentEventTimeControl.setValue(fCurrentTimestamp);
+    }
+
+    private void updateDisplayedTimeRange(long start, long end) {
+        fWindowStartTime = start;
+        fWindowEndTime = end;
+        fWindowSpan = fWindowEndTime - fWindowStartTime;
+        fFullTraceHistogram.setTimeRange(fWindowStartTime, fWindowSpan);
+    }
+
     private TmfTimeRange updateTraceTimeRange() {
         fTraceStartTime = 0L;
         fTraceEndTime = 0L;
index dc4c806dc2e5ce839ee16c47c81252def52bfe19..b78de308a231224b52cb300e33f27bf038f10175 100644 (file)
@@ -46,8 +46,6 @@ public class HistogramZoom implements MouseWheelListener {
     private long fRangeStartTime;
     private long fRangeDuration;
 
-    private MouseScrollCounter fScrollCounter;
-
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -110,16 +108,6 @@ public class HistogramZoom implements MouseWheelListener {
     // Operations
     // ------------------------------------------------------------------------
 
-    /**
-     * Stops the zooming (multiple consecutive execution)
-     */
-    public synchronized void stop() {
-        if (fScrollCounter != null) {
-            fScrollCounter.interrupt();
-            fScrollCounter = null;
-        }
-    }
-
     /**
      * The the full time range of the histogram
      *
@@ -163,17 +151,10 @@ public class HistogramZoom implements MouseWheelListener {
 
     @Override
     public synchronized void mouseScrolled(MouseEvent event) {
-        if (fScrollCounter == null) {
-            fScrollCounter = new MouseScrollCounter(this);
-            fScrollCounter.start();
-        }
-        fScrollCounter.incrementMouseScroll(event.count);
+        zoom(event.count);
     }
 
     private synchronized void zoom(int nbClicks) {
-        // The job is finished
-        fScrollCounter = null;
-
         // Compute the new time range
         long requestedRange = (nbClicks > 0) ? Math.round(ZOOM_FACTOR * fRangeDuration) : (long) Math.ceil(fRangeDuration * (1.0 / ZOOM_FACTOR));
 
@@ -208,73 +189,4 @@ public class HistogramZoom implements MouseWheelListener {
         }
         return realEnd;
     }
-
-    // ------------------------------------------------------------------------
-    // DelayedMouseScroll
-    // ------------------------------------------------------------------------
-
-    private static class MouseScrollCounter extends Thread {
-
-        // --------------------------------------------------------------------
-        // Constants
-        // --------------------------------------------------------------------
-
-        private final static long QUIET_TIME = 100L;
-        private final static long POLLING_INTERVAL = 10L;
-
-        // --------------------------------------------------------------------
-        // Attributes
-        // --------------------------------------------------------------------
-
-        private HistogramZoom fZoom = null;
-
-        private long fLastPoolTime = 0L;
-        private int nbScrollClick = 0;
-
-        // --------------------------------------------------------------------
-        // Constructors
-        // --------------------------------------------------------------------
-
-        /**
-         * Constructor of inner class to handle consecutive scrolls of mouse wheel.
-         * @param zoom the histogram zoom reference
-         */
-        public MouseScrollCounter(HistogramZoom zoom) {
-            fZoom = zoom;
-            fLastPoolTime = System.currentTimeMillis();
-        }
-
-        // --------------------------------------------------------------------
-        // Operation
-        // --------------------------------------------------------------------
-
-        /**
-         * Increments the number of scroll clicks.
-         * @param nbScrolls the number to add to the current value
-         */
-        public void incrementMouseScroll(int nbScrolls) {
-            fLastPoolTime = System.currentTimeMillis();
-            nbScrollClick += nbScrolls;
-        }
-
-        // --------------------------------------------------------------------
-        // Thread
-        // --------------------------------------------------------------------
-
-        @Override
-        public void run() {
-            while ((System.currentTimeMillis() - fLastPoolTime) < QUIET_TIME) {
-                try {
-                    Thread.sleep(POLLING_INTERVAL);
-                } catch (Exception e) {
-                    return;
-                }
-            }
-            // Done waiting. Notify the histogram.
-            if (!isInterrupted()) {
-                fZoom.zoom(nbScrollClick);
-            }
-        }
-    }
-
 }
index cb1e2c9c3f87a2927dbfc3ef7aac0277c8026103..9c64a084a7c0c9016e7ce82320ef08afeb0cd5a1 100644 (file)
@@ -70,7 +70,6 @@ public class TimeRangeHistogram extends Histogram {
         if (fZoom != null) {
             fZoom.setFullRange(0L, 0L);
             fZoom.setNewRange(0L, 0L);
-            fZoom.stop();
         }
         super.clear();
     }
This page took 0.031415 seconds and 5 git commands to generate.