Skip to main content

[memorypoolview~source-code-repository:b1b5335e] Added garbage collector summary panel

  • From:
  • To:
  • Subject: [memorypoolview~source-code-repository:b1b5335e] Added garbage collector summary panel
  • Date: Tue, 12 Mar 2013 14:54:31 +0000

Project:    memorypoolview
Repository: source-code-repository
Revision:   b1b5335e8bc4573b1f1d9886eeb78125a4629f2d
Author:     pingtimeout
Date:       2013-03-12 14:56:54 UTC
Link:       

Log Message:
------------
Added garbage collector summary panel


Revisions:
----------
b1b5335e8bc4573b1f1d9886eeb78125a4629f2d


Modified Paths:
---------------
src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
src/com/kodewerk/visualvm/memorypools/PanelPositions.java
src/com/kodewerk/visualvm/memorypools/gc/Collections.java
src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java


Diffs:
------
diff --git a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java 
b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
index 2677694..5688f5b 100644
--- a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
+++ b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
@@ -19,6 +19,7 @@ package com.kodewerk.visualvm.memorypools;
 
 import com.kodewerk.visualvm.memorypools.gc.GarbageCollectorModel;
 import com.kodewerk.visualvm.memorypools.gc.GarbageCollectorPanel;
+import com.kodewerk.visualvm.memorypools.gc.GarbageCollectorSummaryPanel;
 import com.sun.tools.visualvm.application.Application;
 import com.sun.tools.visualvm.core.ui.DataSourceView;
 import com.sun.tools.visualvm.core.ui.components.DataViewComponent;
