Skip to main content

[memorypoolview~source-code-repository:584a0259] Added last GC duration for IBM J9 and Hotspot

  • From:
  • To:
  • Subject: [memorypoolview~source-code-repository:584a0259] Added last GC duration for IBM J9 and Hotspot
  • Date: Tue, 12 Mar 2013 13:55:49 +0000

Project:    memorypoolview
Repository: source-code-repository
Revision:   584a0259a291d176ed40df8c7f00b791eaa96b4f
Author:     pingtimeout
Date:       2013-03-12 13:56:30 UTC
Link:       

Log Message:
------------
Added last GC duration for IBM J9 and Hotspot
Garbage collector panels are now sorted so that young generation GC are
displayed first, regardless of their names.


Revisions:
----------
584a0259a291d176ed40df8c7f00b791eaa96b4f


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


Added Paths:
------------
src/com/kodewerk/visualvm/memorypools/gc/Collections.java
src/com/kodewerk/visualvm/memorypools/gc/GarbageCollector.java
src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java
src/com/kodewerk/visualvm/memorypools/gc/Generation.java


Diffs:
------
diff --git a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java 
b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
index d45fd02..2677694 100644
--- a/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
+++ b/src/com/kodewerk/visualvm/memorypools/MemoryPoolView.java
@@ -33,13 +33,15 @@ import javax.swing.*;
 import java.awt.*;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * @author kirk
  */
 class MemoryPoolView extends DataSourceView {
     private ArrayList<MemoryPoolModel> memoryPoolModels = new 
ArrayList<MemoryPoolModel>();
-    private ArrayList<GarbageCollectorModel> garbageCollectorModels = new 
ArrayList<GarbageCollectorModel>();
+    private Set<GarbageCollectorModel> garbageCollectorModels = new 
TreeSet<GarbageCollectorModel>(GarbageCollectorModel.compareOnGeneration());
     private DataViewComponent dvc;
 
     public MemoryPoolView(Application application) {
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/Collections.java 
b/src/com/kodewerk/visualvm/memorypools/gc/Collections.java
new file mode 100644
index 0000000..a0f7be5
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/gc/Collections.java
@@ -0,0 +1,40 @@
+package com.kodewerk.visualvm.memorypools.gc;
+
+public class Collections {
+    private final long count;
+    private final long totalDuration;
+    private final long averageDuration;
+    private final long lastDuration;
+
+    public Collections() {
+        this(0, 0, 0);
+    }
+
+    public Collections(long count, long totalDuration, long lastDuration) {
+        this.count = count;
+        this.totalDuration = totalDuration;
+        this.lastDuration = lastDuration;
+        this.averageDuration = count != 0 ? totalDuration / count : 0;
+    }
+
+    public long getCount() {
+        return count;
+    }
+
+    public long getTotalDuration() {
+        return totalDuration;
+    }
+
+    public long getAverageDuration() {
+        return averageDuration;
+    }
+
+    public long getLastDuration() {
+        return lastDuration;
+    }
+
+    public boolean differFrom(Long collectionTime, Long collectionCount, 
Long lastDuration) {
+        return collectionTime != null && collectionCount != null && 
lastDuration != null
+                && !collectionCount.equals(count);
+    }
+}
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollector.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollector.java
new file mode 100644
index 0000000..a8fa065
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollector.java
@@ -0,0 +1,28 @@
+package com.kodewerk.visualvm.memorypools.gc;
+
+public enum GarbageCollector {
+    PS_SCAVENGE("PS Scavenge", Generation.YOUNG)
+    , PS_MARK_SWEEP("PS MarkSweep", Generation.OLD)
+    ;
+
+    private final String name;
+    private final Generation generation;
+
+    GarbageCollector(String name, Generation generation) {
+        this.name = name;
+        this.generation = generation;
+    }
+
+    public Generation getGeneration() {
+        return generation;
+    }
+
+    static GarbageCollector fromName(String name) {
+        for (GarbageCollector garbageCollector : values()) {
+            if(garbageCollector.name.equals(name)) {
+                return garbageCollector;
+            }
+        }
+        return null;
+    }
+}
diff --git 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
index 283bbdd..000d741 100644
--- a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorModel.java
@@ -8,6 +8,7 @@ import org.openide.util.Exceptions;
 import javax.management.*;
 import javax.management.openmbean.CompositeData;
 import java.io.IOException;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Set;
 
@@ -17,6 +18,7 @@ public class GarbageCollectorModel implements 
MBeanCacheListener {
     private final String name;
     private final ObjectName mbeanName;
     private final MBeanServerConnection mbeanServerConnection;
+    private final GarbageCollector garbageCollector;
 
     private Collections collections = new Collections();
 
@@ -25,6 +27,7 @@ public class GarbageCollectorModel implements 
MBeanCacheListener {
         this.mbeanServerConnection = mbeanServerConnection;
         
CachedMBeanServerConnectionFactory.getCachedMBeanServerConnection(model, 
2000).addMBeanCacheListener(this);
         name = mbeanServerConnection.getAttribute(mbeanName, 
"Name").toString();
+        garbageCollector = GarbageCollector.fromName(name);
     }
 
     @Override
@@ -83,42 +86,22 @@ public class GarbageCollectorModel implements 
MBeanCacheListener {
         listeners.add(listener);
     }
 
-    public class Collections {
-        private final long count;
-        private final long totalDuration;
-        private final long averageDuration;
-        private final long lastDuration;
-
-        public Collections() {
-            this(0, 0, 0);
-        }
-
-        public Collections(long count, long totalDuration, long 
lastDuration) {
-            this.count = count;
-            this.totalDuration = totalDuration;
-            this.lastDuration = lastDuration;
-            this.averageDuration = count != 0 ? totalDuration / count : 0;
-        }
-
-        public long getCount() {
-            return count;
-        }
-
-        public long getTotalDuration() {
-            return totalDuration;
-        }
-
-        public long getAverageDuration() {
-            return averageDuration;
-        }
-
-        public long getLastDuration() {
-            return lastDuration;
-        }
+    public GarbageCollector getGarbageCollector() {
+        return garbageCollector;
+    }
 
-        public boolean differFrom(Long collectionTime, Long collectionCount, 
Long lastDuration) {
-            return collectionTime != null && collectionCount != null && 
lastDuration != null
-                    && !collectionCount.equals(count) && 
!collectionTime.equals(totalDuration);
-        }
+    public static Comparator<GarbageCollectorModel> compareOnGeneration() {
+        return new Comparator<GarbageCollectorModel>() {
+            @Override
+            public int compare(GarbageCollectorModel o1, 
GarbageCollectorModel o2) {
+                // This method does not respect the general contract of 
compare in Comparable
+                // However, since we cannot have two GC for the same 
generation in a JVM, this method does the job
+                if(o1.garbageCollector.getGeneration() == Generation.YOUNG) {
+                    return -1;
+                } else {
+                    return 1;
+                }
+            }
+        };
     }
 }
diff --git 
a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
index 0cd2f21..c54e7da 100644
--- a/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
+++ b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorPanel.java
@@ -7,6 +7,10 @@ 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;
@@ -31,10 +35,17 @@ public class GarbageCollectorPanel extends JPanel 
implements GarbageCollectorMod
         chart.addValues(System.currentTimeMillis(), dataPoints);
 
         String[] details = new String[4];
-        details[0] = model.getCollections().getLastDuration() + " ms";
+        details[0] = formatNumber(model.getCollections().getLastDuration()) 
+ " ms";
         details[1] = String.valueOf(model.getCollections().getCount());
-        details[2] = model.getCollections().getAverageDuration() + " ms";
-        details[3] = model.getCollections().getTotalDuration() + " ms";
+        details[2] = 
formatNumber(model.getCollections().getAverageDuration()) + " ms";
+        details[3] = formatNumber(model.getCollections().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
new file mode 100644
index 0000000..aaa2db3
--- /dev/null
+++ 
b/src/com/kodewerk/visualvm/memorypools/gc/GarbageCollectorSummaryPanel.java
@@ -0,0 +1,4 @@
+package com.kodewerk.visualvm.memorypools.gc;
+
+public class GarbageCollectorSummaryPanel {
+}
diff --git a/src/com/kodewerk/visualvm/memorypools/gc/Generation.java 
b/src/com/kodewerk/visualvm/memorypools/gc/Generation.java
new file mode 100644
index 0000000..51167b2
--- /dev/null
+++ b/src/com/kodewerk/visualvm/memorypools/gc/Generation.java
@@ -0,0 +1,5 @@
+package com.kodewerk.visualvm.memorypools.gc;
+
+public enum Generation {
+    YOUNG, OLD
+}




[memorypoolview~source-code-repository:584a0259] Added last GC duration for IBM J9 and Hotspot

pingtimeout 03/12/2013
 
 
Close
loading
Please Confirm
Close