jmeter-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1783579&view=rev
Log:
Make GUI more responsive when it gets a lot of events.
Convert Table Visualizer to use a queue, when new rows 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/TableVisualizer.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/TableVisualizer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/TableVisualizer.java?rev=1783579&r1=1783578&r2=1783579&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/TableVisualizer.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/TableVisualizer.java Sat Feb
18 19:22:40 2017
@@ -24,6 +24,8 @@ import java.awt.FlowLayout;
 import java.text.Format;
 import java.text.SimpleDateFormat;
 import java.util.Comparator;
+import java.util.Deque;
+import java.util.concurrent.ConcurrentLinkedDeque;
 
 import javax.swing.BorderFactory;
 import javax.swing.ImageIcon;
@@ -33,6 +35,7 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.JTextField;
+import javax.swing.Timer;
 import javax.swing.border.Border;
 import javax.swing.border.EmptyBorder;
 import javax.swing.table.TableCellRenderer;
@@ -110,6 +113,8 @@ public class TableVisualizer extends Abs
 
     private Format format = new SimpleDateFormat("HH:mm:ss.SSS"); //$NON-NLS-1$
 
+    private Deque<SampleResult> newRows = new ConcurrentLinkedDeque<>();
+
     // Column renderers
     private static final TableCellRenderer[] RENDERERS =
         new TableCellRenderer[]{
@@ -180,43 +185,21 @@ public class TableVisualizer extends Abs
                 return;
             }
         }
-        JMeterUtils.runSafe(false, new Runnable() {
-            @Override
-            public void run() {
-                synchronized (calc) {
-                    calc.addSample(res);
-                    int count = calc.getCount();
-                    TableSample newS = new TableSample(
-                            count,
-                            res.getSampleCount(),
-                            res.getStartTime(),
-                            res.getThreadName(),
-                            res.getSampleLabel(),
-                            res.getTime(),
-                            res.isSuccessful(),
-                            res.getBytesAsLong(),
-                            res.getSentBytes(),
-                            res.getLatency(),
-                            res.getConnectTime()
-                            );
-                    model.addRow(newS);
-                }
-                updateTextFields(res);
-                if (autoscroll.isSelected()) {
-                    table.scrollRectToVisible(table.getCellRect(table.getRowCount() - 1,
0, true));
-                }
-            }
-        });
+        newRows.add(res);
+
     }
 
     @Override
     public synchronized void clearData() {
-        model.clearData();
-        calc.clear();
-        noSamplesField.setText("0"); // $NON-NLS-1$
-        dataField.setText("0"); // $NON-NLS-1$
-        averageField.setText("0"); // $NON-NLS-1$
-        deviationField.setText("0"); // $NON-NLS-1$
+        synchronized (calc) {
+            model.clearData();
+            calc.clear();
+            newRows.clear();
+            noSamplesField.setText("0"); // $NON-NLS-1$
+            dataField.setText("0"); // $NON-NLS-1$
+            averageField.setText("0"); // $NON-NLS-1$
+            deviationField.setText("0"); // $NON-NLS-1$            
+        }
         repaint();
     }
 
@@ -337,6 +320,39 @@ public class TableVisualizer extends Abs
         // Add the main panel and the graph
         this.add(mainPanel, BorderLayout.NORTH);
         this.add(tablePanel, BorderLayout.CENTER);
+        new Timer(500, e -> collectNewSamples()).start();
+    }
+
+    private void collectNewSamples() {
+        synchronized (calc) {
+            SampleResult res = null;
+            while (!newRows.isEmpty()) {
+                res = newRows.pop();
+                calc.addSample(res);
+                int count = calc.getCount();
+                TableSample newS = new TableSample(
+                        count,
+                        res.getSampleCount(),
+                        res.getStartTime(),
+                        res.getThreadName(),
+                        res.getSampleLabel(),
+                        res.getTime(),
+                        res.isSuccessful(),
+                        res.getBytesAsLong(),
+                        res.getSentBytes(),
+                        res.getLatency(),
+                        res.getConnectTime()
+                        );
+                model.addRow(newS);
+            }
+            if (res == null) {
+                return;
+            }
+            updateTextFields(res);
+            if (autoscroll.isSelected()) {
+                table.scrollRectToVisible(table.getCellRect(table.getRowCount() - 1, 0, true));
+            }
+        }
     }
 
     public static class SampleSuccessFunctor extends Functor {



Mime
View raw message