@@ -30,6 +31,7 @@ import org.openide.util.ImageUtilities;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 import javax.swing.*;
+import javax.swing.border.EmptyBorder;
 import java.awt.*;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -40,8 +42,8 @@ import java.util.TreeSet;
  * @author kirk
  */
 class MemoryPoolView extends DataSourceView {
-    private ArrayList<MemoryPoolModel> memoryPoolModels = new 
ArrayList<MemoryPoolModel>();
-    private Set<GarbageCollectorModel> garbageCollectorModels = new 
TreeSet<GarbageCollectorModel>(GarbageCollectorModel.compareOnGeneration());
+    private final ArrayList<MemoryPoolModel> memoryPoolModels = new 
ArrayList<MemoryPoolModel>();
+    private final Set<GarbageCollectorModel> garbageCollectorModels = new 
TreeSet<GarbageCollectorModel>(GarbageCollectorModel.compareOnGeneration());
     private DataViewComponent dvc;
 
     public MemoryPoolView(Application application) {
@@ -115,11 +117,31 @@ class MemoryPoolView extends DataSourceView {
     private void findGarbageCollectorsAndCreatePanels() {
         findGarbageCollectors();
         PanelPositions positions = new PanelPositions();
+        createGarbageCollectorSummaryPanel(garbageCollectorModels, 
positions);
         for (GarbageCollectorModel model : garbageCollectorModels) {
             createGarbageCollectorPanelFor(model, positions);
         }
     }
 
+    private void 
createGarbageCollectorSummaryPanel(Set<GarbageCollectorModel> 
garbageCollectorModels, PanelPositions positions) {
+        JPanel groupPanel = new JPanel();
+        groupPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+        groupPanel.setOpaque(false);
+        groupPanel.setLayout(new BoxLayout(groupPanel, BoxLayout.Y_AXIS));
+        for (GarbageCollectorModel garbageCollectorModel : 
garbageCollectorModels) {
+            GarbageCollectorSummaryPanel summaryPanel = new 
GarbageCollectorSummaryPanel(garbageCollectorModel.getName());
+            garbageCollectorModel.registerView(summaryPanel);
+
+            groupPanel.add(summaryPanel);
+            groupPanel.add(Box.createVerticalGlue());
+        }
+
+        Point position = positions.of("GC Summary Panel");
+        DataViewComponent.DetailsView detailsView = new 
DataViewComponent.DetailsView(
+                "GC Summary Panel", "Garbage Collectors summary panel", 
position.y, groupPanel, null);
+        dvc.addDetailsView(detailsView, position.x);
+    }
+
     protected void findGarbageCollectors() {
         try {
             MBeanServerConnection conn = 
getMBeanServerConnection((Application) super.getDataSource());
diff --git a/src/com/kodewerk/visualvm/memorypools/PanelPositions.java 
b/src/com/kodewerk/visualvm/memorypools/PanelPositions.java
index 9241ba7..4b3eb4c 100644
--- a/src/com/kodewerk/visualvm/memorypools/PanelPositions.java
+++ b/src/com/kodewerk/visualvm/memorypools/PanelPositions.java
@@ -41,8 +41,10 @@ public class PanelPositions {
         positions.put("JIT data cache", new 
Point(DataViewComponent.BOTTOM_LEFT, 20));
 
         // Hotspot Garbage Collectors
+        positions.put("GC Summary Panel", new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
         positions.put("PS Scavenge", new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
         positions.put("PS MarkSweep", new 
Point(DataViewComponent.BOTTOM_RIGHT, 20));
+
     }
 
     /**
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/Collections.java 
b/src/com/kodewerk/visualvm/memorypools/gc/Collections.java
index a0f7be5..0b9c837 100644
--- a/src/com/kodewerk/visualvm/memorypools/gc/Collections.java
+++ b/src/com/kodewerk/visualvm/memorypools/gc/Collections.java
@@ -1,5 +1,10 @@
 package com.kodewerk.visualvm.memorypools.gc;
 
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.util.Locale;
+
 public class Collections {
     private final long count;
     private final long totalDuration;
@@ -37,4 +42,11 @@ public class Collections {
         return collectionTime != null && collectionCount != null && 
lastDuration != null
                 && !collectionCount.equals(count);
     }
+
+    public static String formatNumber(long number) {
+        DecimalFormat formatter = (DecimalFormat) 
NumberFormat.getInstance(new Locale("en_US"));
+        DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
+        symbols.setGroupingSeparator(' ');
+        return formatter.format(number);
+    }
 }
diff --git 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
index 000d741..87d87dc 100644
--- a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
@@ -78,16 +78,24 @@ public class GarbageCollectorModel implements 
MBeanCacheListener {
         return name;
     }
 
-    public Collections getCollections() {
-        return collections;
+    public long getCount() {
+        return collections.getCount();
     }
 
-    public void registerView(GarbageCollectorModelListener listener) {
-        listeners.add(listener);
+    public long getTotalDuration() {
+        return collections.getTotalDuration();
+    }
+
+    public long getAverageDuration() {
+        return collections.getAverageDuration();
     }
 
-    public GarbageCollector getGarbageCollector() {
-        return garbageCollector;
+    public long getLastDuration() {
+        return collections.getLastDuration();
+    }
+
+    public void registerView(GarbageCollectorModelListener listener) {
+        listeners.add(listener);
     }
 
     public static Comparator<GarbageCollectorModel> compareOnGeneration() {
diff --git 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
index c54e7da..1ff524a 100644
--- a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
@@ -7,10 +7,6 @@ import com.sun.tools.visualvm.charts.SimpleXYChartSupport;
 
 import javax.swing.*;
 import java.awt.*;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.NumberFormat;
-import java.util.Locale;
 
 public class GarbageCollectorPanel extends JPanel implements 
GarbageCollectorModelListener {
     private SimpleXYChartSupport chart;
@@ -30,22 +26,15 @@ public class GarbageCollectorPanel extends JPanel 
implements GarbageCollectorMod
     @Override
     public void garbageCollectorUpdated(GarbageCollectorModel model) {
         long[] dataPoints = new long[2];
-        dataPoints[0] = model.getCollections().getLastDuration();
-        dataPoints[1] = model.getCollections().getAverageDuration();
+        dataPoints[0] = model.getLastDuration();
+        dataPoints[1] = model.getAverageDuration();
         chart.addValues(System.currentTimeMillis(), dataPoints);
 
         String[] details = new String[4];
-        details[0] = formatNumber(model.getCollections().getLastDuration()) 
+ " ms";
-        details[1] = String.valueOf(model.getCollections().getCount());
-        details[2] = 
formatNumber(model.getCollections().getAverageDuration()) + " ms";
-        details[3] = formatNumber(model.getCollections().getTotalDuration()) 
+ " ms";
+        details[0] = Collections.formatNumber(model.getLastDuration()) + " 
ms";
+        details[1] = String.valueOf(model.getCount());
+        details[2] = Collections.formatNumber(model.getAverageDuration()) + 
" ms";
+        details[3] = Collections.formatNumber(model.getTotalDuration()) + " 
ms";
         chart.updateDetails(details);
     }
-
-    public String formatNumber(long number) {
-        DecimalFormat formatter = (DecimalFormat) 
NumberFormat.getInstance(new Locale("en_US"));
-        DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
-        symbols.setGroupingSeparator(' ');
-        return formatter.format(number);
-    }
 }
diff --git 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java
index aaa2db3..e8a1b89 100644
--- 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java
+++ 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java
@@ -1,4 +1,51 @@
 package com.kodewerk.visualvm.memorypools.gc;
 
-public class GarbageCollectorSummaryPanel {
+import javax.swing.*;
+import java.awt.*;
+
+public class GarbageCollectorSummaryPanel extends JPanel implements 
GarbageCollectorModelListener {
+    private static GarbageCollectorSummaryPanel 
forModel(GarbageCollectorModel model) {
+        GarbageCollectorSummaryPanel garbageCollectorPanel = new 
GarbageCollectorSummaryPanel(model.getName());
+        model.registerView(garbageCollectorPanel);
+        return garbageCollectorPanel;
+    }
+
+    private final JLabel gcCount;
+    private final JLabel averageDuration;
+    private final JLabel lastDuration;
+    private final JLabel totalDuration;
+
+    public GarbageCollectorSummaryPanel(String name) {
+        setLayout(new GridLayout(0, 2));
+        setOpaque(false);
+
+        gcCount = new JLabel("0");
+        averageDuration = new JLabel("0 ms");
+        lastDuration = new JLabel("0 ms");
+        totalDuration = new JLabel("0 ms");
+
+        add(createBoldLabel("Number of " + name + " :"));
+        add(gcCount);
+        add(createBoldLabel("Average " + name + " duration : "));
+        add(averageDuration);
+        add(createBoldLabel("Total " + name + " time : "));
+        add(totalDuration);
+        add(createBoldLabel("Last " + name + " duration : "));
+        add(lastDuration);
+    }
+
+    private JLabel createBoldLabel(String text) {
+        JLabel jLabel = new JLabel(text);
+        Font font = jLabel.getFont();
+        jLabel.setFont(font.deriveFont(font.getStyle() | Font.BOLD));
+        return jLabel;
+    }
+
+    @Override
+    public void garbageCollectorUpdated(GarbageCollectorModel model) {
+        gcCount.setText(String.valueOf(model.getCount()));
+        
averageDuration.setText(Collections.formatNumber(model.getAverageDuration()) 
+ " ms");
+        
lastDuration.setText(Collections.formatNumber(model.getLastDuration()) + " 
ms");
+        
totalDuration.setText(Collections.formatNumber(model.getTotalDuration()) + " 
ms");
+    }
 }




[memorypoolview~source-code-repository:b1b5335e] Added garbage collector summary panel

pingtimeout 03/12/2013
 
 
Close
loading
Please Confirm
Close