Fix for bug 382910: Improve responsiveness of Control Flow and Resources
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 18 Jun 2012 21:57:06 +0000 (17:57 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Mon, 18 Jun 2012 21:57:06 +0000 (17:57 -0400)
views.

org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/controlflow/ControlFlowView.java
org.eclipse.linuxtools.lttng2.kernel.ui/src/org/eclipse/linuxtools/internal/lttng2/kernel/ui/views/resources/ResourcesView.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/internal/tmf/core/statesystem/StateHistorySystem.java
org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statesystem/IStateSystemQuerier.java

index 157d45eafbb2a72a6be61d031d23276073798657..eaaf90ec87e58967cb5826434fef37a20482cc90 100644 (file)
@@ -101,6 +101,11 @@ public class ControlFlowView extends TmfView {
             TRACE_COLUMN\r
     };\r
 \r
+    /**\r
+     * Redraw state enum\r
+     */\r
+    private enum State { IDLE, BUSY, PENDING };\r
+\r
     // ------------------------------------------------------------------------\r
     // Fields\r
     // ------------------------------------------------------------------------\r
@@ -138,6 +143,12 @@ public class ControlFlowView extends TmfView {
     // A comparator class\r
     private final ControlFlowEntryComparator fControlFlowEntryComparator = new ControlFlowEntryComparator();\r
 \r
+    // The redraw state used to prevent unnecessary queuing of display runnables\r
+    private State fRedrawState = State.IDLE;\r
+\r
+    // The redraw synchronization object\r
+    final private Object fSyncObj = new Object();\r
+\r
     // ------------------------------------------------------------------------\r
     // Classes\r
     // ------------------------------------------------------------------------\r
@@ -278,7 +289,6 @@ public class ControlFlowView extends TmfView {
                 }\r
                 zoom(entry, fMonitor);\r
             }\r
-            redraw();\r
         }\r
 \r
         private void zoom(ControlFlowEntry entry, IProgressMonitor monitor) {\r
@@ -290,6 +300,7 @@ public class ControlFlowView extends TmfView {
                     entry.setZoomedEventList(zoomedEventList);\r
                 }\r
             }\r
