jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject svn commit: r1783580 - /jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java
Date Sat, 18 Feb 2017 19:58:02 GMT
Author: fschumacher
Date: Sat Feb 18 19:58:02 2017
New Revision: 1783580

URL: http://svn.apache.org/viewvc?rev=1783580&view=rev
Log:
Make GUI more responsive when it gets a lot of events.
Convert Graph Visualizer to use a queue, when new Samples are to be inserted.
Update the model (or at least notify the gui) only periodically.
That way we get the update of the model out of the busy path of the swing
event loop. Note, that this will not save us from OOM exceptions.

Bugzilla Id: 60687


Modified:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java?rev=1783580&r1=1783579&r2=1783580&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/GraphVisualizer.java Sat Feb
18 19:58:02 2017
@@ -27,6 +27,8 @@ import java.awt.Image;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.text.NumberFormat;
+import java.util.Deque;
+import java.util.concurrent.ConcurrentLinkedDeque;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
@@ -37,6 +39,7 @@ import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 import javax.swing.ScrollPaneConstants;
 import javax.swing.SwingConstants;
+import javax.swing.Timer;
 import javax.swing.border.Border;
 import javax.swing.border.EmptyBorder;
 
@@ -94,6 +97,8 @@ public class GraphVisualizer extends Abs
 
     private JTextField medianField;
 
+    private Deque<SampleResult> newSamples = new ConcurrentLinkedDeque<>();
+
     /**
      * Constructor for the GraphVisualizer object.
      */
@@ -117,8 +122,30 @@ public class GraphVisualizer extends Abs
         return result;
     }
 
-    public synchronized void updateGui(Sample s) {
+    /**
+     * @deprecated use {@link GraphVisualizer#add(SampleResult)} instead
+     */
+    public void updateGui(Sample s) {
+        JMeterUtils.runSafe(false, () -> _updateGui(s));
+    }
+
+    // called inside AWT Thread
+    private void collectSamplesFromQueue() {
         // We have received one more sample
+        Sample s = null;
+        synchronized (graph) {
+            while (!newSamples.isEmpty()) {
+                s = model.addSample(newSamples.pop());
+            }
+        }
+        _updateGui(s);
+    }
+
+    // called inside AWT Thread
+    private void _updateGui(Sample s) {
+        if (s == null) {
+            return;
+        }
         graph.updateGui(s);
         noSamplesField.setText(Long.toString(s.getCount()));
         dataField.setText(Long.toString(s.getData()));
@@ -131,12 +158,7 @@ public class GraphVisualizer extends Abs
 
     @Override
     public void add(final SampleResult res) {
-        JMeterUtils.runSafe(false, new Runnable() {
-            @Override
-            public void run() {
-                updateGui(model.addSample(res));
-            }
-        });
+        newSamples.add(res);
     }
 
     @Override
@@ -162,8 +184,11 @@ public class GraphVisualizer extends Abs
 
     @Override
     public void clearData() {
-        graph.clearData();
-        model.clear();
+        synchronized (graph) {
+            graph.clearData();
+            model.clear();
+            newSamples.clear();
+        }
         dataField.setText(ZERO);
         averageField.setText(ZERO);
         deviationField.setText(ZERO);
@@ -208,6 +233,8 @@ public class GraphVisualizer extends Abs
         // Add the main panel and the graph
         this.add(makeTitlePanel(), BorderLayout.NORTH);
         this.add(graphPanel, BorderLayout.CENTER);
+        
+        new Timer(500, e -> collectSamplesFromQueue()).start();
     }
 
     // Methods used in creating the GUI



Mime
View raw message