+            redraw();\r
             for (ControlFlowEntry child : entry.getChildren()) {\r
                 if (fMonitor.isCanceled()) {\r
                     return;\r
@@ -667,7 +678,7 @@ public class ControlFlowView extends TmfView {
         List<ITimeEvent> eventList = null;\r
         try {\r
             int statusQuark = ssq.getQuarkRelative(entry.getThreadQuark(), Attributes.STATUS);\r
-            List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution);\r
+            List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);\r
             eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r
             long lastEndTime = -1;\r
             for (ITmfStateInterval statusInterval : statusIntervals) {\r
@@ -727,6 +738,14 @@ public class ControlFlowView extends TmfView {
     }\r
 \r
     private void redraw() {\r
+        synchronized (fSyncObj) {\r
+            if (fRedrawState == State.IDLE) {\r
+                fRedrawState = State.BUSY;\r
+            } else {\r
+                fRedrawState = State.PENDING;\r
+                return;\r
+            }\r
+        }\r
         Display.getDefault().asyncExec(new Runnable() {\r
             @Override\r
             public void run() {\r
@@ -735,6 +754,14 @@ public class ControlFlowView extends TmfView {
                 }\r
                 fTimeGraphCombo.redraw();\r
                 fTimeGraphCombo.update();\r
+                synchronized (fSyncObj) {\r
+                    if (fRedrawState == State.PENDING) {\r
+                        fRedrawState = State.IDLE;\r
+                        redraw();\r
+                    } else {\r
+                        fRedrawState = State.IDLE;\r
+                    }\r
+                }\r
             }\r
         });\r
     }\r
index 5f6680d3d28fe1cddd56fc185940e24c9d790d62..51e0abceafb34c14c2b96b4310b6436e89a699ee 100644 (file)
@@ -75,6 +75,11 @@ public class ResourcesView extends TmfView {
     /** Initial time range */\r
     private static final long INITIAL_WINDOW_OFFSET = (1L * 100  * 1000 * 1000); // .1sec\r
 \r
+    /**\r
+     * Redraw state enum\r
+     */\r
+    private enum State { IDLE, BUSY, PENDING };\r
+\r
     // ------------------------------------------------------------------------\r
     // Fields\r
     // ------------------------------------------------------------------------\r
@@ -109,6 +114,12 @@ public class ResourcesView extends TmfView {
     // The zoom thread\r
     private ZoomThread fZoomThread;\r
 \r
+    // The redraw state used to prevent unnecessary queuing of display runnables\r
+    private State fRedrawState = State.IDLE;\r
+\r
+    // The redraw synchronization object\r
+    final private Object fSyncObj = new Object();\r
+\r
     // ------------------------------------------------------------------------\r
     // Classes\r
     // ------------------------------------------------------------------------\r
@@ -246,9 +257,9 @@ public class ResourcesView extends TmfView {
                             entry.setZoomedEventList(zoomedEventList);\r
                         }\r
                     }\r
+                    redraw();\r
                 }\r
             }\r
-            redraw();\r
         }\r
 \r
         public void cancel() {\r
@@ -509,7 +520,7 @@ public class ResourcesView extends TmfView {
         try {\r
             if (entry.getType().equals(Type.CPU)) {\r
                 int statusQuark = ssq.getQuarkRelative(quark, Attributes.STATUS);\r
-                List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution);\r
+                List<ITmfStateInterval> statusIntervals = ssq.queryHistoryRange(statusQuark, startTime, endTime - 1, resolution, monitor);\r
                 eventList = new ArrayList<ITimeEvent>(statusIntervals.size());\r
                 long lastEndTime = -1;\r
                 for (ITmfStateInterval statusInterval : statusIntervals) {\r
@@ -532,7 +543,7 @@ public class ResourcesView extends TmfView {
                     }\r
                 }\r
             } else if (entry.getType().equals(Type.IRQ)) {\r
-                List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution);\r
+                List<ITmfStateInterval> irqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r
                 eventList = new ArrayList<ITimeEvent>(irqIntervals.size());\r
                 long lastEndTime = -1;\r
                 boolean lastIsNull = true;\r
@@ -558,7 +569,7 @@ public class ResourcesView extends TmfView {
                     lastEndTime = time + duration;\r
                 }\r
             } else if (entry.getType().equals(Type.SOFT_IRQ)) {\r
-                List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution);\r
+                List<ITmfStateInterval> softIrqIntervals = ssq.queryHistoryRange(quark, startTime, endTime - 1, resolution, monitor);\r
                 eventList = new ArrayList<ITimeEvent>(softIrqIntervals.size());\r
                 long lastEndTime = -1;\r
                 boolean lastIsNull = true;\r
@@ -622,6 +633,14 @@ public class ResourcesView extends TmfView {
 \r
 \r
     private void redraw() {\r
+        synchronized (fSyncObj) {\r
+            if (fRedrawState == State.IDLE) {\r
+                fRedrawState = State.BUSY;\r
+            } else {\r
+                fRedrawState = State.PENDING;\r
+                return;\r
+            }\r
+        }\r
         Display.getDefault().asyncExec(new Runnable() {\r
             @Override\r
             public void run() {\r
@@ -630,6 +649,14 @@ public class ResourcesView extends TmfView {
                 }\r
                 fTimeGraphViewer.getControl().redraw();\r
                 fTimeGraphViewer.getControl().update();\r
+                synchronized (fSyncObj) {\r
+                    if (fRedrawState == State.PENDING) {\r
+                        fRedrawState = State.IDLE;\r
+                        redraw();\r
+                    } else {\r
+                        fRedrawState = State.IDLE;\r
+                    }\r
+                }\r
             }\r
         });\r
     }\r
index 4ee5cdcde7e6486c94555e32b49f8cb078b2f1ec..fb4f585f56bd09fe6a1a0936afa7353ae190197f 100644 (file)
@@ -18,6 +18,8 @@ import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.linuxtools.internal.tmf.core.Tracer;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
@@ -214,6 +216,13 @@ public class StateHistorySystem extends StateSystem implements
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2, long resolution) throws TimeRangeException,
             AttributeNotFoundException {
+        return queryHistoryRange(attributeQuark, t1, t2, resolution, new NullProgressMonitor());
+    }
+
+    @Override
+    public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+            long t1, long t2, long resolution, IProgressMonitor monitor) throws TimeRangeException,
+            AttributeNotFoundException {
         List<ITmfStateInterval> intervals;
         ITmfStateInterval currentInterval;
         long ts, tEnd;
@@ -241,6 +250,9 @@ public class StateHistorySystem extends StateSystem implements
          */
         for (ts = t1; (currentInterval.getEndTime() != -1) && (ts < tEnd);
                 ts += resolution) {
+            if (monitor.isCanceled()) {
+                return intervals;
+            }
             if (ts <= currentInterval.getEndTime()) {
                 continue;
             }
index 1e1a68f75947dc444a08f883591878b23f19e8b7..6a2e36125bee105334c1d53756af9a089612f81c 100644 (file)
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.statesystem;
 
 import java.util.List;
 
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException;
 import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException;
 import org.eclipse.linuxtools.tmf.core.interval.ITmfStateInterval;
@@ -273,4 +274,35 @@ public interface IStateSystemQuerier {
     public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
             long t1, long t2, long resolution) throws TimeRangeException,
             AttributeNotFoundException;
+
+    /**
+     * Return the state history of a given attribute, but with at most one
+     * update per "resolution". This can be useful for populating views (where
+     * it's useless to have more than one query per pixel, for example).
+     * A progress monitor can be used to cancel the query before completion.
+     *
+     * @param attributeQuark
+     *            Which attribute this query is interested in
+     * @param t1
+     *            Start time of the range query
+     * @param t2
+     *            Target end time of the query. If t2 is greater than the end of
+     *            the trace, we will return what we have up to the end of the
+     *            history.
+     * @param resolution
+     *            The "step" of this query
+     * @param monitor
+     *            A progress monitor. If the monitor is canceled during a query,
+     *            we will return what has been found up to that point.
+     * @return The List of states that happened between t1 and t2
+     * @throws TimeRangeException
+     *             If t1 is invalid, if t2 <= t1, or if the resolution isn't
+     *             greater than zero.
+     * @throws AttributeNotFoundException
+     *             If the attribute doesn't exist
+     * @since 1.1
+     */
+    public List<ITmfStateInterval> queryHistoryRange(int attributeQuark,
+            long t1, long t2, long resolution, IProgressMonitor monitor) throws TimeRangeException,
+            AttributeNotFoundException;
 }
This page took 0.030286 seconds and 5 git commands to generate.